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] Include rules from other files #9

Open
dmitriid opened this issue Nov 17, 2011 · 2 comments
Open

[Feature request] Include rules from other files #9

dmitriid opened this issue Nov 17, 2011 · 2 comments

Comments

@dmitriid
Copy link

I don't know if this is feasible at all, but for some grammars this could be very well worth it. So, rationale and other incoherent thoughts follow:

Sometimes you need to parse a grammar which is a combination of different grammars. For example, Markdown and Textile include rules for HTML, most grammars include definitions for newlines and white spaces, large grammars could be split into a number of blocks that define various aspects of the grammar in question.

So, perhaps it is possible to give the grammar author the possibility to include relevant rules from external files?

Something along the lines:

main.peg

    document <- block1 block2 block3

    %% retrieve block2 rule from block2.peg
    block1 <- ``block1.peg``

    %% assign some_rule definition to block2 from block2.peg
    block2 <- ``block2.peg:some_rule``

    block3 <- sub_block1 sub_block2

    %% retrieve all rule definitions from sub_blocks.peg
    ``sub_blocks.peg``

block1.peg

   block1 <- "some text"

block2.peg

   some_rule <- "some other rule"

sub_blocks.peg

    sub_block1 <- "rule1" 
    sub_block2 <- "rule2" 

So, when run, Neotoma would work on the following resulting file:

    document <- block1 block2 block3

    %% retrieve block2 rule from block2.peg
    block1 <- "some text"

    %% assign some_rule definition to block2 from block2.peg
    block2 <- "some other rule"

    block3 <- sub_block1 sub_block2

    %% retrieve all rule definitions from sub_blocks.peg

    sub_block1 <- "rule1" 
    sub_block2 <- "rule2" 
@superbobry
Copy link
Contributor

Any hints on how this might be implemented? I was thinking something like the following might work:

$ cat foo.peg
foo <- bar:baz SP boo
$ cat bar.peg
bar <- [a-z]+

@seancribbs
Copy link
Owner

I've been working on a refactoring recently that might make this more feasible. I'll keep you informed.

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

No branches or pull requests

3 participants