Commit 57895aa9 authored by Alexander Weigl's avatar Alexander Weigl
Browse files

fix for underscore in ids

parent e96e5a81
Pipeline #18766 failed with stages
in 2 minutes and 31 seconds
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":DockFX" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="org.dockfx" external.system.module.version="1.0-FM" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/out/production/classes" />
<output-test url="file://$MODULE_DIR$/out/test/classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/out" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Gradle: commons-cli:commons-cli:1.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Gradle: com.google.guava:guava:22.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Gradle: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Gradle: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Gradle: org.apache.logging.log4j:log4j-core:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Gradle: org.apache.logging.log4j:log4j-api:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Gradle: org.projectlombok:lombok:1.16.16" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Gradle: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Gradle: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Gradle: com.google.j2objc:j2objc-annotations:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Gradle: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: commons-cli:commons-cli:1.4" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: com.google.guava:guava:22.0" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.apache.logging.log4j:log4j-core:2.6" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.apache.logging.log4j:log4j-api:2.6" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: com.google.j2objc:j2objc-annotations:1.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: commons-cli:commons-cli:1.4" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: com.google.guava:guava:22.0" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: commons-io:commons-io:2.5" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.apache.logging.log4j:log4j-core:2.6" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.apache.logging.log4j:log4j-api:2.6" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: com.google.j2objc:j2objc-annotations:1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -48,7 +48,9 @@ assignment
expression
:
expression MUL expression #exprMultiplication
MINUS expression #exprNegate
| NOT expression #exprNot
| expression MUL expression #exprMultiplication
| <assoc=right> expression DIV expression #exprDivision
| expression op=(PLUS|MINUS) expression #exprLineOperators
| expression op=(LE|GE|LEQ|GEQ) expression #exprComparison
......@@ -59,8 +61,6 @@ expression
//| expression EQUIV expression already covered by EQ/NEQ
| expression LBRACKET substExpressionList RBRACKET #exprSubst
| ID LPAREN (expression (',' expression)*)? RPAREN #function
| MINUS expression #exprNegate
| NOT expression #exprNot
| LPAREN expression RPAREN #exprParen
| literals #exprLiterals
| matchPattern #exprMatch
......@@ -164,7 +164,7 @@ MATCH : 'match';
SCRIPT : 'script' ;
TRUE : 'true' ;
FALSE : 'false' ;
CALL : 'call' ;
//CALL : 'call' ;
REPEAT : 'repeat' ;
/*INT : 'int' ;
BOOL: 'bool' ;
......@@ -212,4 +212,4 @@ QUESTION_MARK: '?';
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
......@@ -96,6 +96,28 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
});
}
/**
*
* @param text
* @return
*/
public static Expression splitIdentifier(final String text) {
final String[] ids = text.split("-");
List<Expression> literals = new ArrayList<>(ids.length);
for (int i = 0; i < ids.length; i++) {
if (ids[i].isEmpty()) {
literals.add(new UnaryExpression(
Operator.NEGATE,
new Variable(ids[i + 1])
));
i++; // overjump next variable, already consumed
} else {
literals.add(new Variable(ids[i]));
}
}
return literals.stream().reduce((a, b) -> new BinaryExpression(a, Operator.MINUS, b)).orElse(null);
}
@Override
public List<ProofScript> visitStart(ScriptLanguageParser.StartContext ctx) {
ctx.script().forEach(s ->
......@@ -156,7 +178,6 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
return statements;
}
@Override
public Object visitStatement(ScriptLanguageParser.StatementContext ctx) {
return ctx.getChild(0).accept(this);
......@@ -220,7 +241,6 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
return createBinaryExpression(ctx, ctx.expression(), findOperator(ctx.op.getText()));
}
private Operator findOperator(String n) {
return findOperator(n, 2);
}
......@@ -315,7 +335,12 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
@Override
public Object visitLiteralID(ScriptLanguageParser.LiteralIDContext ctx) {
return new Variable(ctx.ID().getSymbol());
String text = ctx.ID().getSymbol().getText();
int p = text.indexOf('-');
if (p == -1) {
return new Variable(ctx.ID().getSymbol());
}
return (Expression) splitIdentifier(text);
}
@Override
......
edu.kit.iti.formal.psdbg.interpreter.functions.FindInSequence
\ No newline at end of file
package edu.kit.iti.formal.psdbg.parser;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Alexander Weigl
* @version 1 (16.02.18)
*/
public class TransformAstTest {
@Test
public void testSplitIdentifier() {
Assert.assertEquals(
Facade.parseExpression("- a"),
Facade.parseExpression("-a")
);
Assert.assertEquals(
Facade.parseExpression("- a"),
TransformAst.splitIdentifier("-a")
);
Assert.assertEquals(
Facade.parseExpression("- a - b"),
TransformAst.splitIdentifier("-a-b")
);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment