seancribbs/neotoma — Issue #9: [Feature request] Include rules from other files 
Author: dmitriid
Created: 2011-11-17 09:13:22+00:00
State: open

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"