Grammars without 'with' generate errors [message #59002] |
Wed, 15 July 2009 05:54  |
Eclipse User |
|
|
|
Hi,
I just tried to make a very simple Xtest grammar but get Java code errors.
The error lies in the ui fragment inside
org.xtext.example.contentassist.antlr.MyDslParser.getFollowE lements()
where the InternalMyDslParser.entryRuleModel() is not found/generated.
The test is quite simple: i moved all the terminals from the orginal
grammar, copied the definitions in the current grammar and removed the
'with' keyword.
My goal is to have 'autonomous' grammars, that is containing terminals and
rules in the same file (they are very small, more like ASCII protocol
decoding than DSLs for humans), as i did for years with ANTLR.
What i'm doing wrong?
(It is counter-intuitive to me to have to separate terminals and rules for
even the most basic grammar.)
[For reference, the xtext grammar):
------------------------------------------------------------ --------
grammar org.xtext.example.MyDsl hidden(WS, ML_COMMENT, SL_COMMENT)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate myDsl "http://www.xtext.org/example/MyDsl"
terminal ID :
'^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')* ;
terminal INT returns ecore::EInt: ('0'..'9')+ ;
terminal STRING :
'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|"'"|'\\') | !('\\'|'"') )* '"' |
"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|"'"|'\\') | !('\\'|"'") )* "'";
terminal ML_COMMENT : '/*' -> '*/' ;
terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')? ;
terminal WS : (' '|'\t'|'\r'|'\n')+ ;
terminal ANY_OTHER: . ;
Model :
(imports+=Import)*
(elements+=Type)*;
Import :
'import' importURI=STRING;
Type:
DataType | Class;
DataType:
'datatype' name=ID ';'?;
Class :
'class' name=ID ('extends' superClass=[Class])? '{'
properties+=Property*
'}';
Property:
Attribute | Reference;
Attribute:
'attr' name=ID ':' type=[DataType] ';'?;
Reference:
'ref' name=ID ':' type=[Class] ';'?;
------------------------------------------------------------ --------
|
|
|
Re: Grammars without 'with' generate errors [message #59050 is a reply to message #59002] |
Wed, 15 July 2009 07:31   |
Eclipse User |
|
|
|
Hi Christophe,
this is a bug in Xtext. Please define your terminal rules at the end of
the file. A bugzilla is welcome ;-)
Sorry for inconvenience,
Sebastian
Am 15.07.2009 11:54 Uhr, schrieb Christophe Avare:
> Hi,
>
> I just tried to make a very simple Xtest grammar but get Java code errors.
>
> The error lies in the ui fragment inside
> org.xtext.example.contentassist.antlr.MyDslParser.getFollowE lements()
> where the InternalMyDslParser.entryRuleModel() is not found/generated.
>
> The test is quite simple: i moved all the terminals from the orginal
> grammar, copied the definitions in the current grammar and removed the
> 'with' keyword.
>
> My goal is to have 'autonomous' grammars, that is containing terminals
> and rules in the same file (they are very small, more like ASCII
> protocol decoding than DSLs for humans), as i did for years with ANTLR.
>
> What i'm doing wrong?
> (It is counter-intuitive to me to have to separate terminals and rules
> for even the most basic grammar.)
>
> [For reference, the xtext grammar):
>
> ------------------------------------------------------------ --------
> grammar org.xtext.example.MyDsl hidden(WS, ML_COMMENT, SL_COMMENT)
>
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
> generate myDsl "http://www.xtext.org/example/MyDsl"
>
> terminal ID : '^'?('a'..'z'|'A'..'Z'|'_')
> ('a'..'z'|'A'..'Z'|'_'|'0'..'9')* ;
> terminal INT returns ecore::EInt: ('0'..'9')+ ;
> terminal STRING : '"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|"'"|'\\') |
> !('\\'|'"') )* '"' |
> "'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|"'"|'\\') | !('\\'|"'") )* "'";
> terminal ML_COMMENT : '/*' -> '*/' ;
> terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')? ;
> terminal WS : (' '|'\t'|'\r'|'\n')+ ;
> terminal ANY_OTHER: . ;
>
> Model :
> (imports+=Import)*
> (elements+=Type)*;
>
> Import :
> 'import' importURI=STRING;
>
> Type:
> DataType | Class;
>
> DataType:
> 'datatype' name=ID ';'?;
>
> Class :
> 'class' name=ID ('extends' superClass=[Class])? '{'
> properties+=Property*
> '}';
>
> Property:
> Attribute | Reference;
>
> Attribute:
> 'attr' name=ID ':' type=[DataType] ';'?;
>
> Reference:
> 'ref' name=ID ':' type=[Class] ';'?;
> ------------------------------------------------------------ --------
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03737 seconds