aboutsummaryrefslogtreecommitdiffstats
path: root/Application/org.eclipse.viatra.solver.language/src
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <marussy@mit.bme.hu>2020-06-23 15:17:00 +0200
committerLibravatar Kristóf Marussy <marussy@mit.bme.hu>2020-06-23 15:17:00 +0200
commit42c58bbeead1dae09c51f47abc8e10dfbb9c3f9f (patch)
tree21d49c3a1dadc54dda399a4b8cfe8dc028563f51 /Application/org.eclipse.viatra.solver.language/src
parentMeasurements framework fixes (diff)
downloadVIATRA-Generator-42c58bbeead1dae09c51f47abc8e10dfbb9c3f9f.tar.gz
VIATRA-Generator-42c58bbeead1dae09c51f47abc8e10dfbb9c3f9f.tar.zst
VIATRA-Generator-42c58bbeead1dae09c51f47abc8e10dfbb9c3f9f.zip
New configuration language parser WIP
Diffstat (limited to 'Application/org.eclipse.viatra.solver.language/src')
-rw-r--r--Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/GenerateSolverLanguage.mwe22
-rw-r--r--Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguage.xtext215
-rw-r--r--Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/parser/antlr/SolverLanguageTokenSource.java47
3 files changed, 156 insertions, 108 deletions
diff --git a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/GenerateSolverLanguage.mwe2 b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/GenerateSolverLanguage.mwe2
index 50072f0d..644e681d 100644
--- a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/GenerateSolverLanguage.mwe2
+++ b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/GenerateSolverLanguage.mwe2
@@ -32,7 +32,7 @@ Workflow {
32 language = StandardLanguage { 32 language = StandardLanguage {
33 name = "org.eclipse.viatra.solver.language.SolverLanguage" 33 name = "org.eclipse.viatra.solver.language.SolverLanguage"
34 fileExtensions = "vsc" 34 fileExtensions = "vsc"
35 referencedResource = "platform:/resource/org.eclipse.viatra.solver.language/model/SolverLanguage.genmodel" 35 referencedResource = "platform:/resource/org.eclipse.viatra.solver.language.model/model/model.genmodel"
36 36
37 serializer = { 37 serializer = {
38 generateStub = false 38 generateStub = false
diff --git a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguage.xtext b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguage.xtext
index d0578d78..51115da0 100644
--- a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguage.xtext
+++ b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/SolverLanguage.xtext
@@ -3,66 +3,80 @@ import "http://www.eclipse.org/emf/2002/Ecore" as ecore
3import "http://www.eclipse.org/viatra/solver/language/SolverLanguage" 3import "http://www.eclipse.org/viatra/solver/language/SolverLanguage"
4 4
5Problem: 5Problem:
6 (statements+=Statement)*; 6 ("problem" name=QualifiedName FULL_STOP)?
7 imports+=Import*
8 statements+=Statement*;
7 9
8Statement: 10Statement:
9 ( 11 (
10 AssertionOrDefinition | PredicateDefinition | UnnamedErrorPrediateDefinition | DefaultDefinition | MetricDefinition | 12 AssertionOrDefinition | PredicateDefinition | UnnamedErrorPredicateDefintion | DefaultAssertion |
11 ExternPredicateDefinition | ExternMetricDefinition | ExternAggregatorDefinition | ExternDatatypeDefinition | 13 FunctionDefinition | Attribute | ExternDeclaration | ScopeDeclaration | ObjectiveDeclaration |
12 ClassDefinition | ScopeDefinition | ObjectiveDefinition 14 ClassDeclaration | EnumDeclaration
13 ) FULL_STOP; 15 );
16
17Import:
18 UriImport | NamespaceImport;
19
20UriImport:
21 "import" uri=STRING ("as" alias=QualifiedName) FULL_STOP;
22
23NamespaceImport:
24 "import" importedNamespace=QualifiedName ("as" alias=QualifiedName) FULL_STOP;
14 25
15AssertionOrDefinition returns Statement: 26AssertionOrDefinition returns Statement:
16 Expression ( 27 Expression (
17 {Interpretation.body=current} ":" range=Expression | 28 {Assertion.expression=current} (":" range=Expression)? |
18 {PredicateDefinition.head=current} ":-" body=Expression | 29 {PredicateDefinition.head=current} ":-" body=Expression |
19 {MetricDefinition.head=current} "=" body=Expression 30 {FunctionDefinition.head=current} ":=" body=Expression
20 )?; 31 ) FULL_STOP;
21 32
22PredicateDefinition: 33PredicateDefinition:
23 (functional?="functional" error?="error"? | error?="error" functional?="functional"?) head=Call ":-" body=Expression; 34 (functional?="functional" error?="error"? | error?="error" functional?="functional"?) head=Call ":-" body=Expression FULL_STOP;
24 35
25UnnamedErrorPrediateDefinition: 36UnnamedErrorPredicateDefintion:
26 "error" argumentList=ArgumentList ":-" body=Expression; 37 "error" argumentList=ArgumentList ":-" body=Expression FULL_STOP;
27 38
28DefaultDefinition: 39DefaultAssertion:
29 "default" head=Call ":" range=Expression; 40 "default" expression=Call (":" range=Expression)? FULL_STOP;
30 41
31MetricDefinition: 42FunctionDefinition:
32 type=[NamedElement|QualifiedName] head=Call "=" body=Expression; 43 resultType=[Symbol|QualifiedName] head=Call ":=" body=Expression FULL_STOP;
33 44
34ExternPredicateDefinition: 45TypeReference:
35 "extern" name=QualifiedName argumentList=ArgumentList; 46 type=[Symbol|QualifiedName] forceObjectType?="object"?;
36 47
37ExternMetricDefinition: 48enum AttributeKind:
38 "extern" type=[NamedElement|QualifiedName] name=QualifiedName argumentList=ArgumentList; 49 FUNCTIONAL="functional" | ERROR="error" | ROOT="root" | CONTAINMENT="containment";
39 50
40ExternAggregatorDefinition: 51Attribute:
41 "extern" type=[NamedElement|QualifiedName] name=QualifiedName "{" inputType=[NamedElement|QualifiedName] "..." "}"; 52 kind=AttributeKind target=[Symbol|QualifiedName] FULL_STOP;
42 53
43ExternDatatypeDefinition: 54ExternDeclaration:
44 "extern" "datatype" name=QualifiedName ("extends" supertypes+=[NamedElement|QualifiedName] ("," supertypes+=[NamedElement|QualifiedName])*); 55 ExternPredicateDeclaration | ExternFunctionDeclaration | ExternAggregationOperatorDeclaration | ExternDatatypeDeclaration;
45 56
46Variable: 57ExternPredicateDeclaration:
47 type=[NamedElement|QualifiedName]? name=ID; 58 "extern" (functional?="functional"? & error?="error"?) name=QualifiedName argumentList=ArgumentList FULL_STOP;
59
60ExternFunctionDeclaration:
61 "extern" resultType=[Symbol|QualifiedName] name=QualifiedName argumentList=ArgumentList FULL_STOP;
62
63ExternAggregationOperatorDeclaration:
64 "extern" resultType=[Symbol|QualifiedName] name=QualifiedName "{" argumentType=[Symbol|QualifiedName] "..." "}" FULL_STOP;
65
66ExternDatatypeDeclaration:
67 "extern" "datatype" name=QualifiedName FULL_STOP;
48 68
49Expression: 69Expression:
50 IfElse | Let | ImplicationExpression; 70 ConditionalExpression | LetExpression | DisjunctiveExpression ({Forall.condition=current} "=>" body=DisjunctiveExpression)?;
51 71
52IfElse: 72ConditionalExpression:
53 "if" condition=Expression "then" then=Expression "else" else=Expression; 73 "if" condition=DisjunctiveExpression "then" then=Expression "else" else=Expression;
54 74
55Let: 75LetExpression:
56 "let" bindings+=LetBinding ("," bindings+=LetBinding)* "in" body=Expression; 76 "let" bindings+=LetBinding ("," bindings+=LetBinding)* "in" body=Expression;
57 77
58LetBinding: 78LetBinding:
59 variable=Variable "=" value=AdditiveExpression; 79 type=[Symbol|QualifiedName]? name=ID "=" value=AdditiveExpression;
60
61enum ImplicationOperator returns BinaryOperator:
62 IMPLIES = "=>";
63
64ImplicationExpression returns Expression:
65 DisjunctiveExpression ({BinaryExpression.left=current} op=ImplicationOperator right=ImplicationExpression)?;
66 80
67DisjunctiveExpression returns Expression: 81DisjunctiveExpression returns Expression:
68 ConjunctiveExpression ( 82 ConjunctiveExpression (
@@ -77,19 +91,19 @@ ConjunctiveExpression returns Expression:
77 ComparisonExpression ({Conjunction.children+=current} ("," children+=ComparisonExpression)+)?; 91 ComparisonExpression ({Conjunction.children+=current} ("," children+=ComparisonExpression)+)?;
78 92
79enum ComparisonOperator returns BinaryOperator: 93enum ComparisonOperator returns BinaryOperator:
80 EQ="==" | NOT_EQ="!=" | LESS="<" | LESS_EQ="<=" | GREATER=">" | GREATER_EQ=">=" | IN="in"; 94 EQUALS="==" | NOT_EQUALS="!=" | LESS="<" | LESS_EQUALS="<=" | GREATER=">" | GREATER_EQUALS=">=" | IN="in";
81 95
82ComparisonExpression returns Expression: 96ComparisonExpression returns Expression:
83 AdditiveExpression ({Comparison.left=current} op=ComparisonOperator right=AdditiveExpression)?; 97 AdditiveExpression ({BinaryExpression.left=current} op=ComparisonOperator right=AdditiveExpression)?;
84 98
85enum AdditiveBinaryOperator returns BinaryOperator: 99enum AdditiveBinaryOperator returns BinaryOperator:
86 ADD="+" | SUB="-"; 100 PLUS="+" | MINUS="-";
87 101
88AdditiveExpression returns Expression: 102AdditiveExpression returns Expression:
89 MultiplicativeExpression ({BinaryExpression.left=current} op=AdditiveBinaryOperator right=MultiplicativeExpression)*; 103 MultiplicativeExpression ({BinaryExpression.left=current} op=AdditiveBinaryOperator right=MultiplicativeExpression)*;
90 104
91enum MultiplicativeBinaryOperator returns BinaryOperator: 105enum MultiplicativeBinaryOperator returns BinaryOperator:
92 MUL="*" | DIV="/"; 106 MULTIPLY="*" | DIVIDE="/";
93 107
94MultiplicativeExpression returns Expression: 108MultiplicativeExpression returns Expression:
95 ExponentialExpression ({BinaryExpression.left=current} op=MultiplicativeBinaryOperator right=ExponentialExpression)*; 109 ExponentialExpression ({BinaryExpression.left=current} op=MultiplicativeBinaryOperator right=ExponentialExpression)*;
@@ -101,61 +115,59 @@ ExponentialExpression returns Expression:
101 CastExpression ({BinaryExpression.left=current} op=ExponentialOp right=CastExpression)?; 115 CastExpression ({BinaryExpression.left=current} op=ExponentialOp right=CastExpression)?;
102 116
103CastExpression returns Expression: 117CastExpression returns Expression:
104 UnaryExpression ({CastExpression.body=current} "as" type=[NamedElement|QualifiedName])?; 118 UnaryExpression ({CastExpression.body=current} "as" targetType=[Symbol|QualifiedName])?;
105 119
106enum UnaryOp: 120enum UnaryOperator:
107 NEG="!" | PLUS="+" | MINUS="-" | MAY="may" | MUST="must" | CURRENT="current"; 121 NOT="!" | PLUS="+" | MINUS="-" | MAYBE="?";
108 122
109UnaryExpression returns Expression: 123UnaryExpression returns Expression:
110 AggregationExpression | {UnaryExpression} op=UnaryOp body=AggregationExpression; 124 BracedAggregateExpression | {UnaryExpression} op=UnaryOperator body=BracedAggregateExpression;
111
112AggregationExpression returns Expression:
113 AtomicExpression | QuantifiedExpression | Aggregation;
114 125
115LocalVariables: 126BracedAggregateExpression returns Expression:
116 {LocalVariables} "[" (variables+=Variable ("," variables+=Variable)*)? "]"; 127 AtomicExpression | Aggregation | Count ;
117
118enum Quantifier:
119 EXISTS="exists" | FORALL="forall" | COUNT="count";
120
121QuantifiedExpression:
122 quantifier=Quantifier localVariables=LocalVariables? "{" body=Expression "}";
123 128
124Aggregation: 129Aggregation:
125 op=[NamedElement|QualifiedName] localVariables=LocalVariables? "{" body=Expression ("|" condition=Expression)? "}"; 130 op=[Symbol|QualifiedName] "{" value=Expression "|" condition=Expression "}";
131
132Count:
133 "count" "{" condition=Expression "}";
126 134
127AtomicExpression returns Expression: 135AtomicExpression returns Expression:
128 Reference | Call | Interval | Literal | "(" Expression ")"; 136 Reference | Call | Interval | Literal | "(" Expression ")";
129 137
130Call: 138Call:
131 functor=Reference (transitiveClosure?=TRANSITIVE_CLOSURE | reflexiveTransitiveClosure?=REFLEXIVE_TRANSITIVE_CLOSURE)? argumentList=ArgumentList; 139 functor=Reference argumentList=ArgumentList;
132 140
133ArgumentList: 141ArgumentList:
134 {ArgumentList} "(" (arguments+=Argument ("," arguments+=Argument)*)? ")"; 142 {ArgumentList} "(" (arguments+=Argument ("," arguments+=Argument)*)? ")";
135 143
136Argument: 144Argument:
137 ExpressionArgument | StarArgument | TypedArgument | TypedStarArgument; 145 ExpressionArgument | StarArgument | TypedVariableArgument | TypedStarArgument;
138 146
139ExpressionArgument: 147ExpressionArgument:
140 body=ComparisonExpression; 148 expression=ComparisonExpression;
141 149
142StarArgument: 150StarArgument:
143 {StarArgument} "*"; 151 {StarArgument} "*";
144 152
145TypedArgument: 153TypedVariableArgument:
146 type=[NamedElement|QualifiedName] variable=[NamedElement|QualifiedName]; 154 typeReference=TypeReference name=ID;
147 155
148TypedStarArgument: 156TypedStarArgument:
149 type=[NamedElement|QualifiedName] "*"; 157 typeReference=TypeReference "*";
150 158
151Reference: 159Reference:
152 referred=[NamedElement|QualifiedName]; 160 components+=PathComponent ("." components+=PathComponent)*;
161
162PathComponent:
163 inverse?="~"? symbol=[Symbol|QualifiedName]
164 (transitiveClosure?=TRANSITIVE_CLOSURE | reflexiveTransitiveClosure?=REFLEXIVE_TRANSITIVE_CLOSURE)?;
153 165
154Interval: 166Interval:
155 "[" lowerBound=Expression ".." upperBound=Expression "]"; 167 "[" lowerBound=AdditiveExpression "," upperBound=AdditiveExpression "]";
156 168
157Literal: 169Literal:
158 LogicLiteral | NumericLiteral | InfinityLiteral | EmptyIntervalLiteral | StringLiteral; 170 LogicLiteral | IntLiteral | RealLiteral | InfinityLiteral | EmptyLiteral | StringLiteral;
159 171
160enum LogicValue: 172enum LogicValue:
161 TRUE="true" | FALSE="false" | UNKNOWN="unknown" | ERROR="error"; 173 TRUE="true" | FALSE="false" | UNKNOWN="unknown" | ERROR="error";
@@ -163,69 +175,82 @@ enum LogicValue:
163LogicLiteral: 175LogicLiteral:
164 value=LogicValue; 176 value=LogicValue;
165 177
166NumericLiteral: 178IntLiteral:
179 value=INT;
180
181RealLiteral:
167 value=Real; 182 value=Real;
168 183
169InfinityLiteral: 184InfinityLiteral:
170 {InfinityLiteral} "inf"; 185 {InfinityLiteral} "inf";
171 186
172EmptyIntervalLiteral: 187EmptyLiteral:
173 {EmptyIntervalLiteral} "empty"; 188 {EmptyLiteral} "empty";
174 189
175StringLiteral: 190StringLiteral:
176 value=STRING; 191 value=STRING;
177 192
178ClassDefinition: 193ClassDeclaration:
179 abstract?="abstract"? "class" name=ID ("extends" superclasses+=[NamedElement|QualifiedName] ("," superclasses+=[NamedElement|QualifiedName])*)? 194 (abstract?="abstract"? & root?="root"?) "class" name=ID ("extends" supertypes+=[Symbol|QualifiedName] ("," supertypes+=[Symbol|QualifiedName])*)?
180 "{" members+=MemberDefinition* "}"; 195 ("{" fields+=Field* "}" | FULL_STOP);
181 196
182MemberDefinition: 197Field:
183 containment?="contains"? type=[NamedElement|QualifiedName] multiplicity=Multiplicity? name=ID ("opposite" opposite=[NamedElement|QualifiedName])? ";"?; 198 (containment?="contains" | crossReference?="refers")? type=[Symbol|QualifiedName] multiplicity=Multiplicity?
199 name=ID ("opposite" opposite=[Symbol|QualifiedName])? ";"?;
184 200
185Multiplicity: 201Multiplicity:
186 ManyMultiplicity | ExactMultiplicity | BoundedMultiplicity; 202 UnboundedMultiplicity | ExactMultiplicity | BoundedMultiplicity;
187 203
188ManyMultiplicity: 204UnboundedMultiplicity:
189 {ManyMultiplicity} "[" "]"; 205 {UnboundedMultiplicity} "[" "]";
190 206
191ExactMultiplicity: 207ExactMultiplicity:
192 "[" multiplicity=UpperMultiplicty "]"; 208 "[" value=UpperMultiplicty "]";
193 209
194BoundedMultiplicity: 210BoundedMultiplicity:
195 "[" lowerBound=INT ".." upperBound=UpperMultiplicty "]"; 211 "[" lowerBound=INT "," upperBound=UpperMultiplicty "]";
212
213EnumDeclaration:
214 "enum" name=ID ("{" (literals+=EnumLiteral (","? literals+=EnumLiteral)*)? "}" | FULL_STOP);
196 215
197ScopeDefinition: 216EnumLiteral:
198 ExactScopeDefinition | BoundedScopeDefinition | LowerBoundedScopeDefinition; 217 name=ID;
199 218
200ExactScopeDefinition: 219ScopeDeclaration:
201 "scope" type=[NamedElement|QualifiedName] "==" exactScope=INT; 220 ExactScope | BoundedScope | LowerBoundedScope;
202 221
203BoundedScopeDefinition: 222ExactScope:
223 "scope" type=[Symbol|QualifiedName] "==" size=INT FULL_STOP;
224
225BoundedScope:
204 "scope" ( 226 "scope" (
205 (lowerBound=INT "<=")? type=[NamedElement|QualifiedName] "<=" upperBound=INT | 227 (lowerBound=INT "<=")? type=[Symbol|QualifiedName] "<=" upperBound=INT |
206 upperBound=INT ">=" type=[NamedElement|QualifiedName] (">=" lowerBound=INT)? 228 upperBound=INT ">=" type=[Symbol|QualifiedName] (">=" lowerBound=INT)?
207 ); 229 ) FULL_STOP;
208 230
209LowerBoundedScopeDefinition: 231LowerBoundedScope:
210 "scope" ( 232 "scope" (
211 lowerBound=INT "<=" type=[NamedElement|QualifiedName] | 233 lowerBound=INT "<=" type=[Symbol|QualifiedName] |
212 type=[NamedElement|QualifiedName] ">=" lowerBound=INT 234 type=[Symbol|QualifiedName] ">=" lowerBound=INT
213 ); 235 ) FULL_STOP;
214 236
215enum ObjectiveKind: 237enum ObjectiveKind:
216 MINIMIZE="minimize" | MAXIMIZE="maximize"; 238 MINIMIZATION="minimize" | MAXIMIZATION="maximize";
217 239
218ObjectiveDefinition: 240ObjectiveDeclaration:
219 kind=ObjectiveKind objective=Expression; 241 kind=ObjectiveKind objective=Expression FULL_STOP;
220 242
221UpperMultiplicty returns ecore::EInt: 243UpperMultiplicty returns ecore::EInt:
222 INT | "*"; 244 INT | "*";
223 245
224Real returns ecore::EBigDecimal hidden(): 246Real returns ecore::EBigDecimal hidden():
225 INT ("." INT)?; 247 INT "." INT;
248
249QualifiedNameSegment:
250 ID | QUOTED_ID | "object";
226 251
227QualifiedName hidden(): 252QualifiedName hidden():
228 ID ("." ID)* | QUOTED_ID; 253 QualifiedNameSegment ("::" QualifiedNameSegment)*;
229 254
230@Override 255@Override
231terminal STRING returns ecore::EString: 256terminal STRING returns ecore::EString:
diff --git a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/parser/antlr/SolverLanguageTokenSource.java b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/parser/antlr/SolverLanguageTokenSource.java
index 4c1dacd5..70e7e492 100644
--- a/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/parser/antlr/SolverLanguageTokenSource.java
+++ b/Application/org.eclipse.viatra.solver.language/src/org/eclipse/viatra/solver/language/parser/antlr/SolverLanguageTokenSource.java
@@ -29,6 +29,7 @@ public class SolverLanguageTokenSource implements TokenSource {
29 private int plusTokenId = -1; 29 private int plusTokenId = -1;
30 private int starTokenId = -1; 30 private int starTokenId = -1;
31 private int dotTokenId = -1; 31 private int dotTokenId = -1;
32 private int tildeTokenId = -1;
32 private int openParenTokenId = -1; 33 private int openParenTokenId = -1;
33 34
34 public SolverLanguageTokenSource(TokenSource delegate) { 35 public SolverLanguageTokenSource(TokenSource delegate) {
@@ -42,33 +43,49 @@ public class SolverLanguageTokenSource implements TokenSource {
42 43
43 @Override 44 @Override
44 public Token nextToken() { 45 public Token nextToken() {
45 Token token = internalNextToken(); 46 Token token;
47 if (acceptor.hasNext()) {
48 token = acceptor.next();
49 } else {
50 token = delegate.nextToken();
51 }
52 postProcessToken(token);
46 lastTokenId = token.getType(); 53 lastTokenId = token.getType();
47 return token; 54 return token;
48 } 55 }
49 56
50 protected Token internalNextToken() { 57 protected void postProcessToken(Token token) {
51 if (acceptor.hasNext()) {
52 return acceptor.next();
53 }
54 Token token = delegate.nextToken();
55 int type = token.getType(); 58 int type = token.getType();
56 if (type == plusTokenId) { 59 if (type == plusTokenId) {
57 if ((lastTokenId == RULE_ID || lastTokenId == RULE_QUOTED_ID) 60 if (isTransitiveClosureInReferenceContext()) {
58 && peekUntilVisible().getType() == openParenTokenId) {
59 token.setType(RULE_TRANSITIVE_CLOSURE); 61 token.setType(RULE_TRANSITIVE_CLOSURE);
60 } 62 }
61 } else if (type == starTokenId) { 63 } else if (type == starTokenId) {
62 if ((lastTokenId == RULE_ID || lastTokenId == RULE_QUOTED_ID) 64 if (isTransitiveClosureInReferenceContext()) {
63 && peekUntilVisible().getType() == openParenTokenId) {
64 token.setType(RULE_REFLEXIVE_TRANSITIVE_CLOSURE); 65 token.setType(RULE_REFLEXIVE_TRANSITIVE_CLOSURE);
65 } 66 }
66 } else if (type == dotTokenId) { 67 } else if (type == dotTokenId) {
67 if ((lastTokenId != RULE_ID && lastTokenId != RULE_INT) || peekToken().getType() != lastTokenId) { 68 if (isFullStopContext()) {
68 token.setType(RULE_FULL_STOP); 69 token.setType(RULE_FULL_STOP);
69 } 70 }
70 } 71 }
71 return token; 72 }
73
74 private boolean isIdFragment(int tokenId) {
75 return tokenId == RULE_ID || tokenId == RULE_QUOTED_ID;
76 }
77
78 private boolean isTransitiveClosureInReferenceContext() {
79 int nextVisibleTokenId = peekUntilVisible().getType();
80 return isIdFragment(lastTokenId)
81 && (nextVisibleTokenId == dotTokenId || nextVisibleTokenId == openParenTokenId);
82 }
83
84 private boolean isFullStopContext() {
85 int nextTokenId = peekToken().getType();
86 boolean inReference = isIdFragment(lastTokenId) && (isIdFragment(nextTokenId) || nextTokenId == tildeTokenId);
87 boolean inReal = lastTokenId == RULE_INT && nextTokenId == RULE_INT;
88 return !(inReference || inReal);
72 } 89 }
73 90
74 protected Token peekUntilVisible() { 91 protected Token peekUntilVisible() {
@@ -101,6 +118,9 @@ public class SolverLanguageTokenSource implements TokenSource {
101 case "'.'": 118 case "'.'":
102 dotTokenId = entry.getKey(); 119 dotTokenId = entry.getKey();
103 break; 120 break;
121 case "'~'":
122 tildeTokenId = entry.getKey();
123 break;
104 case "'('": 124 case "'('":
105 openParenTokenId = entry.getKey(); 125 openParenTokenId = entry.getKey();
106 break; 126 break;
@@ -115,6 +135,9 @@ public class SolverLanguageTokenSource implements TokenSource {
115 if (dotTokenId == -1) { 135 if (dotTokenId == -1) {
116 throw new IllegalStateException("Token '.' was not found"); 136 throw new IllegalStateException("Token '.' was not found");
117 } 137 }
138 if (tildeTokenId == -1) {
139 throw new IllegalStateException("Token '~' was not found");
140 }
118 if (openParenTokenId == -1) { 141 if (openParenTokenId == -1) {
119 throw new IllegalStateException("Token '(' was not found"); 142 throw new IllegalStateException("Token '(' was not found");
120 } 143 }