Skip to main content



      Home
Home » Modeling » TMF (Xtext) » mismatched input '0' expecting RULE_ID
mismatched input '0' expecting RULE_ID [message #1816055] Fri, 18 October 2019 05:10 Go to next message
Eclipse UserFriend
Hello everyone, I am not sure if this question is related with the use of keywords so I will ask it again. Apologies if this is the case. For the following grammar:

Import:
	'import' importURI=STRING;

TaskDef:
	'TaskDef' name=ID 'on' 'Task=' mapped=[Task|QualifiedNamed] '{'
		(statements+=Statement)*
	'}';

QualifiedNamed:
	ID ('.' ID)*
;


And the following concrete grammar:

TaskDef FrontSensor on Task=0 {
  out = 2
}


I am getting the following message:

mismatched input '0' expecting RULE_ID


The class Task is imported. Any clue about what is going on?

Regards, Matias.
Re: mismatched input '0' expecting RULE_ID [message #1816056 is a reply to message #1816055] Fri, 18 October 2019 05:13 Go to previous messageGo to next message
Eclipse UserFriend
0 is an INT (or a keyword depending on your grammar)
https://blogs.itemis.com/en/xtext-hint-identifiers-conflicting-with-keywords

QualifiedNamed allows ID only

=> you can use a MyID

MyID: ID | INT;
or
MyID: ID | '0';

depending on your situation

and use

MyID in QualifiedName
Re: mismatched input '0' expecting RULE_ID [message #1816065 is a reply to message #1816056] Fri, 18 October 2019 08:28 Go to previous messageGo to next message
Eclipse UserFriend
Hello Christian and thanks for the quick answer. I tried:

TaskDef:
	'TaskDef' name=ID 'on' 'Task=' mapped=[Task|QualifiedNamed] '{'
		(statements+=Statement)*
	'}';

QualifiedNamed:
	MyID ('.' MyID)*
;	

MyID: ID | INT;


I am getting this:

no viable alternative at input '2'


It works well when I use:

MyID: ID | '0';


However, I have to do it for every value?, e.g.,:

MyID: ID | '0' | '1';


In my model, the ID I am using is an EString named TaskId.

Regards, Matias.

[Updated on: Mon, 21 October 2019 04:09] by Moderator

Re: mismatched input '0' expecting RULE_ID [message #1816067 is a reply to message #1816065] Fri, 18 October 2019 08:45 Go to previous messageGo to next message
Eclipse UserFriend
I fixed by using:


QualifiedNamed:
	MyID ('.' MyID)*
;	

MyID: ID | NUMBER;

terminal NUMBER returns ecore::EBigDecimal:
	('0'..'9')* ('.' ('0'..'9')+)?;


I am not sure if this is correct.
Re: mismatched input '0' expecting RULE_ID [message #1816068 is a reply to message #1816067] Fri, 18 October 2019 09:33 Go to previous messageGo to next message
Eclipse UserFriend
I have. No clue. what is in your grammar besides your snippet

[Updated on: Fri, 18 October 2019 09:34] by Moderator

Re: mismatched input '0' expecting RULE_ID [message #1816099 is a reply to message #1816068] Mon, 21 October 2019 04:09 Go to previous messageGo to next message
Eclipse UserFriend
Apologies for that. Here is the whole grammar:

grammar xtext.tasks.MyTasks with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "platform:/resource/my.metamodel.org/model/mymodel.ecore" as mymodel
generate myTasks "http://www.metamodel.org/xtext/tasks/MyTasks"

Module:
	'module' name=ID '{'
	(imports+=Import)*
	(taskdefs+=TaskDef)*
    '}';

Import:
	'import' importURI=STRING;

TaskDef:
	'TaskDef' name=ID 'on' 'Task=' mapped=[mymodel::Task|QualifiedNamed] '{'
	'}';

QualifiedNamed:
	MyID ('.' MyID)*
;	

MyID: ID | NUMBER;

terminal NUMBER returns ecore::EBigDecimal:
	('0'..'9')* ('.' ('0'..'9')+)?;
Re: mismatched input '0' expecting RULE_ID [message #1816103 is a reply to message #1816099] Mon, 21 October 2019 05:49 Go to previous message
Eclipse UserFriend
Yes the fix looks legit
Previous Topic:Add Xtext content to toolbar
Next Topic:Working directory for xtext plugin
Goto Forum:
  


Current Time: Tue Apr 15 01:06:10 EDT 2025

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

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

Back to the top