Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
ProofScriptParser
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
24
Issues
24
List
Boards
Labels
Service Desk
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sarah.grebing
ProofScriptParser
Commits
ffb9d946
Commit
ffb9d946
authored
May 21, 2017
by
Alexander Weigl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lookup for proofscript in directories
parent
814a7c3e
Pipeline
#10643
passed with stage
in 2 minutes and 4 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
160 additions
and
4 deletions
+160
-4
src/main/antlr4/edu/kit/formal/proofscriptparser/ScriptLanguage.g4
...antlr4/edu/kit/formal/proofscriptparser/ScriptLanguage.g4
+1
-1
src/main/java/edu/kit/formal/interpreter/Value.java
src/main/java/edu/kit/formal/interpreter/Value.java
+4
-0
src/main/java/edu/kit/formal/interpreter/funchdl/BuiltinCommands.java
...a/edu/kit/formal/interpreter/funchdl/BuiltinCommands.java
+0
-1
src/main/java/edu/kit/formal/interpreter/funchdl/MacroCommandHandler.java
...u/kit/formal/interpreter/funchdl/MacroCommandHandler.java
+44
-0
src/main/java/edu/kit/formal/interpreter/funchdl/ProofScriptHandler.java
...du/kit/formal/interpreter/funchdl/ProofScriptHandler.java
+89
-0
src/test/java/edu/kit/formal/interpreter/InterpreterTest.java
...test/java/edu/kit/formal/interpreter/InterpreterTest.java
+12
-2
src/test/resources/edu/kit/formal/interpreter/includetest.kps
...test/resources/edu/kit/formal/interpreter/includetest.kps
+5
-0
src/test/resources/edu/kit/formal/interpreter/lib/test.kps
src/test/resources/edu/kit/formal/interpreter/lib/test.kps
+5
-0
No files found.
src/main/antlr4/edu/kit/formal/proofscriptparser/ScriptLanguage.g4
View file @
ffb9d946
...
...
@@ -180,4 +180,4 @@ NOT: 'not';
DIGITS : DIGIT+ ;
fragment DIGIT : [0-9] ;
ID : [a-zA-Z] [_a-zA-Z0-9]* ;
\ No newline at end of file
ID : [a-zA-Z] ([_a-zA-Z0-9] | '.' | '\\' )* ;
\ No newline at end of file
src/main/java/edu/kit/formal/interpreter/Value.java
View file @
ffb9d946
...
...
@@ -73,4 +73,8 @@ public class Value<T> {
public
String
toString
()
{
return
data
+
":"
+
type
;
}
public
static
Value
<
String
>
from
(
String
s
)
{
return
new
Value
<>(
Type
.
STRING
,
s
);
}
}
src/main/java/edu/kit/formal/interpreter/funchdl/BuiltinCommands.java
View file @
ffb9d946
...
...
@@ -2,7 +2,6 @@ package edu.kit.formal.interpreter.funchdl;
import
edu.kit.formal.interpreter.*
;
import
edu.kit.formal.proofscriptparser.ast.CallStatement
;
import
edu.kit.formal.proofscriptparser.ast.Parameters
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
...
...
src/main/java/edu/kit/formal/interpreter/funchdl/MacroCommandHandler.java
0 → 100644
View file @
ffb9d946
package
edu.kit.formal.interpreter.funchdl
;
import
de.uka.ilkd.key.macros.ProofMacro
;
import
de.uka.ilkd.key.macros.scripts.MacroCommand
;
import
edu.kit.formal.interpreter.Interpreter
;
import
edu.kit.formal.interpreter.Value
;
import
edu.kit.formal.interpreter.VariableAssignment
;
import
edu.kit.formal.proofscriptparser.ast.CallStatement
;
import
edu.kit.formal.proofscriptparser.ast.Parameters
;
import
edu.kit.formal.proofscriptparser.ast.StringLiteral
;
import
edu.kit.formal.proofscriptparser.ast.Variable
;
import
lombok.RequiredArgsConstructor
;
import
java.lang.reflect.Parameter
;
import
java.util.Map
;
/**
* @author Alexander Weigl
* @version 1 (21.05.17)
*/
@RequiredArgsConstructor
public
class
MacroCommandHandler
implements
CommandHandler
{
private
final
Map
<
String
,
ProofMacro
>
macros
;
@Override
public
boolean
handles
(
CallStatement
call
)
throws
IllegalArgumentException
{
return
macros
.
containsKey
(
call
.
getCommand
());
}
@Override
public
void
evaluate
(
Interpreter
interpreter
,
CallStatement
call
,
VariableAssignment
params
)
{
//ProofMacro m = macros.get(call.getCommand());
Parameters
p
=
new
Parameters
();
p
.
put
(
new
Variable
(
"#2"
),
new
StringLiteral
(
call
.
getCommand
()));
CallStatement
macroCall
=
new
CallStatement
(
"macro"
,
p
);
macroCall
.
setRuleContext
(
call
.
getRuleContext
().
get
());
//macro proofscript command
interpreter
.
getFunctionLookup
().
callCommand
(
interpreter
,
call
,
params
);
//TODO change MacroCommand.Parameters to public
}
}
src/main/java/edu/kit/formal/interpreter/funchdl/ProofScriptHandler.java
0 → 100644
View file @
ffb9d946
package
edu.kit.formal.interpreter.funchdl
;
import
edu.kit.formal.interpreter.Interpreter
;
import
edu.kit.formal.interpreter.VariableAssignment
;
import
edu.kit.formal.proofscriptparser.Facade
;
import
edu.kit.formal.proofscriptparser.ast.CallStatement
;
import
edu.kit.formal.proofscriptparser.ast.ProofScript
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author Alexander Weigl
* @version 1 (21.05.17)
*/
@RequiredArgsConstructor
public
class
ProofScriptHandler
implements
CommandHandler
{
private
static
final
String
SUFFIX
=
".kps"
;
@Getter
private
final
Map
<
String
,
ProofScript
>
scripts
;
@Getter
private
final
List
<
File
>
searchPath
=
new
ArrayList
<>();
public
ProofScriptHandler
(
List
<
ProofScript
>
proofScripts
)
{
scripts
=
new
HashMap
<>();
proofScripts
.
forEach
(
s
->
scripts
.
put
(
s
.
getName
(),
s
));
}
/**
* lib/test.test
*
* @param name
* @return
*/
public
ProofScript
find
(
String
name
)
throws
IOException
{
File
f
=
new
File
(
name
.
replace
(
'\\'
,
'/'
));
String
path
=
f
.
getParent
();
String
[]
filename
=
f
.
getName
().
split
(
"\\."
,
1
);
String
candidate
=
path
+
'/'
+
filename
[
0
]
+
SUFFIX
;
for
(
File
dir
:
searchPath
)
{
File
test
=
new
File
(
dir
,
candidate
);
if
(
test
.
exists
())
{
addFile
(
path
,
filename
[
0
],
test
);
return
scripts
.
get
(
name
);
}
}
return
null
;
}
private
void
addFile
(
String
path
,
String
filename
,
File
test
)
throws
IOException
{
List
<
ProofScript
>
ps
=
Facade
.
getAST
(
test
);
for
(
ProofScript
s
:
ps
)
{
String
name
=
s
.
getName
();
String
prefix
=
path
.
replace
(
'/'
,
'\\'
)
+
'\\'
;
if
(
name
.
equals
(
filename
))
{
scripts
.
put
(
prefix
+
name
,
s
);
}
scripts
.
put
(
prefix
+
filename
+
'.'
+
name
,
s
);
}
}
@Override
public
boolean
handles
(
CallStatement
call
)
throws
IllegalArgumentException
{
if
(
scripts
.
containsKey
(
call
.
getCommand
()))
return
true
;
try
{
return
find
(
call
.
getCommand
())
!=
null
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
@Override
public
void
evaluate
(
Interpreter
interpreter
,
CallStatement
call
,
VariableAssignment
params
)
{
ProofScript
ps
=
scripts
.
get
(
call
.
getCommand
());
//TODO create new context/introduce signature
ps
.
accept
(
interpreter
);
}
}
src/test/java/edu/kit/formal/interpreter/InterpreterTest.java
View file @
ffb9d946
...
...
@@ -4,6 +4,7 @@ import edu.kit.formal.ScopeLogger;
import
edu.kit.formal.interpreter.funchdl.BuiltinCommands
;
import
edu.kit.formal.interpreter.funchdl.CommandLookup
;
import
edu.kit.formal.interpreter.funchdl.DefaultLookup
;
import
edu.kit.formal.interpreter.funchdl.ProofScriptHandler
;
import
edu.kit.formal.proofscriptparser.Facade
;
import
edu.kit.formal.proofscriptparser.ast.CallStatement
;
import
edu.kit.formal.proofscriptparser.ast.ProofScript
;
...
...
@@ -11,6 +12,7 @@ import org.antlr.v4.runtime.CharStreams;
import
org.junit.Assert
;
import
org.junit.Test
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.List
;
...
...
@@ -24,19 +26,22 @@ public class InterpreterTest {
public
Interpreter
execute
(
InputStream
is
)
throws
IOException
{
List
<
ProofScript
>
scripts
=
Facade
.
getAST
(
CharStreams
.
fromStream
(
is
));
Interpreter
i
=
new
Interpreter
(
createTestLookup
());
Interpreter
i
=
new
Interpreter
(
createTestLookup
(
scripts
));
i
.
setMatcherApi
(
new
EvaluatorTest
.
PseudoMatcher
());
//i.getEntryListeners().add(new ScopeLogger("scope:"));
i
.
interpret
(
scripts
,
"abc"
);
return
i
;
}
private
CommandLookup
createTestLookup
()
{
private
CommandLookup
createTestLookup
(
List
<
ProofScript
>
scripts
)
{
DefaultLookup
defaultLookup
=
new
DefaultLookup
();
defaultLookup
.
getBuilders
().
add
(
new
BuiltinCommands
.
PrintCommand
());
defaultLookup
.
getBuilders
().
add
(
new
BuiltinCommands
.
SplitCommand
());
defaultLookup
.
getBuilders
().
add
(
new
AssertionCommand
());
defaultLookup
.
getBuilders
().
add
(
new
AssertionEqCommand
());
ProofScriptHandler
scriptHandler
=
new
ProofScriptHandler
(
scripts
);
scriptHandler
.
getSearchPath
().
add
(
new
File
(
"src/test/resources/edu/kit/formal/interpreter/"
));
defaultLookup
.
getBuilders
().
add
(
scriptHandler
);
return
defaultLookup
;
}
...
...
@@ -45,7 +50,12 @@ public class InterpreterTest {
public
void
testSimple
()
throws
IOException
{
Interpreter
i
=
execute
(
getClass
().
getResourceAsStream
(
"simple1.txt"
));
Assert
.
assertEquals
(
10
,
i
.
getCurrentState
().
getGoals
().
size
());
}
@Test
public
void
testInclude
()
throws
IOException
{
Interpreter
i
=
execute
(
getClass
().
getResourceAsStream
(
"includetest.kps"
));
}
private
class
AssertionEqCommand
extends
BuiltinCommands
.
BuiltinCommand
{
...
...
src/test/resources/edu/kit/formal/interpreter/includetest.kps
0 → 100644
View file @
ffb9d946
script A () {
print_state;
lib\test;
lib\test.abc i=2;
}
\ No newline at end of file
src/test/resources/edu/kit/formal/interpreter/lib/test.kps
0 → 100644
View file @
ffb9d946
script test() {
print_state;
}
script abc(i:int,j:int){j:=1;print_state;}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment