本文整理汇总了Python中pypy.rlib.parsing.ebnfparse.make_parse_function函数的典型用法代码示例。如果您正苦于以下问题:Python make_parse_function函数的具体用法?Python make_parse_function怎么用?Python make_parse_function使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_parse_function函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_parse_python_args
def test_parse_python_args():
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
NAME: "[a-zA-Z_]*";
NUMBER: "0|[1-9][0-9]*";
parameters: ["("] >varargslist<? [")"];
varargslist: (fpdef ("=" test)? [","])* star_or_starstarargs |
fpdef ("=" test)? ([","] fpdef ("=" test)?)* [","]?;
star_or_starstarargs: "*" NAME [","] "**" NAME | "*" NAME | "**" NAME;
fpdef: <NAME> | "(" <fplist> ")";
fplist: fpdef ([","] fpdef)* [","]?;
test: NUMBER;
""")
parse = make_parse_function(regexs, rules)
t = parse("(a)").visit(ToAST())[0]
t = parse("(a,)").visit(ToAST())[0]
t = parse("(a,b,c,d)").visit(ToAST())[0]
t = parse("(a,b,c,d,)").visit(ToAST())[0]
t = parse("((a, b, c),b,c,d,)").visit(ToAST())[0]
t = parse("((a, b, (d, e, (f, g))), b, *args, **kwargs)").visit(ToAST())[0]
t = parse("((a, b, c),b,c,d,*args)").visit(ToAST())[0]
t = parse("((a, b, c),b,c,d,**kwargs)").visit(ToAST())[0]
t = parse("((a, b, c),b,c,d,*args, **args)").visit(ToAST())[0]
t = parse("()").visit(ToAST())[0]
t = parse("(*args, **args)").visit(ToAST())[0]
t = parse("(a=1)").visit(ToAST())[0]
t = parse("(a=2,)").visit(ToAST())[0]
t = parse("(a,b,c,d=3)").visit(ToAST())[0]
t = parse("(a,b,c,d=4,)").visit(ToAST())[0]
t = parse("((a, b, c),b,c,(c, d)=1,)").visit(ToAST())[0]
t = parse("((a, b, c),b,c,d=1,*args)").visit(ToAST())[0]
t = parse("((a, b, c),b,c,d=2,**kwargs)").visit(ToAST())[0]
t = parse("((a, b, c),b,c,(c, d)=4,*args, **args)").visit(ToAST())[0]
t = parse("(self, a, b, args)").visit(ToAST())[0]
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:34,代码来源:test_pythonparse.py
示例2: parse_js
def parse_js( path ):
regexs, rules, ToAST = parse_ebnf(ebnf)
parse = make_parse_function(regexs, rules, eof=True)
doc = open(path, 'r').read()
t = parse(doc)
t = ToAST().transform(t)
return t
开发者ID:khskrede,项目名称:mehh,代码行数:8,代码来源:parser.py
示例3: test_nest_star_and_questionmark
def test_nest_star_and_questionmark():
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
y: x "END";
x: "B" ("A" "B"?)*;
""")
parse = make_parse_function(regexs, rules)
t = ToAST().transform(parse("B A B A B END"))
t = ToAST().transform(parse("B A A A END"))
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:test_ebnfparse.py
示例4: test_example1
def test_example1():
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
n: "a" "b" "c" m;
m: "(" <n> ")" | "d";
""")
parse = make_parse_function(regexs, rules)
t = parse("a b c (a b c d)")
t = ToAST().transform(t)
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:test_ebnfparse.py
示例5: test_example2
def test_example2():
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
DECIMAL: "0|[1-9][0-9]*";
list: DECIMAL >list< | DECIMAL;
""")
parse = make_parse_function(regexs, rules)
t = parse("1 2 3 4 5")
t = ToAST().transform(t)
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:test_ebnfparse.py
示例6: test_escape_quotes
def test_escape_quotes():
regexs, rules, ToAST = parse_ebnf("""
QUOTE: "a\\"";
IGNORE: " ";
expr: QUOTE "\\"" EOF;""")
parse = make_parse_function(regexs, rules, eof=True)
t = parse('a" "')
assert t.children[0].additional_info == 'a"'
assert t.children[1].additional_info == '"'
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:test_ebnfparse.py
示例7: test_mix_star_and_questionmark
def test_mix_star_and_questionmark():
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
y: x "END";
x: "B" ("A" "B")* "A"?;
""")
parse = make_parse_function(regexs, rules)
t = ToAST().transform(parse("B A B END"))
assert len(t.children[0].children) == 3
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:test_ebnfparse.py
示例8: test_starred_star
def test_starred_star():
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
start: ("b"* "a")* EOF;
""")
parse = make_parse_function(regexs, rules, eof=True)
for s in ["b b b b a b b a", "b a b a", "a a", ""]:
t = parse(s)
t = ToAST().transform(t)
assert [c.additional_info for c in t.children] == (s + " EOF").split()
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:test_ebnfparse.py
示例9: test_double_star
def test_double_star():
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " |\n";
start: "a"* "b"* "c";
""")
parse = make_parse_function(regexs, rules, eof=True)
for s in ["a a a b b c", "a b b c", "a a c", "b b c", "c"]:
t = parse(s)
t = ToAST().transform(t)
assert [c.additional_info for c in t.children] == s.split()
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:test_ebnfparse.py
示例10: test_grouping_only_parens
def test_grouping_only_parens():
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
x: ["m"] ("a" "b") "c" | <y>;
y: ["n"] "a" "b" "c";
""")
parse = make_parse_function(regexs, rules)
t0 = ToAST().transform(parse("m a b c"))
t1 = ToAST().transform(parse("n a b c"))
assert len(t0.children) == len(t1.children)
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:test_ebnfparse.py
示例11: test_clash_literal_nonterminal
def test_clash_literal_nonterminal():
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
y: x "END";
x: "y";
a: "x";
""")
parse = make_parse_function(regexs, rules)
py.test.raises(ParseError, parse, "x END")
parse("y END")
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:test_ebnfparse.py
示例12: test_lexer_end_string_corner_case
def test_lexer_end_string_corner_case():
regexs, rules, ToAST = parse_ebnf("""
NUMBER: "[0-9]*(\.[0-9]+)?";
ATOM: "\.";
IGNORE: " ";
expr: NUMBER ATOM EOF;
""")
parse = make_parse_function(regexs, rules, eof=True)
t = parse("2.")
assert t.children[0].additional_info == "2"
assert t.children[1].additional_info == "."
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:test_ebnfparse.py
示例13: test_quoting
def test_quoting():
regexs, rules, ToAST = parse_ebnf("""
ATOM: "[a-z]*";
IGNORE: " ";
list: ATOM "\n" ATOM;
""")
parse = make_parse_function(regexs, rules, eof=True)
t = parse("""abc
abd""")
assert len(t.children) == 3
assert t.children[1].additional_info == "\n"
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:test_ebnfparse.py
示例14: test_bug
def test_bug():
# this could be seen as using the transformer in the wrong way
# but I have no clue how to detect this situation
py.test.skip("fix me somehow")
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
DECIMAL: "0|[1-9][0-9]*";
list: DECIMAL >list< | <DECIMAL>;
""")
parse = make_parse_function(regexs, rules)
t = parse("1 2 3 4 5")
t = ToAST().transform(t)
开发者ID:alkorzt,项目名称:pypy,代码行数:12,代码来源:test_ebnfparse.py
示例15: test_transform_greater_than
def test_transform_greater_than():
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
x: ["a"] >b< "c";
b: "A" "A";
""")
parse = make_parse_function(regexs, rules)
t = parse("a A A c")
t = ToAST().transform(t)
assert len(t.children) == 3
assert t.children[0].additional_info == "A"
assert t.children[1].additional_info == "A"
assert t.children[2].additional_info == "c"
开发者ID:alkorzt,项目名称:pypy,代码行数:13,代码来源:test_ebnfparse.py
示例16: test_plus
def test_plus():
regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
x: "A"+ "B";
""")
parse = make_parse_function(regexs, rules)
t = parse("A A B")
t = ToAST().transform(t)
assert len(t.children) == 3
assert t.children[0].additional_info == "A"
assert t.children[1].additional_info == "A"
assert t.children[2].additional_info == "B"
py.test.raises(ParseError, parse, "B")
开发者ID:alkorzt,项目名称:pypy,代码行数:13,代码来源:test_ebnfparse.py
示例17: test_toast
def test_toast():
regexs, rules, ToAST = parse_ebnf("""
DECIMAL: "0|[1-9][0-9]*";
IGNORE: " ";
additive: multitive ["+!"] additive | <multitive>;
multitive: primary ["*!"] multitive | <primary>; #nonsense!
primary: "(" <additive> ")" | <DECIMAL>;
""")
parse = make_parse_function(regexs, rules)
tree = parse("(0 +! 10) *! (999 +! 10) +! 1")
tree = tree.visit(ToAST())[0]
assert len(tree.children) == 2
assert tree.children[0].children[0].symbol == "additive"
assert tree.children[1].symbol == "DECIMAL"
开发者ID:alkorzt,项目名称:pypy,代码行数:14,代码来源:test_ebnfparse.py
示例18: print_dot
def print_dot( path ):
regexs, rules, ToAST = parse_ebnf(ebnf)
parse = make_parse_function(regexs, rules, eof=True)
f = open(path, 'r')
doc = f.read()
t = parse(doc)
t = ToAST().transform(t)
print "digraph parsed {"
print "\n".join(list(t.dot()))
print "}"
开发者ID:khskrede,项目名称:mehh,代码行数:14,代码来源:parser.py
示例19: test_long_inline_quotes
def test_long_inline_quotes():
regexs, rules, transformer = parse_ebnf("""
DECIMAL: "0|[1-9][0-9]*";
IGNORE: " ";
additive: multitive "+!" additive | multitive;
multitive: primary "*!" multitive | primary; #nonsense!
primary: "(" additive ")" | DECIMAL;
""")
class MyEvalVisitor(EvaluateVisitor):
def visit_primary(self, node):
if len(node.children) == 3:
return node.children[1].visit(self)
return int(node.children[0].additional_info)
parse = make_parse_function(regexs, rules)
tree = parse("0 +! 10 +! 999")
assert tree.visit(MyEvalVisitor()) == 10 + 999
开发者ID:alkorzt,项目名称:pypy,代码行数:16,代码来源:test_ebnfparse.py
示例20: parse_func
def parse_func(start=None):
if start is not None:
parse_function = make_parse_function(regexs, setstartrule(rules, start),
eof=True)
else:
parse_function = get_defaultparse()
def methodparse(self, text):
tree = parse_function(text)
if start is not None:
assert tree.symbol == "hacked_first_symbol"
tree = tree.children[0]
tree = tree.visit(ToAST())[0]
if conftest.option and conftest.option.view:
tree.view()
return tree
return methodparse
开发者ID:rafaelcaricio,项目名称:lang-js,代码行数:17,代码来源:test_parser.py
注:本文中的pypy.rlib.parsing.ebnfparse.make_parse_function函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论