Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Parse error - keyword used as parameter value
Parse error - keyword used as parameter value [message #1727692] Fri, 25 March 2016 11:33 Go to next message
Mihai Traistariu is currently offline Mihai TraistariuFriend
Messages: 6
Registered: March 2016
Junior Member
Hi,
I'm trying to parse language where the naming convention is not very strict and the keywords can be used as parameters (name or value). I have the following dummy grammar (each statement should be on a separate line) :

grammar test.org.xtext.example.mydsl.MyDsl hidden (WS)
generate myDsl "http://www.org.test/xtext/example/mydsl/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Model:
	(statements+=Statement EOL+)*
	statements+=Statement EOL*
;

Statement:
	ImportStatement|
	RunStatement
;

RunStatement:
	{RunQueryStatement} 'RUN' 'PROC' parameterList+=ParameterDefinition+
;

ParameterDefinition:
	{VariableDefinition} paramName=ID '=' paramValue=(ID|STRING)
;

ImportStatement:
	{ImportProcSatatement} 'IMPORT' 'PROC' 'FROM' fileName=STRING
;


terminal ID:
	(!('\r'|'\n'|' '|'\t'|'"'|"'"|'='))+
;

terminal EOL:
	('\r'? '\n')
;

terminal WS : 
	(' '|'\t')+
;

terminal STRING	: 
			'"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"' |
			"'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'"
		; 

When parsing the following code :

IMPORT PROC FROM 'myfile'
RUN PROC param=PROC


I get an error on the second line "no viable alternative at input 'PROC'".
How can I change the rules to be able to parse this script?
Re: Parse error - keyword used as parameter value [message #1727694 is a reply to message #1727692] Fri, 25 March 2016 11:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
You can introduce a datatype rule

MyID: ID | ... | 'MyKeword' ;

And use this one instead of ID


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Parse error - keyword used as parameter value [message #1727699 is a reply to message #1727694] Fri, 25 March 2016 12:13 Go to previous message
Mihai Traistariu is currently offline Mihai TraistariuFriend
Messages: 6
Registered: March 2016
Junior Member
Thank you.
Previous Topic:After parsing files using xtext, Should we keep xtext emf model in the memory?
Next Topic:error in creation of new project EMF Generator Model
Goto Forum:
  


Current Time: Fri Apr 19 16:10:29 GMT 2024

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

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

Back to the top