|
|
|
|
|
Re: Xtext grammar related query [message #1741946 is a reply to message #1741942] |
Tue, 30 August 2016 17:44 |
|
i do not want to have a look at such a big grammar to solve your problem
i am sure you use backtracking (have a look at your workflow)
the grammar gives me errors and
warning(200): ../org.xtext.example.mydsl1/src-gen/org/xtext/example/mydsl1/parser/antlr/internal/InternalMyDsl.g:719:3: Decision can match input such as "'->' RULE_NUMBER" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.mydsl1/src-gen/org/xtext/example/mydsl1/parser/antlr/internal/InternalMyDsl.g:719:3: Decision can match input such as "'->' RULE_ID" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.mydsl1/src-gen/org/xtext/example/mydsl1/parser/antlr/internal/InternalMyDsl.g:719:3: Decision can match input such as "'->' RULE_STRING" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
and many others
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Xtext grammar related query [message #1741947 is a reply to message #1741946] |
Tue, 30 August 2016 17:45 |
|
btw what is the error you get.
please use this grammar as starting point
grammar org.xtext.example.mydsl1.MyDsl with org.eclipse.xtext.common.Terminals hidden(WS, SL_COMMENT, ML_COMMENT)
generate myDsl "http://www.xtext.org/example/mydsl1/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Model: {Model} NL* statements+=Statement*;
Statement: (NonRecursingStatement|ConditionalElseBlock) ';'? NL+ | HASH_COMMENT NL*;
NonRecursingStatement returns Statement:
( OpenAssignment
)
;
//Annotation: {Annotation} '@app' '(' (appExp+=Expression)* ')' ('->'appExp+=Expression);
Annotation: '@app' '(' (appExp+=Expression)* ')' ('->'appExp+=Expression);
Block : (statements+=StartBlock) statementlist+=Statement* (statements+=EndBlock);
StartBlock returns Statement : {StartBlock}'{' NL+;
EndBlock returns Statement : {EndBlock}'}';
IfStatement returns Statement: {Statement} 'if' (ifExp+=Expression)*;
ElseStatement returns Statement: {Else} (HASH_COMMENT NL*)* 'else';
ElseIfStatement returns Statement: (HASH_COMMENT NL*)* ('else' NL* 'if') (exp+=Expression (','? exp+=Expression)*);
ConditionalIfBlock returns Statement:
IfStatement {ConditionalIfBlock.left=current} NL+ (=>block+=Block|right+=(NonRecursingStatement)|conditionalIfBlock+=ConditionalIfBlock)
;
ConditionalElseIfBlock returns Statement:
ConditionalIfBlock {ConditionalElseBlock.left=current} (NL+ elseif+=ElseIfStatement NL+ (=>block+=Block|right+=(NonRecursingStatement)))*
;
ConditionalElseBlock returns Statement:
ConditionalElseIfBlock {ConditionalElseBlock.left=current} (NL+ else+=ElseStatement NL+ (=>block+=Block|right+=(NonRecursingStatement)))?
;
OpenAssignment: args+=Assignment (',' args+=Assignment)* ','?;
Assignment: name=('math')? (precision=Precision)? assignExp+=Expression;
Precision: (width=NUMBER)|((width=NUMBER)?'.'(decimal_places=NUMBER));
Expression:
Equivalency
;
Equivalency returns Expression:
Relational ({Equivalency.left=current} ('=') right=Relational)*
;
Relational returns Expression:
PlusMinus ({Relational.left=current} ('>') right=PlusMinus)*
;
PlusMinus returns Expression:
ArrowExpression ({PlusMinus.left=current} ('-') right=ArrowExpression)*
;
ArrowExpression returns Expression:
Primary ({ArrowExpression.left=current} '->' right=Primary)*
;
Primary returns Expression: {Expression}
name=NUMBER | Annotation=Annotation | name=ID
;
terminal ID : (':'('+')?)? ('a'..'z'|'A'..'Z'|'$'|'.'|'@'|'_')('a'..'z'|'A'..'Z'|'$'|'.'|'0'..'9'|'@'|'*'|'_'|'!')*;
terminal STRING : '"' ( '\\'('"'|('\r'? '\n')) | !('\n'|'"') )* '"' |
"'" ( '\\'("'"|('\r'? '\n')) | !('\n'|"'") )* "'";
terminal SL_COMMENT: '//' !('\n' | '\r')*;
terminal HASH_COMMENT : ('#'('\r'? '\n')?) | ('#' !('#'|'\n'|'\r')+ ('\r'? '\n')?) | (('#''#''#') !('\n'|'\r')* ('\r'? '\n')?);
terminal WS : (' '|'\t'| ('\\'((' '|'\t')* '\r'? '\n')))+;
terminal NL : ('\r'? '\n')+;
terminal NUMBER: ('+'|'-')? (INT);
terminal INT returns ecore::EInt: '0'..'9' ('0'..'9')*;
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.02879 seconds