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

Support for Include in grammars #93

Open
attilah opened this issue Dec 30, 2016 · 7 comments
Open

Support for Include in grammars #93

attilah opened this issue Dec 30, 2016 · 7 comments

Comments

@attilah
Copy link

attilah commented Dec 30, 2016

It would be nice to have an @include "BaseRules.peg" statement, which can import the content of any other grammar file. To not to mess with the "first tag is the start tag by default" rule, those includes can be appended to the end of the grammar file.

Another restriction can be that the imported grammar cannot have settings in its front matter, just rules.

What do you think @otac0n ?

@otac0n
Copy link
Owner

otac0n commented Dec 31, 2016

Are you familiar with the ability to -export rules and use them with a #parse{} expression?

https://github.com/otac0n/Pegasus/wiki/How-Do-I...-%3F#how-do-i-reference-an-exported-rule-from-another-parser

I don't like the idea of appending the text of another file directly halfway through the parse. Instead, I could see this being a sort of extension on the -export flag. For example, we could parse the other grammar, find the -export rules, and emit code relatively similar to:

@members
{
    OtherNamespace.OtherClassName __other = new OtherNamespace.OtherClassName();
}

ruleA <ruleAType> = #parse{ this.__other.Exported.ruleA(ref cursor); }
ruleB <ruleBType> = #parse{ this.__other.Exported.ruleB(ref cursor); }

@attilah
Copy link
Author

attilah commented Dec 31, 2016

Sure I read the docs, but what I'd like to have is not to copy the basic rules. For example how would the reuse of a EOL or WS rule look like? not so nice with the current #parse syntax.

Grammar inheritance which ends in basic class inheritance can also nice, but that restricts the grammar reuse to an inheritance chain.

@otac0n
Copy link
Owner

otac0n commented Dec 31, 2016

I'm just saying that plain text concatenation won't really work and that in the meantime all I can offer is what is currently supported.

@otac0n
Copy link
Owner

otac0n commented Dec 31, 2016

We need to consider cases where Grammar.peg references Lib1.peg and Lib2.peg which both reference a fourth file, Shared.peg

Another thing to consider, how would you export rules imported from another file?

A third case: Grammar.peg references Lib1.peg and Lib2.peg which both define a "WS" rule. Which one wins?

@otac0n
Copy link
Owner

otac0n commented Jan 2, 2017

Relevant discussion: pegjs/pegjs#38

@otac0n
Copy link
Owner

otac0n commented Jan 2, 2017

I would like input on this syntax proposal which is inspired by TypeScript's modules.

@import { a, b, c, whtespace as ws } from OtherNamespace.Lib3;

Because this would be incompatible with the existing syntax for rules it would qualify as a breaking change. So, I would also like to propose a syntax option that is a non-breaking change:

@import { a, b, c, whtespace as ws from OtherNamespace.Lib3 };

@furesoft
Copy link

furesoft commented Oct 9, 2019

i really like the typescript syntax

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

3 participants