Question

I'm trying to define a rule where one element is the perfect candidate for the common terminal rule ID. When I launch the editor to test with sample code, the ID rule is not matched for the string "ABC":

Define : ABC : Holder_1 

I get "mismatched input 'ABC' expecting RULE_ID".

Is there something in my grammar conflicting with the ID rule to cause this error?

This is my grammar file:

grammar com.testco.Test with org.eclipse.xtext.common.Terminals 
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate defwiz "http://www.testco.com/Test"

Define_Holder:
  'Definition' ':' holder_name=ID ':' holder_number=HOLDER_NUMBER (':' attribute=define_attr)? (':' pad=holder_pad)?
;

holder_pad:
  HEX
;

Type:
  TYPE_TERM ':' type_value=TYPE_VAL
;


//***************** TERMINALS *****************
terminal TYPE_TERM:
 'Type_' INT+
;  

terminal PROFILE:
  (PROFILE_ID)(PROFILE_ID)'.'(PROFILE_ID)(PROFILE_ID)
;

terminal HOLDER_NUMBER returns ecore:: EString:
  'Holder_' INT+; 

terminal HEX returns ecore:: EString :
  ('0'..'9'|'A'..'F')
;

terminal PROFILE_ID  : '^'?('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9')*;


//***************** ENUMS *****************
enum define_attr:
  BINARY='Binary' |
  SCRAMBLE='Scramble' |
  FORCESIZE='ForceSize' |
  FIXEDSIZE='FixedSize'
;
Was it helpful?

Solution

Your rule PROFILE_ID shadows the ID rule for almost every case (except for the underscore).

OTHER TIPS

Yes, it's likely that lexer scans ABC as HEX terminal. Try to define the latter, for example, as follows:

terminal HEX returns ecore:: EString :
 '0x' ('0'..'9'|'A'..'F')
;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top