Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Customizing actions in rules
Customizing actions in rules [message #958732] Fri, 26 October 2012 07:12 Go to next message
Markus Wolf is currently offline Markus WolfFriend
Messages: 153
Registered: July 2009
Senior Member
Hi there,

I would like to know if it is possible to customize the code/grammar of a rule at runtime?
What I need is "Automatic Semicolon Insertion" as declared in the ECMA5 specification in chapter 7.9.
In short it means that if there is an offending next token which could not be matched and e.g. the next char (maybe hidden token) is a newline, then insert a semicolon and continue parsing.

This is hard to achieve I think. I already tried to mark my explicit semicolons as optional but this is no easy solution. Even with a semantic predicate my grammar gets ambiguous.

Can anyone help me?
Re: Customizing actions in rules [message #959190 is a reply to message #958732] Fri, 26 October 2012 14:18 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-26-10 9:12, Markus Wolf wrote:
> Hi there,
>
> I would like to know if it is possible to customize the code/grammar of
> a rule at runtime?
> What I need is "Automatic Semicolon Insertion" as declared in the ECMA5
> specification in chapter 7.9.
> In short it means that if there is an offending next token which could
> not be matched and e.g. the next char (maybe hidden token) is a newline,
> then insert a semicolon and continue parsing.
>
> This is hard to achieve I think. I already tried to mark my explicit
> semicolons as optional but this is no easy solution. Even with a
> semantic predicate my grammar gets ambiguous.
>
> Can anyone help me?

There is no easy solution. You can't modify the grammar dynamically -
there is lots of code that has been generated.

The right approach is to make those keywords optional in the grammar.
I even do that for things that are required to be there, but I then
validate it instead of giving the user a syntax error - this because the
user often gets very confusing errors because of this problem.

I offer a quick fix for it.
In the serializer, if there is no node model, I emit the optional keyword.

The most difficult is to handle the ambiguities in your language. There
is no easy fix to that. You have to follow the rules of left-factoring
(look at expression based languages), use semantic predicates, and as a
last resort turn on backtracking.

You can take a look at cloudsmith / geppetto @ gitghub - it has a quite
forgiving grammar where semantics are checked in the validator.

One other alternative I can think of is if it is possible to detect the
missing tokens in the lexer, in that case, and external lexer can emit
something like IMPLIED_COMMA token. This is more difficult as you do not
have the semantic scope available - only the text sequence.

Regards
- henrik
Re: Customizing actions in rules [message #959378 is a reply to message #958732] Fri, 26 October 2012 17:14 Go to previous message
Markus Wolf is currently offline Markus WolfFriend
Messages: 153
Registered: July 2009
Senior Member
Hi Hendrik,

thanks for your lengthy response. I'll give validation a try I think. Smile
Previous Topic:One line = one attribute
Next Topic:Unhide tokens
Goto Forum:
  


Current Time: Sun Apr 18 07:11:42 GMT 2021

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

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

Back to the top