Ejemplo n.º 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()
Ejemplo n.º 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
Ejemplo n.º 3
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()
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def lexer_bot():
    sc = scanner.Scanner("q1_ := select nombre='Gabriel' (personas);")
    lex = lexer.Lexer(sc)
    return lex
Ejemplo n.º 6
0
def lexer_tokens():
    sc = scanner.Scanner("> < <= >= = <> , ; ( )")
    return lexer.Lexer(sc)
Ejemplo n.º 7
0
 def make_lexer(self, text):
     sc = scanner.Scanner(text)
     lex = lexer.Lexer(sc)
     return lex
Ejemplo n.º 8
0
def select_bot():
    sc = scanner.Scanner("q1 := select id=2 (ages);")
    lex = lexer.Lexer(sc)
    par = parser.Parser(lex)
    return par
Ejemplo n.º 9
0
 def setUp(self):
     sc = scanner.Scanner("q1 := select id=2 (p);")
     lex = lexer.Lexer(sc)
     self.parser = parser.Parser(lex)