Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Grammars without 'with' generate errors
Grammars without 'with' generate errors [message #59002] Wed, 15 July 2009 09:54 Go to next message
Christophe Avare is currently offline Christophe AvareFriend
Messages: 28
Registered: July 2009
Junior Member
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 11:31 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
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] ';'?;
> ------------------------------------------------------------ --------
>
>
Re: Grammars without 'with' generate errors [message #59125 is a reply to message #59002] Wed, 15 July 2009 12:02 Go to previous message
Christophe Avare is currently offline Christophe AvareFriend
Messages: 28
Registered: July 2009
Junior Member
Thank you,

Bug 283534 has been created.

Xtext gets better and better every day!
Previous Topic:cannot distinguish between alternative(s)
Next Topic:Invoking antlr - path to grammar files
Goto Forum:
  


Current Time: Thu Aug 08 16:22:34 GMT 2024

Powered by FUDForum. Page generated in 0.04076 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top