Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » using common terminal names as keywords(parse errors when using INT, STRING as keywords)
using common terminal names as keywords [message #1699292] Tue, 23 June 2015 09:16 Go to next message
Ajay Panyala is currently offline Ajay PanyalaFriend
Messages: 3
Registered: June 2015
Junior Member
Hi,

I am trying to use 'INT' and 'STRING' as keywords. When I write a sample DSL code, I see the errors saying 'String literal is not properly closed' when STRING is used and the error saying **For input string: "INT"** when INT is used as a keyword.

For some reason ID does not have this problem.

Thanks
Ajay
Re: using common terminal names as keywords [message #1699346 is a reply to message #1699292] Tue, 23 June 2015 13:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

can you give a complete grammar and sample model


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 23 June 2015 14:02]

Report message to a moderator

Re: using common terminal names as keywords [message #1699388 is a reply to message #1699346] Tue, 23 June 2015 23:07 Go to previous messageGo to next message
Ajay Panyala is currently offline Ajay PanyalaFriend
Messages: 3
Registered: June 2015
Junior Member
Thanks for the quick reply. Please see the minimal grammar below that produces the errors previously mentioned:


grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

import "eclipse.org/emf/2002/Ecore" as ecore
generate myDsl "xtext.org/example/mydsl/MyDsl"

MyDsl :  (sc+=Section)+ ;

Section : '<' 
	 pm='parameter' name=ID (pas=ParamAttrs)? '/>' 
    ;
    
ParamAttrs : name='type' '=' tm=Singletype ;

Singletype :
     name='INT' 
    | name='FLOAT' 
    | name='STRING'
    |  name='ID' 
    ;


------------------------------------------
Example DSL code:

<parameter in type=STRING /> (shows the error String literal is not properly closed)

<parameter in type=INT /> (shows the error For input string: "INT")

<parameter in type=ID /> (No errors here)



Re: using common terminal names as keywords [message #1699394 is a reply to message #1699388] Wed, 24 June 2015 04:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
The Problem comes from the String/IntValueConverters. these converters are called for terminal rule called STRING and INT. by using keywords you are introducing these.
the solution may be to introduce alternate terminals or a different value converter service.

Singletype :
name=STN
;

terminal STN: 'INT'|'FLOAT'|'STRING'|'ID';

you may have to adopt the content assist.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: using common terminal names as keywords [message #1699398 is a reply to message #1699394] Wed, 24 June 2015 04:45 Go to previous message
Ajay Panyala is currently offline Ajay PanyalaFriend
Messages: 3
Registered: June 2015
Junior Member
Introducing alternate terminals worked. Thank you!
Previous Topic:Call a jar library function from generated code in src-gen
Next Topic:Includes, global constants in DSL files
Goto Forum:
  


Current Time: Thu Sep 26 00:46:58 GMT 2024

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

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

Back to the top