lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In the following example there are two grammars, where `grammar2'
is actually just a subset of `grammar1'. Is it possible to get rid
of `grammar2'? That is, is it possible to change the initial rule
of `grammar1' in between?

Ciao
Andreas



require 'lpeg'

rule_a = lpeg.V 'rule_a'
rule_b = lpeg.V 'rule_b'
rule_c = lpeg.V 'rule_c'

grammar1 = lpeg.P{
   'rule_a';
   rule_a = '[' * rule_b * ']';
   rule_b = rule_c * (',' * rule_b)^0;
   rule_c = lpeg.R('az')/print;
}

grammar2 = lpeg.P{
   'rule_c';
   rule_c = lpeg.R('az')/print;
}

lpeg.match(grammar1, '[a,b,c]')
lpeg.match(grammar2, 'a')