Skip to main content



      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 05:16 Go to next message
Eclipse UserFriend
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 09:58 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

can you give a complete grammar and sample model

[Updated on: Tue, 23 June 2015 10:02] by Moderator

Re: using common terminal names as keywords [message #1699388 is a reply to message #1699346] Tue, 23 June 2015 19:07 Go to previous messageGo to next message
Eclipse UserFriend
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 00:00 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: using common terminal names as keywords [message #1699398 is a reply to message #1699394] Wed, 24 June 2015 00:45 Go to previous message
Eclipse UserFriend
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: Tue Jul 01 15:19:25 EDT 2025

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

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

Back to the top