コード例 #1
0
    def test_squareBrackets(self):
        ast = Parser(Lexer('A = [ B ] ;')).grammar()

        self.assertEqual(len(ast), 1)
        self.assertEqual(ast[0].rule, Token('A', Token.RULE))
        self.assertEqual(ast[0].stmt.__class__.__name__, "Optional")
        self.assertEqual(ast[0].stmt.token, Token('B', Token.RULE))
コード例 #2
0
    def test_curlyBrackets(self):
        ast = Parser(Lexer('A = { B } ;')).grammar()

        self.assertEqual(len(ast), 1)
        self.assertEqual(ast[0].rule, Token('A', Token.RULE))
        self.assertEqual(ast[0].stmt.__class__.__name__, "Repetition")
        self.assertEqual(ast[0].stmt.token, Token('B', Token.RULE))
コード例 #3
0
    def test_brackets(self):
        ast = Parser(Lexer('A = ( B ) ;')).grammar()

        self.assertEqual(len(ast), 1)
        self.assertEqual(ast[0].rule, Token('A', Token.RULE))
        self.assertEqual(ast[0].stmt.__class__.__name__, "Grouping")
        self.assertEqual(ast[0].stmt.token, Token('B', Token.RULE))
コード例 #4
0
    def test_idAndId(self):
        ast = Parser(Lexer('A = B , C ;')).grammar()

        self.assertEqual(len(ast), 1)
        self.assertEqual(ast[0].rule, Token('A', Token.RULE))
        self.assertEqual(ast[0].stmt.__class__.__name__, "Concatenation")
        self.assertEqual(ast[0].stmt.lhs, Token('B', Token.RULE))
        self.assertEqual(ast[0].stmt.rhs, Token('C', Token.RULE))
コード例 #5
0
    def test_multiline(self):
        ast = Parser(Lexer('A = ( B );\nB = "C" ;')).grammar()

        self.assertEqual(len(ast), 2)

        self.assertEqual(ast[0].rule, Token('A', Token.RULE))
        self.assertEqual(ast[0].stmt.__class__.__name__, "Grouping")
        self.assertEqual(ast[0].stmt.token, Token('B', Token.RULE))

        self.assertEqual(ast[1].rule, Token('B', Token.RULE))
        self.assertEqual(ast[1].stmt, Token('C', Token.LITERAL))
コード例 #6
0
    def test_Parse(self):
        ast = Parser(Lexer('letter = "A" ;')).grammar()

        self.assertEqual(len(ast), 1)
        self.assertEqual(ast[0].rule, Token('letter', Token.RULE))
        self.assertEqual(ast[0].stmt, Token('A', Token.LITERAL))
コード例 #7
0
    def test_id(self):
        ast = Parser(Lexer('A = B ;')).grammar()

        self.assertEqual(len(ast), 1)
        self.assertEqual(ast[0].rule, Token('A', Token.RULE))
        self.assertEqual(ast[0].stmt, Token('B', Token.RULE))