How to use EOL to grammar [message #1770686] |
Wed, 16 August 2017 09:12 |
Krzysztof Drozd Messages: 12 Registered: July 2017 Location: Amsterdam |
Junior Member |
|
|
Hi,
I've some old legacy language with many problems... and it seems that only way (with ANTLR) is to use EndOfLine as part of the grammar and in general, make in withe space aware language.
But EOL solves one problem giving 2 back ;)
My problems:
1. Rule MyVarField is defined with list of modifiers (*)
2. When I try to define MyMethod after MyVarField modifiers from MyMethod are parsed as part of MyVarField...
3. With added EOL rule it works better but parser comes with errors like 'missing EOF at \n' or 'no viable alternative at input \n'.
So how bad is my situation? Any hope?
This is a short version of my grammar so far:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
MyModel:
myElements+=MyElements*;
MyElements:
MyPackage | MyVarField | MyMethod ;
MyPackage:
'$package' name=ID EOL+;
MyMethod:
modifiers+=MyModifiers* name=ID '(' ')' EOL+
myCommands+=MyCommands*;
MyCommands:
MyReturn | MyVarField | MySet ;
MySet:
'set' var=[MyVarField] '=' value=INT;
MyReturn:
'return' var=[MyVarField];
MyVarField:
type=('$var'|'$val') name=ID (isArray?='(' ')')? varFieldSettings+=MyFieldSettings* EOL+;
MyFieldSettings:
MyType | MyModifiers;
MyModifiers:
modifiers=MyModifiersEnum;
MyModifiersEnum:
FINAL='final' |
EXTERNAL='external' |
INTERNAL='internal' |
PACKAGE='package' |
PUBLIC='public' |
PRIVATE='private';
MyType:
'type' '=' type=[MyModel];
@Override terminal WS:
(' ' | '\t')+;
terminal EOL:
'\r'? '\n';
Thanks
Krzysiek
|
|
|
Re: How to use EOL to grammar [message #1770688 is a reply to message #1770686] |
Wed, 16 August 2017 09:21 |
|
whats your actual problem/question
are
you asking about this ambiguity:
warning(200): ../org.xtext.example.mydsl3/src-gen/org/xtext/example/mydsl3/parser/antlr/internal/InternalMyDsl.g:276:3: Decision can match input such as "'$var' RULE_ID '(' ')' 'type' '=' RULE_ID RULE_EOL" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.mydsl3.ide/src-gen/org/xtext/example/mydsl3/ide/contentassist/antlr/internal/InternalMyDsl.g:741:41: Decision can match input such as "'$var' RULE_ID '(' ')' 'type' '=' RULE_ID RULE_EOL" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
Re: How to use EOL to grammar [message #1770703 is a reply to message #1770701] |
Wed, 16 August 2017 11:12 |
|
i am still get tons of ambiguity errors in the log.
and still the question
where does the field end and where does the method start?
maybe you can try something like
grammar org.xtext.example.mydsl5.MyDsl with org.eclipse.xtext.common.Terminals hidden(SL_COMMENT, ML_COMMENT, WS, EOL)
MyVarField hidden(WS):
'$var' name=ID (isArray?='(' ')')? varFieldSettings+=MyFieldSettings*;
@Override terminal WS:
(' ' | '\t')+;
terminal EOL:
'\r'? '\n';
this grammar now has no EOL nor WHITESPACE at all
maybe something like this works for you
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: How to use EOL to grammar [message #1770716 is a reply to message #1770703] |
Wed, 16 August 2017 12:56 |
Krzysztof Drozd Messages: 12 Registered: July 2017 Location: Amsterdam |
Junior Member |
|
|
Hi,
Now is much better :)
I'm able to correctly parse this model:
$package vars
$var varName public external //test
$var var2Arr() private internal
public final method1()
type = String
set var = 123
private final method2()
return Var
Without any errors in Error log or parser errors.
Just on top of your changes I changed this:
MyVarField hidden(WS):
'$var' name=ID (isArray?='(' ')')? varFieldSettings+=MyFieldSettings* (EOL | SL_COMMENT)+;
to add some kind of separator as varFieldSettings was still mixed with modifiers list
Thank you for help
Thanks
Krzysiek
|
|
|
Powered by
FUDForum. Page generated in 0.04149 seconds