Versuch, Ausdruck wie zu analysieren Name (arg1, arg2 ...)
Also versuche ich:
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, ")"
Zuerst habe ich versucht, Gen von List abzuleiten, aber dann bekomme ich es GrammarTypeError: in der Grammatik: "("
Ich verstehe nicht, was es bedeutet, von "str" oder von "Liste" abgeleitet zu werden. Wo finde ich eine Erklärung?
Antworten:
0 für die Antwort № 1Probieren Sie diese Änderungen aus:
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)