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)
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)
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)
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)
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]
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))
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])
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")
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")
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")
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)
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")
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")
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")
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])
def t_ANY_error(t): # noqa: N802 value = t.value if len(value) > 10: value = value[:10] raise ParserException("", t.lineno, t.lexpos, value)
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")