Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using single "'" / "Hiding" terminal rules
Using single "'" / "Hiding" terminal rules [message #663110] Sun, 03 April 2011 17:22 Go to next message
Simon Stratmann is currently offline Simon StratmannFriend
Messages: 27
Registered: February 2011
Junior Member
Hello,

in the language my editor is for you can either use ' for characters, like in java, or to access attributes like "object'anAttribute".

Let's say this is my grammar (I can't post the real grammar, so this will have to do):

Object :
	"object" name=ID "with" attributes+=ID*;

Access : 
	object=ID "'" attribute=ID;


With this something like

object a with b
a'b


should work, but the parser expects the ' to open a string and thus another ' to close the string.

How can I get this to work?
My title is the way it is because when I remove the STRING terminal rule, it works, but I need this somewhere else (in my real grammar), but only once. So I thought it might be possible to "hide" this terminal rule in a way that it is only recognized where used in a parser rule and not somewhere else.

Any help is appreciated.

Thanks a lot,

Simon
Re: Using single "'" / "Hiding" terminal rules [message #663111 is a reply to message #663110] Sun, 03 April 2011 17:42 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

it is not possible to use terminal rules only in a particular position. This is because the lexing (chopping the input file into tokens) is done before the parsing and without any context from the remaining grammar.

What you could try is making the String rule a data type rule. These are evaluated only in the context where they are expected. However, writing down the rule may not be trivial (as negation is not allowed in data type rules).

Alex
Re: Using single "'" / "Hiding" terminal rules [message #663211 is a reply to message #663111] Mon, 04 April 2011 11:04 Go to previous message
Simon Stratmann is currently offline Simon StratmannFriend
Messages: 27
Registered: February 2011
Junior Member
Alex,

thanks again for your help.
It did take some time, but rewriting the rule to a datatype rule (and, while I was it, using the nex terminal fragments, cleaning my sometimes 6 line long rules) worked.

Simon
Previous Topic:[xbase] x-friends of org.eclipse.xtext.xbase
Next Topic:NodeUtil in Xtext 2.0 (M6)? [Solved]
Goto Forum:
  


Current Time: Tue Apr 23 07:44:52 GMT 2024

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

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

Back to the top