Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with multiple alternatives
Problem with multiple alternatives [message #1775888] Tue, 07 November 2017 16:08 Go to next message
Pedro Sánchez is currently offline Pedro SánchezFriend
Messages: 4
Registered: October 2017
Junior Member
Hi All,

Many days struggling with an error I am not able to solve.

A simplification of my grammar where the error is:
-----------------------------------------------
Enums: name=ID '::=' (r+=EnumElem)+;

EnumElem: name=ID;

FQN: ID ("." ID)* ;

Vars: Type name=ID (':=' value=Primitive_Value)? ;

Param: name=ID ;

VarPar: Vars | Param ;

SuperVarPar:
v=[VarPar] | e=[EnumElem|FQN]
;

PerVarParam: v=SuperVarPar;
-----------------------------------------------

warning(200): ../org.xtext.example.trprograms/src-gen/org/xtext/example/mydsl/parser/antlr/internal/InternalTR.g:735:2: Decision can match input such as "RULE_ID" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
error(201): ../org.xtext.example.trprograms/src-gen/org/xtext/example/mydsl/parser/antlr/internal/InternalTR.g:735:2: The following alternatives can never be matched: 2

I need to have access to both Vars, Params and Enums in SuperVarPar but the part with "e=[EnumElem|FQN]" gives the previous error.

I have tried many other combinations without error but not recognizing enums elements. FQN was added to allow referencing enums elements (it works fine in other part of the grammar).

Any idea??
(enclosed also the full grammar)

I would need a good tutorial to learn the basics of xText to avoid problems like this one but reading the official documentation is not enough for me.... :(

Many thanks in advance.
Re: Problem with multiple alternatives [message #1775896 is a reply to message #1775888] Tue, 07 November 2017 19:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you please share the reproducible grammar in a usable form. docx is not

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem with multiple alternatives [message #1775907 is a reply to message #1775896] Wed, 08 November 2017 08:01 Go to previous messageGo to next message
Pedro Sánchez is currently offline Pedro SánchezFriend
Messages: 4
Registered: October 2017
Junior Member
Hi Christian,

Many thanks for your help.

Enclosed the xtext file. I am not sure if you need the whole project or not...

Look forwardyour reply.

Pedro.
Spain
  • Attachment: TR.xtext
    (Size: 3.10KB, Downloaded 95 times)
Re: Problem with multiple alternatives [message #1775917 is a reply to message #1775907] Wed, 08 November 2017 09:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
SuperVarPar:
v=[VarPar] | e=[EnumElem|FQN]
;

is short for

SuperVarPar:
v=[VarPar|ID] | e=[EnumElem|FQN]
;

which will be parsed as

SuperVarPar: ID | FQN

since ID is an FQN too this does not work

=> either make FQN be FQN always

FQN: ID ("." ID)+ ;

or have only one Reference

SuperVarPar:
ve=[VarParOrEnumElem|FQN]
;

VarParOrEnumElem: VarPar | EnumElem;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem with multiple alternatives [message #1775921 is a reply to message #1775917] Wed, 08 November 2017 09:41 Go to previous message
Pedro Sánchez is currently offline Pedro SánchezFriend
Messages: 4
Registered: October 2017
Junior Member
Many thanks.
it works! :)

Regards,
Pedro
Previous Topic:EmbeddedEditor in pure e4 application
Next Topic:What is wrong with my grammar
Goto Forum:
  


Current Time: Fri Apr 19 14:20:09 GMT 2024

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

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

Back to the top