[go: up one dir, main page]

Skip to content

Compiling fails for grammars containing macros which expand into grammars

This should work:

grammar one_nest = {"(" find:one_nest? ")"} end

It does not compile, but it should. And it should match "()", "(abc def)", "(abc (def()))" and the like.

$ echo "()" | rosie --rpl 'grammar one_nest = {"(" find:one_nest? ")"} end' match one_nest
Cannot load rpl: 
Compile error
	[compiler]: peg compilation error: rule 'one_nest' undefined in given grammar
	in user input :1:30: grammar one_nest = {"(" find:one_nest? ")"} end
Compile error
	[compiler]: undefined identifier: one_nest
	in user input :1:1: one_nest
$ 

The failure to compile is likely due to the fact that the macro find expands into a grammar expression (something that is used internally, and is not yet exposed at the RPL language level). Nested grammar expressions should work, with the nested scopes that one would expect. Therefore, within the scope of the one_nest grammar, the one_nest binding should be visible (because grammars are recursive).

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information