私はpyparsingでパーサーを書こうとしています。これが私の文法定義の抜粋です。
import pyparsing as pp
Modifier = pp.Word(pp.alphas)
Name = pp.Literal("foobar")
Sentence = pp.Optional(Modifier) + Name + pp.Group(pp.OneOrMore(Modifier))
サンプル文字列を解析すると、次のようになります。
>>> print Sentence.parseString("testA FOOBAR testB testC")
['testA', 'FOOBAR', ['testB', 'testC']]
上記の文法規則を変更して、最初のオプションの修飾子を次のグループにプッシュする方法はありますか?
例:
>>> print MagicSentence.parseString("test A FOOBAR testB testC")
['FOOBAR', ['testA', 'testB', 'testC']]