pypeg:str或List是什么意思?

时间:2015-02-05 20:38:59

标签: python parsing

尝试解析表达式 名(ARG1,ARG2 ...)

所以我试试:

from pypeg2 import *

class Type (str):
    grammar = attr ('type', re.compile (r'[a-z]+'))

class args (List):
    grammar = maybe_some ( csl (word) )

class Gen (str):
    grammar = Type, '(', args, ')'

首先我尝试从List中派生出Gen,但后来我得到了 GrammarTypeError:在语法中:'('

我不明白从' str'或从' List'衍生出来的意义。我在哪里可以找到解释?

1 个答案:

答案 0 :(得分:0)

尝试此更改:

from __future__ import unicode_literals, print_function
import re
from pypeg2 import *

class Type (str):
    grammar = attr ('type', Symbol)

class args (List):
    grammar = maybe_some ( csl (word) )

class Gen (str):
    grammar = Type, '(', args, ')'

teste = "name(arg1,arg2, arg3)"

k = parse(teste, Gen)

print(k)