Xtext recursive statement [message #1732064] |
Thu, 12 May 2016 11:25 |
RamaRao Nandamuri Messages: 120 Registered: April 2016 |
Senior Member |
|
|
Hi,
I have a rule:
OpenDecl: (exp+=Expression (','? exp+=Expression)*);
and expression rule:
Expression:
LogicalOr
;
LogicalOr returns Expression:
BitwiseOr ({LogicalOr.left=current} '||' right=BitwiseOr)*
;
BitwiseOr returns Expression:
LogicalAnd ({BitwiseOr.left=current} '|' right=LogicalAnd)*
;
LogicalAnd returns Expression:
BitwiseAnd ({LogicalAnd.left=current} '&&' right=BitwiseAnd)*
;
BitwiseAnd returns Expression:
Equivalency ({BitwiseAnd.left=current} '&' right=Equivalency)*
;
Equivalency returns Expression:
Relational ({Equivalency.left=current} ('=='|'!='|'=') right=Relational)*
;
Relational returns Expression:
PlusMinus ({Relational.left=current} ('>='|'<='|'>'|'<') right=PlusMinus)*
;
PlusMinus returns Expression:
DivMult ({PlusMinus.left=current} ('+'|'-') right=DivMult)*
;
DivMult returns Expression:
LogicalNot ({DivMult.left=current} ('/'|'*') right=LogicalNot)*
;
LogicalNot returns Expression:
OnesComplement ({LogicalNot.left=current} '!' right=OnesComplement)*
;
OnesComplement returns Expression:
Exponentiation ({OnesComplement.left=current} ('~') right=Exponentiation)*
;
Exponentiation returns Expression:
Concatenation ({Exponentialtion.left=current} '^' right=Concatenation)*
;
Concatenation returns Expression:
Primary ({Concatenation.left=current} '##' right=Primary)*
;
Primary returns Expression:
NUMBER|STRING|ID
;
When I am using any text at beginning of the line it is not showing error.
I understand that the rule OpenDecl is allowing to add text freely but how can I restrict it not allow the text without a keyword of any rule?
[Updated on: Mon, 16 May 2016 09:56] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Xtext recursive statement [message #1732114 is a reply to message #1732113] |
Thu, 12 May 2016 16:51 |
|
the grammar was working before? reeally?
your grammar with all the optionality simply is ambigous. ia it an existing language you are building for? if not: get rid of the optional commas etc
and you have stuff in that is hard to check on parser level. thus doing the equivalency check in the validator would have been 1000000 times easier.
especially your primary is expremely bogus. nearly all stuff in it is ambigous.
it dont get why you always do the strange thing for (something.)
you can try to solve it with predicates. but i dont know if the resulting ast will be what you are looking fo
OpenDecl: (exp+=Equivalency2 (=>','? exp+=Equivalency2)*);
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
Re: Xtext recursive statement [message #1732289 is a reply to message #1732123] |
Sun, 15 May 2016 04:35 |
RamaRao Nandamuri Messages: 120 Registered: April 2016 |
Senior Member |
|
|
Hi,
I am using validator to get the value entered for OpenDecl like
grammar:
OpenDecl: (openDecl+=Expression (','? openDecl+=Expression)*);
Validator Code:
@Check
def void checkOpenDecl(OpenDecl decl) {
println("OPen Declaration Test :::::::::::::::"+decl.openDecl)
}
the output I got:
OPen Declaration Test :::::::::::::::[com.prolifics.jpl.jPLEditor.impl.OneDeclImpl@1d03261 (number: null, jplString: null) (isEmpty: false, isArray: false, maxOccurs: null, isRange: false, range: null, hasSize: false, varsize: null, str: null, isArrayVar: false, hasExp: false, isString: false)]
I tried a lot but no luck. Could you please tell me how to get the value entered in editor?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03483 seconds