Пример #1
0
 def test_pair(self):
     text = '-f -x'
     expect = NonTerminal(document(), [
         NonTerminal(body(), [
             NonTerminal(element(), [
                 NonTerminal(option_line(), [
                     NonTerminal(option_list(), [
                         NonTerminal(ol_first_option(), [
                             NonTerminal(option(), [
                                 Terminal(short_no_arg(), 0, '-f'),
                             ]),
                         ]),
                         NonTerminal(ol_term_with_separator(), [
                             NonTerminal(ol_separator(), [
                                 NonTerminal(ol_space(), [
                                     Terminal(StrMatch(' '), 0, ' '),
                                 ]),
                             ]),
                             NonTerminal(ol_term(), [
                                 NonTerminal(option(
                                 ), [Terminal(short_no_arg(), 0, '-x')]),
                             ]),
                         ]),
                     ]),
                     Terminal(EOF(), 0, ''),
                 ]),
             ]),
         ]),
         Terminal(EOF(), 0, ''),
     ])
     self.parse_and_verify(text, expect)
Пример #2
0
 def test_single_short_no_arg(self):
     text = '-f'
     expect = create_expect(
         NonTerminal(option(), [Terminal(short_no_arg(), 0, '-f')]),
         eof=(text[-1] != '\n'),
     )
     self.parse_and_verify(text, expect)
Пример #3
0
    def test_create_expect(self):

        text = '-f -x -l'

        expect = create_expect(
            NonTerminal(option(), [Terminal(short_no_arg(), 0, '-f')]),
            NonTerminal(option(), [Terminal(short_no_arg(), 0, '-x')]),
            NonTerminal(option(), [Terminal(short_no_arg(), 0, '-l')]),
            eof=(text[-1] != '\n'),
        )

        # print("[ expect ]")
        # pp(expect[0][0][0][0][1])

        parsed = self.parse(text, expect)
        # tprint("[parsed]") ; pp(parsed)

        # print("[ parsed ]")
        # pp(parsed[0][0][0][0][1])

        self.verify(text, expect, parsed)
Пример #4
0
    def test_single_short_no_arg (self):
        text = '-f'
        parsed = self.parser.parse(text)
        # tprint("[parsed]") ; pp(parsed)
        expect = create_expect (
            NonTerminal( option(), [Terminal(short_no_arg(), 0, '-f')] )
        )

        assert nodes_equal(parsed, expect, verbose=True), \
            ( f"[expect]\n{pp_str(expect)}\n"
              f"[parsed]\n{pp_str(parsed)}"
              f"text = '{text}' :\n" )
Пример #5
0
 def test_single_short_w_arg(self):
     text = '-fNORM'
     expect = create_expect(
         NonTerminal(option(), [
             NonTerminal(short_adj_arg(), [
                 Terminal(short_adj_arg__option(), 0, '-f'),
                 NonTerminal(operand(), [
                     Terminal(operand_all_caps(), 0, 'NORM'),
                 ]),
             ]),
         ]),
         eof=(text[-1] != '\n'),
     )
     self.parse_and_verify(text, expect)
Пример #6
0
 def test_single_short_with_one_arg (self):
     text = '-fNORM'
     parsed = self.parser.parse(text)
     # tprint("[parsed]") ; pp(parsed)
     expect = create_expect (
         NonTerminal( option(), [
             NonTerminal( short_adj_arg(), [
                 Terminal( short_adj_arg__option(), 0, '-f' ) ,
                 NonTerminal( operand(), [
                     Terminal( operand_all_caps(), 0, 'NORM' ) ,
                 ]) ,
             ]) ,
         ]) ,
     )
Пример #7
0
 def test_single(self):
     text = '-f'
     expect = NonTerminal(document(), [
         NonTerminal(body(), [
             NonTerminal(element(), [
                 NonTerminal(option_line(), [
                     NonTerminal(option_list(), [
                         NonTerminal(ol_first_option(), [
                             NonTerminal(option(), [
                                 Terminal(short_no_arg(), 0, '-f'),
                             ]),
                         ]),
                     ]),
                     Terminal(EOF(), 0, ''),
                 ]),
             ]),
         ]),
         Terminal(EOF(), 0, ''),
     ])
     self.parse_and_verify(text, expect)
Пример #8
0
def term__short_adj_arg(opt, op):
    return NonTerminal( option(), [
        NonTerminal( short_adj_arg(),
                     [ Terminal( short_adj_arg__option(), 0, opt ) ,
                       term__operand(op) ], ) ])
Пример #9
0
def term__short_no_arg(opt):
    return NonTerminal( option(), [ Terminal( short_no_arg(), 0, opt ) ] )
Пример #10
0
def term__long_eq_arg(opt, op):
    return NonTerminal( option(), [
        NonTerminal( long_eq_arg(),
                     [ Terminal( long_no_arg(), 0, opt ) ,
                       t_eq,
                       term__operand(op) ], ) ])
Пример #11
0
def term__long_no_arg(opt):
    return NonTerminal( option(), [ Terminal( long_no_arg(), 0, opt ) ] )