E. Apperloo
E. Apperloo

Reputation: 51

Possible bug: What is the meaning of this Rascal grammar-rule?

SO I'm working on rewriting grammars to other forms of the same grammar and am using the function grammar2rascal(g), however it produces a (in my opinion) weird result when trying to write back follow/precede restrictions. I was wondering if someone could explain to me what this means and why rascal works like this. I'm assuming rascal internally rewrites some things and therefore comes up with this, however I'd still like to understand its meaning and use.

So here goes:

lexical Id = "a" !<< [a-z]+ !>> "b";

becomes:

lex("Id"){prod(lex("Id"),[conditional(iter(\char-class([range(97,122)])),{\not-follow(lit("b")),\not-precede(lit("a"))})],{})}

which seems fine, but is written back as:

lexical Id = [a-z]+ !>> "b" !<< [a-z]+ !>> "b";

This completely removes the not preceded by "a" part of the rule. So am I missing something or is this some sort of bug?

Upvotes: 1

Views: 64

Answers (1)

Davy Landman
Davy Landman

Reputation: 15439

Looking at the code of the grammar2rascal there is a bug where the precede is handled incorrectly. This is fixed in 1c7fed, this should appear on the unstable update site in around an hour (16:00 CET).

And indeed, now it prints, as you would expect:

lexical Id = "a" !<< [a-z]+ !>> "b";

Upvotes: 2

Related Questions