• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python ebnfparse.parse_ebnf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypy.rlib.parsing.ebnfparse.parse_ebnf函数的典型用法代码示例。如果您正苦于以下问题:Python parse_ebnf函数的具体用法?Python parse_ebnf怎么用?Python parse_ebnf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parse_ebnf函数的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: make_parser_from_file

def make_parser_from_file(filename):
    try:
        t = py.path.local(filename).read(mode='U')
        regexs, rules, ToAST = parse_ebnf(t)
    except ParseError, e:
        print e.nice_error_message(filename=filename, source=t)
        raise
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:main.py


示例3: setup_class

 def setup_class(cls):
     from pypy.rlib.parsing.parsing import PackratParser
     regexs, rules, ToAST = parse_ebnf(grammar)
     cls.ToAST = ToAST()
     cls.parser = PackratParser(rules, rules[0].nonterminal)
     cls.regexs = regexs
     names, regexs = zip(*regexs)
     cls.lexer = Lexer(list(regexs), list(names))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:test_pythonparse.py


示例4: 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


示例5: 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


示例6: 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


示例7: 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


示例8: test_leftrecursion

def test_leftrecursion():
    regexs, rules, ToAST = parse_ebnf("""
A: "a";
B: "b";
IGNORE: " |\n";
expr1: A | expr2 A;
expr2: expr1 B;
""")
    py.test.raises(AssertionError, make_parse_function, regexs, rules, True)
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:test_ebnfparse.py


示例9: 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


示例10: 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


示例11: 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


示例12: 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


示例13: parse

def parse(code):
    GFILE = open_file_as_stream(abspath(join(dirname(__file__), "grammar.txt")))

    t = None
    try:
        t = GFILE.read()
        regexs, rules, ToAST = parse_ebnf(t)
    except ParseError,e:
        print e.nice_error_message(filename=str(GFILE),source=t)
        raise
开发者ID:heynemann,项目名称:aquesta,代码行数:10,代码来源:aquesta.py


示例14: 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


示例15: 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


示例16: 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


示例17: test_check_for_missing_names

def test_check_for_missing_names():
    regexs, rules, ToAST = parse_ebnf("""
IGNORE: " ";
DECIMAL: "0|[1-9][0-9]*";
additive: multitive "+" additive | multitive;
multitive: primary "*" multitive | primari; # observe the typo
# the following too!
primary: "(" additive ")" | DECIMAL;
""")
    excinfo = py.test.raises(ValueError, make_parse_function, regexs, rules)
    assert "primari" in str(excinfo.value)
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:test_ebnfparse.py


示例18: 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


示例19: 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


示例20: 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



注:本文中的pypy.rlib.parsing.ebnfparse.parse_ebnf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python rarithmetic.intmask函数代码示例发布时间:2022-05-27
下一篇:
Python ebnfparse.make_parse_function函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap