Пример #1
0
def test_invalid_syntax():
    sc = scanner.Scanner("q1 := !!")
    lex = lexer.Lexer(sc)
    lex.next_token()  # ok
    lex.next_token()  # ok
    with pytest.raises(exceptions.InvalidSyntaxError):
        lex.next_token()
Пример #2
0
def parse(query):
    sc = scanner.Scanner(query)
    lex = lexer.Lexer(sc)
    parser = Parser(lex)
    interpreter = Interpreter(parser)
    interpreter.clear()
    interpreter.to_python()
    return interpreter.SCOPE
Пример #3
0
 def test_line_number_position(self):
     sc = scanner.Scanner("hola\nsoy\n\nga\nbo")
     self.assertEqual(sc.lineno, 1)
     for i in range(5):
         sc.next()
     self.assertEqual(sc.lineno, 2)
     for i in range(5):
         sc.next()
     self.assertEqual(sc.lineno, 4)
Пример #4
0
 def test_position(self):
     sc = scanner.Scanner("hola\n\n\na todos!")
     self.assertEqual(sc.lineno, 1)
     self.assertEqual(sc.index, 0)
     self.assertEqual(sc.colno, 1)
     for i in range(7):
         sc.next()
     self.assertEqual(sc.lineno, 4)
     self.assertEqual(sc.index, 7)
     self.assertEqual(sc.colno, 1)
Пример #5
0
 def test_column_number_position(self):
     sc = scanner.Scanner("hola soy gabo")
     self.assertEqual(sc.colno, 1)
     for i in range(5):
         sc.next()
     self.assertEqual(sc.colno, 6)
     self.assertEqual(sc.char, 's')
     for i in range(4):
         sc.next()
     self.assertEqual(sc.colno, 10)
     self.assertEqual(sc.char, 'g')
Пример #6
0
def test_with_comment2():
    text = ("% this is a comment\n"
            "q1 := select nombre='Gabriel (personas);\n"
            "% oasdlaskdalksjdlaksd\n"
            "% sdksjdksjdkjskdjskdj")
    sc = scanner.Scanner(text)
    lex = lexer.Lexer(sc)
    t = lex.next_token()
    t = lex.next_token()
    t = lex.next_token()
    t = lex.next_token()
    t = lex.next_token()
    assert t.value == "="
    with pytest.raises(exceptions.MissingQuoteError):
        lex.next_token()
Пример #7
0
def test_with_comment():
    sc = scanner.Scanner(("% this is a comment\n"
                          "q1 := select nombre='Gabriel' (personas);\n"
                          "% otro comentario\n"
                          "% lalala\n"
                          "%dddd\n"
                          "% dddd\n\n\n"
                          "q2 := select nombre='Gabriel (personas);"))
    lex = lexer.Lexer(sc)
    for i in range(12):
        token = lex.next_token()
    assert token.value == ":="
    assert lex.sc.lineno == 9
    for i in range(3):
        token = lex.next_token()

    assert token.value == "="
    with pytest.raises(exceptions.MissingQuoteError):
        lex.next_token()
    assert lex.sc.lineno == 9
    assert lex.sc.colno == 41
Пример #8
0
def lexer_bot():
    sc = scanner.Scanner("q1_ := select nombre='Gabriel' (personas);")
    lex = lexer.Lexer(sc)
    return lex
Пример #9
0
def lexer_tokens():
    sc = scanner.Scanner("> < <= >= = <> , ; ( )")
    return lexer.Lexer(sc)
Пример #10
0
 def test_next_char(self):
     sc = scanner.Scanner("hola\na todos!")
     self.assertEqual(sc.char, 'h')
     chars = ['o', 'l', 'a', '\n', 'a']
     for char in chars:
         self.assertEqual(sc.next_char(), char)
Пример #11
0
 def make_lexer(self, text):
     sc = scanner.Scanner(text)
     lex = lexer.Lexer(sc)
     return lex
Пример #12
0
def select_bot():
    sc = scanner.Scanner("q1 := select id=2 (ages);")
    lex = lexer.Lexer(sc)
    par = parser.Parser(lex)
    return par
Пример #13
0
def scanner_bot():
    text = "hola gabo\ncomo estas?\n\n!"
    sc = scanner.Scanner(text)
    return text, sc
Пример #14
0
def test_5():
    sc = scanner.Scanner("\n\n\n\n\nasdasd\n\n  \n  \n\n\n    \n    % asdasd")
    while sc.char:
        sc.next()
    assert sc.lineno == 13
Пример #15
0
 def setUp(self):
     sc = scanner.Scanner("q1 := select id=2 (p);")
     lex = lexer.Lexer(sc)
     self.parser = parser.Parser(lex)