Exemplo n.º 1
0
def p_error(p: YaccProduction) -> None:
    pos = lexer.lexpos - lexer.linestart + 1
    r = Range(file, lexer.lineno, pos, lexer.lineno, pos)

    if p is None:
        # at end of file
        raise ParserException(r, None, "Unexpected end of file")

    # keyword instead of ID
    if p.type in reserved.values():
        if hasattr(p.value, "location"):
            r = p.value.location
        raise ParserException(
            r, str(p.value),
            "invalid identifier, %s is a reserved keyword" % p.value)

    if parser.symstack[-1].type in reserved.values():
        if hasattr(parser.symstack[-1].value, "location"):
            r = parser.symstack[-1].value.location
        raise ParserException(
            r, str(parser.symstack[-1].value),
            "invalid identifier, %s is a reserved keyword" %
            parser.symstack[-1].value)

    raise ParserException(r, p.value)
Exemplo n.º 2
0
def t_ANY_error(t: lex.LexToken) -> lex.LexToken:  # noqa: N802
    lexer = t.lexer

    end = lexer.lexpos - lexer.linestart + 1
    char: str = t.value[0]
    r: Range = Range(lexer.inmfile, lexer.lineno, end, lexer.lineno, end + 1)
    raise ParserException(r, char, "Illegal character '%s'" % char)
Exemplo n.º 3
0
def p_error(p):
    if p is None:
        # at end of file
        raise ParserException(file, lexer.lineno, lexer.lexpos,
                              "Unexpected end of file")

    # keyword instead of ID
    if p.type in reserved.values():
        raise ParserException(
            file, p.lineno, p.lexpos, p.value,
            "invalid identifier, %s is a reserved keyword" % p.value)

    if parser.symstack[-1].type in reserved.values():
        raise ParserException(
            file, p.lineno, p.lexpos, p.value,
            "invalid identifier, %s is a reserved keyword" %
            parser.symstack[-1].value)

    raise ParserException(file, p.lineno, p.lexpos, p.value)
Exemplo n.º 4
0
def p_boolean_expression(p: YaccProduction) -> None:
    """boolean_expression : expression CMP_OP expression
    | expression IN expression
    | expression AND expression
    | expression OR expression"""
    operator = Operator.get_operator_class(str(p[2]))
    if operator is None:
        raise ParserException(p[1].location, str(p[1]),
                              f"Invalid operator {str(p[1])}")
    p[0] = operator(p[1], p[3])
    attach_lnr(p, 2)
Exemplo n.º 5
0
def p_string_dict_key(p: YaccProduction) -> None:
    """dict_key : STRING"""

    key = str(p[1])
    match_obj = format_regex_compiled.findall(key)
    if len(match_obj) != 0:
        raise ParserException(
            p[1].location,
            str(p[1]),
            "String interpolation is not supported in dictionary keys. Use raw string to use a key containing double curly brackets",  # NOQA E501
        )
    p[0] = p[1]
Exemplo n.º 6
0
def t_REGEX(t: lex.LexToken) -> lex.LexToken:  # noqa: N802
    r"/([^/\\]|\\.)+/"
    value = Reference("self")  # anonymous value
    try:
        expr = Regex(value, t.value[1:-1])
        t.value = expr
        return t
    except RegexError as error:
        end = t.lexer.lexpos - t.lexer.linestart + 1
        (s, e) = t.lexer.lexmatch.span()
        start = end - (e - s)

        r: Range = Range(t.lexer.inmfile, t.lexer.lineno, start,
                         t.lexer.lineno, end)
        raise ParserException(r, t.value,
                              "Regex error in %s: '%s'" % (t.value, error))
Exemplo n.º 7
0
def p_attr_list_dict_null_err(p: YaccProduction) -> None:
    "attr : DICT ID '=' NULL"
    raise ParserException(
        p[2].location, str(p[2]),
        'null can not be assigned to dict, did you mean "dict? %s = null"' %
        p[2])
Exemplo n.º 8
0
def p_entity_extends_err(p: YaccProduction) -> None:
    "entity_def : ENTITY ID EXTENDS class_ref_list ':' entity_body_outer"
    raise ParserException(
        p[2].location, str(p[2]),
        "Invalid identifier: Entity names must start with a capital")
Exemplo n.º 9
0
def p_entity_err_1(p: YaccProduction) -> None:
    "entity_def : ENTITY ID ':' entity_body_outer"
    raise ParserException(
        p[2].location, str(p[2]),
        "Invalid identifier: Entity names must start with a capital")
Exemplo n.º 10
0
def p_class_ref_list_term_err(p: YaccProduction) -> None:
    "class_ref_list : var_ref"

    raise ParserException(
        p[1].location, str(p[1]),
        "Invalid identifier: Entity names must start with a capital")
Exemplo n.º 11
0
 def as_assign(self, value: ExpressionStatement, list_only: bool = False) -> AssignStatement:
     if list_only:
         raise ParserException(self.location, "+=", "Can not perform += on variable %s" % self.name)
     return Assign(self.name, value)
Exemplo n.º 12
0
def p_entity_extends_err(p):
    "entity_def : ENTITY ID EXTENDS class_ref_list ':' entity_body_outer "
    raise ParserException(
        file, p.lineno(2), p.lexpos(2), p[2],
        "Invalid identifier: Entity names must start with a capital")
Exemplo n.º 13
0
def p_class_ref_list_term_err(p):
    'class_ref_list : var_ref'
    raise ParserException(
        file, p[1].location.lnr, p[1].lexpos, p[1],
        "Invalid identifier: Entity names must start with a capital")
Exemplo n.º 14
0
def p_class_ref_list_collect_err(p):
    """class_ref_list : var_ref ',' class_ref_list"""
    raise ParserException(
        file, p.lineno(1), p.lexpos(1), p[1],
        "Invalid identifier: Entity names must start with a capital")
Exemplo n.º 15
0
def p_attr_list_dict_null_err(p):
    "attr : DICT ID '=' NULL"
    raise ParserException(
        file, p.lineno(1), p.lexpos(1), p[2],
        "null can not be assigned to dict, did you mean \"dict? %s = null\"" %
        p[2])
Exemplo n.º 16
0
def t_ANY_error(t):  # noqa: N802
    value = t.value
    if len(value) > 10:
        value = value[:10]
    raise ParserException("", t.lineno, t.lexpos, value)
Exemplo n.º 17
0
def p_entity_err_1(p):
    "entity_def : ENTITY ID ':' entity_body_outer "
    raise ParserException(
        file, p.lineno(2), p.lexpos(2), p[2],
        "Invalid identifier: Entity names must start with a capital")