def p_error(p): if not p: print "Syntax error at EOF" else: errors.append('Unexpected symbol \'{0}\' at line {1}'.format(p.value, p.lineno)) yacc.errok() return yacc.token()
def p_error(t): global error_count global ok_count global last_error_token global last_error_line error_count += 1 if t is not None: if last_error_token is None or t.lexpos != getattr(last_error_token,"lexpos",None): if abs(last_error_line - t.lineno) > 3 and ok_count > 2: try: print_context(t) except: pass last_error_line = t.lineno yacc.errok() ok_count = 0 return ok_count = 0 if t is None: if last_error_token != "EOF": print "ERROR: End of the file reached." last_error_token = "EOF" return t t = yacc.token() yacc.restart() last_error_token = t return t
def p_error(tok): if tok is None: print 'Syntax error at end of input' else: print 'Syntax error at token', tok # Try to continue yacc.errok()
def p_error(p): flag = -1 # print dir(yacc) # assert(False) # print("Syntax error at '%s'" % p.value), # print('\t Error: {}'.format(p)) while 1: tok = yacc.token() # Get the next token if not tok: flag = 1 break if tok.type == 'STATE_END': flag = 0 break if flag == 0: yacc.errok() return tok else: yacc.restart()
def p_error(p): flag=-1; # print dir(yacc) # assert(False) # print("Syntax error at '%s'" % p.value), # print('\t Error: {}'.format(p)) while 1: tok = yacc.token() # Get the next token if not tok: flag=1 break if tok.type == 'STATE_END': flag=0 break if flag==0: yacc.errok() return tok else: yacc.restart()
def p_error(p): """ print(p.lexer.prev.lineno, p.lineno) if p.lexer.prev.lineno < p.lineno or p.type == "RBRACKET": yacc.errok() return """ if p == None: if not restricted() and glob.g_tried_semi == False: t = LexToken() t.type = "SEMI" t.value = ";" t.lexpos = -1 t.lineno = -1 glob.g_lexer.push(t) glob.g_tried_semi = True yacc.errok() else: sys.stderr.write(glob.g_file + ": error: unexpected end of file\n") return else: glob.g_error_pre = p if handle_semi_error(p): t = LexToken() t.type = "SEMI" t.value = ";" t.lexpos = p.lexpos t.lineno = p.lineno #glob.g_lexer.push(t) #glob.g_tried_semi = True yacc.errok() glob.g_error = False return else: glob.g_error = True print_err(p) return if glob.g_error: print_err(glob.g_error_pre) glob.g_error_pre = p glob.g_error = True try: line = int(p.lineno) except: line = p.lineno(1) try: lexdata = p.lexer.lexer.lexdata sline = p.lexer.lexer.lexpos except: lexdata = p.lexer.lexdata sline = p.lexer.lexpos sline = lexdata[sline-40:sline+1]
def p_error(p): global error_number error_number += 1 if p: error_parser.write("Syntax error in line %d, position %d \n" % (p.lineno, p.lexpos)) yacc.errok() else: error_parser.write("Sytax error: unexpected end of file\n")
def p_error(p): if p == None: print "missing token" raise TypeError("Token Missing") else: print "Syntax error at token, unexpected", p.type, "on line", str(p.lineno) # raise TypeError("Unknown Text '%s'" % (p.type)) yacc.errok()
def p_error(self, p): if p: if self.debug: print("SchemeParser-{}: Syntax error at {!r}".format( id(self), p.value)) yacc.errok() else: if self.debug: print("SchemeParser-{}: Syntax error at EOF".format(id(self)))
def p_error(p): if p is None: print 'Unexpected end of file' return if p.type == 'NEWLINE': print 'ignoring whitespace' yacc.errok() else: print 'Unexpected token %s' % p.type
def p_error(p): print("ERR YACC: w linii %d fragment: '%s'" % (p.lineno, p.value)) print("ERR YACC: internals: %s" % p) #while 1: # tok = yacc.token() # print("ERR : odrzucam %s" % tok) # if not tok or tok.type == 'RBRACE': break #yacc.restart() yacc.errok()
def p_error(self, p): if p: if self.debug: print(("SchemeParser-{}: Syntax error at {!r}".format( id(self), p.value))) yacc.errok() else: if self.debug: print(("SchemeParser-{}: Syntax error at EOF".format(id(self))))
def p_error(p): #Record the line number the error is on errLineNo = p.lineno tok = yacc.token() # get the next token while tok != None: if tok.lineno != errLineNo: yacc.errok() return tok else: tok = yacc.token()
def p_error(p): if p: if p.type in tokens: print ("Syntax error in line %d, %s token is reserved word" % (p.lineno, p.type)) else: print ("Syntax error in line %d" % p.lineno) print (p) yacc.errok() else: print ("Sytax error: unexpected end of file!")
def parse_file(filehandle, tracking=0): log = logging.getLogger("sifter") yacc = grammar.parser(errorlog=log) yacc.errok() rules = yacc.parse(filehandle.read(), lexer=lexer.lexer(), tracking=tracking) if not yacc.errorok: raise ply.yacc.YaccError('Syntax error') return rules
def p_error(p): if p != None: print("Syntax error at \nLine: %s, Char: %s, Source: '%s'" % (p.lineno, p.lexpos, p.value)) yacc.errok() else: # don't reinitialize the parser! # thanks incredibly much to dimele's SO question and answer # at http://stackoverflow.com/questions/24627928/ply-lex-yacc-errors-handling print("Unexpected end of input") raise SyntaxError
def p_error(p): print("Error at " + str(p)) # look for the blank line separating block while 1: tok = yacc.token() if not tok: break if tok.type == 'BLANK_LINE': yacc.restart() yacc.errok() return yacc.token() # return the next line after the blank
def p_error(p): if p is None: # raise Exception('Error : Unexpected file ending') tok = lex.LexToken() tok.type = 'NEWLINE' tok.value = None return tok if p.type == 'WHITESPACE': yacc.errok() else: raise Exception('Syntax Error : Unexpected ' + p.type + ' pos = %d' % p.lexpos)
def p_error(self, t): if t is not None: self.ms_gramatica.AddMensaje( MS.Mensaje("Se encontro: " + str(t.value), t.lineno, self.find_column(self.input, t), True, "Sintactico")) yacc.errok() else: self.ms_gramatica.AddMensaje( MS.Mensaje("No se pudo recuperar: ", 0, 0, True, "Sintactico"))
def p_error(p): if p is None: return exception_list.append(SyntaxException("Wrong expression '" + str(p.value) + "'.", p.lineno, pos=p.lexpos)) tok = None while 1: tok = yacc.token() if not tok: break if tok.type == 'SEMI': tok = yacc.token() yacc.errok() return tok
def p_error(p): if p is None: return exception_list.append( SyntaxException("Wrong expression '" + str(p.value) + "'.", p.lineno, pos=p.lexpos)) tok = None while 1: tok = yacc.token() if not tok: break if tok.type == 'SEMI': tok = yacc.token() yacc.errok() return tok
def handle_semi_error(p): tok = p.lexer.peek() if len(p.lexer.peeks) > 1: prev = p.lexer.peeks[-2] else: prev = p.lexer.prev cur = p.lexer.cur if prev == None: prev = tok if cur == None: cur = tok if type(prev) == list: prev = prev[0] if type(cur) == list: cur = cur[0] if type(tok) == list: tok = tok[0] ret = tok == None or cur == None or prev.lineno < tok.lineno ret = ret or tok.type == "RBRACKET" or prev.type == "RBRACKET" ret = ret or cur.type == "RBRACKET" p2 = restricted() if p2 != None and not (prev.type in ["RSBRACKET", "RPAREN"] and restrict_prev() == None): ret = False p = p2 glob.g_line = p.lineno glob.g_lexpos = p.lexpos if ret and not glob.g_tried_semi: t = LexToken() t.type = "SEMI" t.value = ";" t.lineno = cur.lineno t.lexpos = cur.lexpos p.lexer.push(p.lexer.cur) p.lexer.push(t) yacc.errok() glob.g_error = False glob.g_tried_semi = True else: ret = False glob.g_error = True glob.g_error_pre = p return ret
def p_error(p): if p: print "Syntax error at line " + str(p.lineno) print 'Token : {}'.format(p) else: print("Syntax error!") while 1: tok = yacc.token() if tok: if tok.type in ['SEMICOLON','BLOCKEND']: a=0 break yacc.errok() # tok = yacc.token() # yacc.restart() return tok
def p_error(t): if t: line_error = str(t.lexer.lineno) if t.type == "error": token = t.value[0] else: token = get_token(t.value) if not token == "\n": seg.insert_error(line_error,"P:No se reconoce el token "+ token+str(t)) yacc.errok() if len(seg.get_segment().pc)==0: seg.get_segment().pc.append("0000H") else: seg.increment_PC(3) tok = yacc.token() return tok else: print "NONE"
def p_error(t): if t: line_error = str(t.lexer.lineno) if t.type == "error": token = t.value[0] else: token = get_token(t.value) if not token == "\n": seg.insert_error(line_error, "P:No se reconoce el token " + token + str(t)) yacc.errok() if len(seg.get_segment().pc) == 0: seg.get_segment().pc.append("0000H") else: seg.increment_PC(3) tok = yacc.token() return tok else: print "NONE"
def p_error(t): global error_count global ok_count global last_error_token global last_error_line, seen_tokens, last_ok_token debug = False # Poner a True para toneladas de debug. # if error_count == 0: print if t is not None: if last_error_token is None or t.lexpos != getattr( last_error_token, "lexpos", None): if abs(last_error_line - t.lineno) > 4 and ok_count > 1 and error_count < 4: error_count += 1 try: print_context(t) except: pass if debug == True: for tokname, tokln, tokdata in seen_tokens[-32:]: if tokln == t.lineno: print(tokname, tokdata) print(repr(last_ok_token[0])) last_error_line = t.lineno elif abs(last_error_line - t.lineno) > 1 and ok_count > 1: last_error_line = t.lineno yacc.errok() ok_count = 0 return ok_count = 0 if t is None: if last_error_token != "EOF": print("ERROR: End of the file reached.") global endoffile print("Last data:", endoffile) last_error_token = "EOF" return t t = yacc.token() yacc.restart() last_error_token = t return t
def p_error(p): if p: print "Syntax error at line " + str(p.lineno) print 'Token : {}'.format(p) else: print("Syntax error!") # while True: # tok = yacc.token() # if not tok or tok.type == 'DELIM': break # yacc.restart() flag = 0 while 1: token = yacc.token() if not token: break elif token.type in ['DELIM']: flag = 1 break if flag == 1: yacc.errok() return token
def p_error(p): if p: print(colors.error("Syntax error near '%s' at line %d, %d" % (p.value, p.lineno, p.lexpos))) else: print(colors.error("Syntax error at EOF")) if error_handle == 1: print("Trying to discard the token '%s'" % p.value) yacc.errok() elif error_handle == 2: print("Trying to discard the whole sentence which includes '%s'" % p.value) while 1: tok = yacc.token() # Get the next token if not tok or tok.type == ';': break yacc.restart() elif error_handle == 3: print(colors.error("It won't be fixed in p_error")) pass else: print(colors.error("Nothing would take place to fix the error")) errflag[0] = True
def p_error(p): raise NameError( "Syntax error at line {0} col {1}, unexpected '{2}'".format(p.lineno, find_column(input, p), p.value) ) # try: # raise NameError("Syntax error at line {0} col {1}, unexpected '{2}'".format(p.lineno, find_column(input, p), p.value)) # except: # raise NameError("Syntax error") lexer.push_state("err") if p: lexer.pop_state() if p.type == "SEMI": while True: tok = lexer.token() if tok.type != "ASCII": yacc.errok() return tok else: break else: raise NameError("Abrupt file termination")
def p_error(p): if p: print("Syntax error in line %d" % p.lineno) yacc.errok() else: print("Sytax error: unexpected end of file!")
def p_error(p): #print "Syntax error at token", p.type # Just discard the token and tell the parser it's okay. yacc.errok()
def handle_semi_error(p): if glob.g_production_debug: print("in handle_semi_error") tok = p.lexer.peek() if len(p.lexer.peeks) > 1: prev = p.lexer.peeks[-2] else: prev = p.lexer.prev cur = p.lexer.cur if prev == None: prev = tok if cur == None: cur = tok #print("p", prev) #print("c", cur) #print("t", tok) if type(prev) == list: prev = prev[0] if type(cur) == list: cur = cur[0] if type(tok) == list: tok = tok[0] if p != None and type(p) != LexToken: print(list(p)) ret = tok == None or cur == None or prev.lineno < tok.lineno ret = ret or tok.type == "RBRACKET" or prev.type == "RBRACKET" ret = ret or cur.type == "RBRACKET" p2 = restricted() if p2 != None and not (prev.type in ["RSBRACKET", "RPAREN"] and restrict_prev() == None): ret = False p = p2 print(prev.type, cur.type, p2, restrict_prev()) print("didn't handle semi error") glob.g_line = p.lineno glob.g_lexpos = p.lexpos #print_err(p) if ret and not glob.g_tried_semi: #""" t = LexToken() t.type = "SEMI" t.value = ";" t.lineno = cur.lineno t.lexpos = cur.lexpos #""" p.lexer.push(p.lexer.cur) p.lexer.push(t) yacc.errok() glob.g_error = False glob.g_tried_semi = True else: ret = False glob.g_error = True glob.g_error_pre = p #for l in prodname_log[-5:-1]: # print(l) #print("a real error occurred 2!?") #print_err(p) return ret
def p_error(p): print "syntax error in line %3d: %s // %s" % (p.lineno, str(p), str(yacc)) yacc.errok()
def p_error(t): print "Syntax error at", t.value, "type", t.type, "on line", t.lexer.lineno import pdb pdb.set_trace() yacc.errok()
def p_error(p): print "Error: Syntax error in line", str(p.lineno), ": Unexpected token :", str(p.value) yacc.errok() global errors errors += 1 pass
def p_error(p): sys.stdout.write("At Line "+str(p.lineno)+": ") print "Syntax error at token", p.value global error error = True yacc.errok()
def p_error(p) : print("syntax error in line {}".format(p.lineno)) yacc.errok()
def p_error(t): print 'Syntax error around line %d in token %s.' % (t.lineno, t.type) yacc.errok()
def p_error(p): print("parser1: Syntax error in line %d" % p.lineno) yacc.errok()
def p_error(p): """ print(p.lexer.prev.lineno, p.lineno) if p.lexer.prev.lineno < p.lineno or p.type == "RBRACKET": yacc.errok() return """ if glob.g_production_debug: if p == None: print("in p_error") else: print("in p_error", p.type, p.value) if p == None: if not restricted() and glob.g_tried_semi == False: t = LexToken() t.type = "SEMI" t.value = ";" t.lexpos = -1 t.lineno = -1 glob.g_lexer.push(t) glob.g_tried_semi = True yacc.errok() else: sys.stderr.write(glob.g_file + ": error: unexpected end of file\n") return else: glob.g_error_pre = p if handle_semi_error(p): t = LexToken() t.type = "SEMI" t.value = ";" t.lexpos = p.lexpos t.lineno = p.lineno #glob.g_lexer.push(t) #glob.g_tried_semi = True yacc.errok() glob.g_error = False if glob.g_production_debug or glob.g_semi_debug: linestr, colstr = err_find_line(p.lexer, p.lexpos); lineno = p.lineno if type(p.lineno) == int else p.lineno(0) sys.stdout.write("handled semicolon error : %d\n" % lineno) sys.stdout.write(linestr+"\n") sys.stdout.write(colstr+"\n") return else: glob.g_error = True print_err(p) return if glob.g_error: print_err(glob.g_error_pre) glob.g_error_pre = p glob.g_error = True try: line = int(p.lineno) except: line = p.lineno(1) try: lexdata = p.lexer.lexer.lexdata sline = p.lexer.lexer.lexpos except: lexdata = p.lexer.lexdata sline = p.lexer.lexpos sline = lexdata[sline-40:sline+1]
def p_error(p): print("syntax error in line %d" % p.lineno) yacc.errok()
def p_error(p): print('syntax error in line {0}'.format(p.lineno)) yacc.errok()
def p_error(p): if _debugging_script_mode: print "Syntax error at token", p.type, p.value yacc.errok() else: raise SyntaxError
def p_error(p): print ("Syntax error at token", p.type) # Just discard the token and tell the parser it's okay. yacc.errok()
def p_error(p): print("Syntax error at '%s'" % p.value) yacc.errok()
def p_error(t): if t is None: print("Syntax error at '%s'" % t) else: print("Syntax error at '%s'" % t.value) yacc.errok()
def p_error(p): print "Syntax error in line %d" % p.lineno yacc.errok()