Esempio n. 1
0
 def setUp(self):
     super().setUp()
     g = GrammarBuilder()
     g.xy = Terminal('x') | Terminal('y')
     g.yx = Terminal('x') | Terminal('y')
     g.start = flatten(Lookahead('x') + g.xy) | g.yx
     self.grammar = g(start=g.start)
Esempio n. 2
0
 def setUp(self):
     g = GrammarBuilder()
     g.a = Terminal('A')
     g.b = Terminal('B')
     g.c = Terminal('C')
     g.ab = g.a | g.b
     g.start = g.ab + g.ab
     g.whitespace = Regexp(r'\s+')
     self.grammar = g(start=g.start, tokenize=[ignore(g.whitespace)])
Esempio n. 3
0
    def test_default_format(self):
        g = GrammarBuilder()
        g.string = builtins.double_quoted_string
        g.sequence = builtins.py_integer + Terminal('x')
        g.start = g.string | g.sequence | epsilon
        grammar = g(start=g.start)

        format = GrammarFormatter()

        self.assertEqual(
            format(grammar),
            textwrap.dedent(r"""
            string    ::=  r'"(?:\\\\"|[^"])*"'
            sequence  ::=  r'[1-9]\\d*' / '0' / r'0[xX][0-9a-fA-F]+' / r'0[oO][0-7]+' / r'0[0-7]+' / r'0[bB][01]+', 'x'
            start     ::=  string / sequence / ɛ
        """).strip())
Esempio n. 4
0
 def setUp(self):
     super().setUp()
     g = GrammarBuilder()
     g.ab = Terminal('A') | Terminal('B')
     g.seq = repeat(g.ab, separator=',', trailing=True)
     self.grammar = g(start=g.seq)
Esempio n. 5
0
 def setUp(self):
     super().setUp()
     g = GrammarBuilder()
     g.ab = Terminal('A') | Terminal('B')
     g.start = g.ab + g.ab
     self.grammar = g(start=g.start)
Esempio n. 6
0
 def setUp(self):
     super().setUp()
     g = GrammarBuilder()
     g.ab = flatten(Terminal('A') | Terminal('B'))
     g.seq = repeat(g.ab)
     self.grammar = g(start=g.seq)