[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: lpeg: subset of a grammar
- From: Andreas Matthias <andreas.matthias@...>
- Date: Wed, 18 Aug 2010 18:47:44 +0200
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')