Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Inverse for syntax exclusion #518

Closed
abort opened this issue Mar 4, 2014 · 4 comments
Closed

Feature Request: Inverse for syntax exclusion #518

abort opened this issue Mar 4, 2014 · 4 comments

Comments

@abort
Copy link

abort commented Mar 4, 2014

During development of a javascript grammar for rascal, exclusion is widely used to only search for 'specific' types of statements. For now, we are getting huge lines like;
Statement!c!d!e!f!g!h!i!j!k.... etcetera, for statements to be just of type or label label/type 'a' and 'b'. In that case it would be more efficient (but more importantly, easier to understand and maintain) to use a form like Statement#a#b or Statement/a/b, where we only expect to match on a and b. This would be the inverse of the exclusion.

@SanderBenschop
Copy link

The following is an example from the JavaScript grammar we are working on. We want a few specific types of statements to match and exclude the rest, without altering syntax or creating redundant depth/overhead in our tree.

Statement!variableSemi!expressionSemi!returnExp!throwExp!returnNoExp!throwNoExp!continueLabel!continueNoLabel!breakLabel!breakNoLabel!empty!expressionLoose!emptyBlockEnd!continueLabelNoSemiBlockEnd!breakLabelNoSemiBlockEnd!continueNoLabelNoSemiBlockEnd!breakNoLabelNoSemiBlockEnd!returnExpNoSemiBlockEnd!returnNoExpNoSemiBlockEnd!throwExpNoSemiBlockEnd!throwNoExpNoSemiBlockEnd!expressionBlockEnd!block!ifThen!ifThenElse!doWhile!whileDo!forDo!forIn!tryBlock!switchCase

@grammarware
Copy link
Member

If some small part of a nonterminal is needed relatively often, it could make sense to promote it to a different nonterminal, which would eliminate the problem entirely. Exclusion is a stretch for small hacks.

@jurgenvinju
Copy link
Member

or an alias could also be nice. I think Sander does not want to change the
shape of the parse forest while restricting to only a few alternatives. I
agree that that is wat a non-terminal is also for. It's interesting :-)

On Thu, Mar 13, 2014 at 1:42 PM, Vadim Zaytsev notifications@github.comwrote:

If some small part of a nonterminal is needed relatively often, it could
make sense to promote it to a different nonterminal, which would eliminate
the problem entirely. Exclusion is a stretch for small hacks.

Reply to this email directly or view it on GitHubhttps://github.com//issues/518#issuecomment-37528093
.

Jurgen Vinju

@afroozeh
Copy link

I faced the same problem Sander has when I was working with the OCaml grammar, so I think it's good to have this feature inn Rascal.

Semantically, adding a nonterminal makes sense, but in addition to changing the parse tree, introducing a new nonterminal will also affect the performance of parsing: GSS calls to the original nonterminal and SPPF nodes with the same label as the original nonterminal are not shared.

I think the alias idea is nice. I was thinking of something like this:

syntax E =  E + E1
       | E - E2
       | - E 
       | a

alias E1 from E with { E - E, E + E}

alias E2 from E without {  - E }

or just simply

alias E2 from E = 
        E + E
        | E - E
        | a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants