Пример #1
0
def p_error(p):
    p_error.error = True
    if p:
        print ("Syntax error in line %d" % p.lineno)
    else:
        print ("Syntax error: unexpected end of file!")
    yacc.restart()
Пример #2
0
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()
Пример #3
0
def p_error(p):
    print "Error de sintaxis en la linea",
    print p.lineno -1 ,
    print ", columna: " + str(find_column(p.lexer.lexdata,p)),
    print ": token inesperado:",
    print p.value
    yacc.restart()
Пример #4
0
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
Пример #5
0
 def p_erro(self, p):
     if p:
         print("Erro Sintático: %s, linha %d \n" % (p.valor, p.lineno))
     else:
         yacc.restart()
         print("Erro Sintático: definições incompletas!")
     exit(1)
Пример #6
0
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()
Пример #7
0
def p_error(t):
    if t:
        print ("Erro sintático: '%s' Linha '%d" % (t.value, t.lineno))
        exit(1)
    else:
        yacc.restart()
        print ("Erro sintático")
        exit(1)
Пример #8
0
 def p_error(self, p):
     if p:
         print(
             "erro sintático: não foi possível reconher '%s' na linha %d" %
             (p.value, p.lineno))
     else:
         yacc.restart()
         print("erro sintático: definições incompletas!")
Пример #9
0
 def p_error(self, p):
     if p:
         print("Erro sintático: '%s', linha %d" % (p.value, p.lineno))
         exit(1)
     else:
         yacc.restart()
         print('Erro sintático: definições incompletas!')
         exit(1)
Пример #10
0
def p_error(p):
    if p:
        print("Erro sintático: '%s', linha %d" % (p.value, p.lineno))
        exit(1)
        #p.lexer.skip(1)
    else:
        yacc.restart()
        print('Erro sintático: definições incompletas!')
        exit(1)
Пример #11
0
def p_error(p):
    if p:
        # print("Erro sintático na linha %d - Posição %d: '%s'" % (p.lineno, p.lexpos, p.value))
        print("Erro sintático na linha %d: '%s' após sentença estranha" %
              (p.lineno - 20, p.value))
        exit(1)
    else:
        yacc.restart()
        print("Erro sintático nas definições!")
        exit(1)
Пример #12
0
 def p_error(self, p):
      if p:
           self.error = True
           print("Syntax error at line {0}, column {1}: LexToken({2}, '{3}')".format(p.lineno, self.scanner.find_tok_column(p), p.type, p.value))
           while 1:
           	       tok = yacc.token()
           	       if not tok or tok.type == 'RBRACE': break
           yacc.restart()
      else:
           print('At end of input')
Пример #13
0
def p_error(p):
    """Fail, and go to the next line."""
    try:
        sys.stderr.write('Syntax error on line %d on token %s\n' %
                         (p.lexer.lineno, p.type))
    except AttributeError:
        sys.stderr.write('Unexpected EOL\n')
    while True:
        tok = yacc.token()
        if not tok: break
    yacc.restart()
Пример #14
0
def p_error(p):
    if p:
        print("Line %d: Syntax error at '%s'" % (p.lineno, p.value))
    # Scan ahead looking for a name token
    while True:
        tok = yacc.token()
        if not tok or tok.type == 'RPAREN':
            break
    if tok:
        yacc.restart()
    return None
Пример #15
0
def p_error(p):
    if p:
        print("Line %d: Syntax error at '%s'" % (p.lineno, p.value))
    # Scan ahead looking for a name token
    while True:
        tok = yacc.token()
        if not tok or tok.type == 'RPAREN':
            break
    if tok:
        yacc.restart()
    return None
Пример #16
0
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
Пример #17
0
def p_error(token):
    if not token:
        print >> sys.stderr, "ERROR: Unexpected EOF"
    else:
        print >> sys.stderr, "ERROR: line %d parser failure at or near %s" % \
                             (token.lineno, token.type)

        while True:
            tok = yacc.token()
            if not tok or tok.type in recovery_tokens:
                break
        yacc.restart()
Пример #18
0
def p_error(p):
	if p:
		if p.type == 'NEWLINE':
			print("Syntax error :  %s aka %s is not attempt at line %s." % (p.type, "'line jump'", nlines))
		else:
			print("Syntax error :  %s aka %s is not attempt at line %s." % (p.type, str(p.value), nlines))
		while 1:
			tok = yacc.token()             # Get the next token
			if not tok or tok.type == 'NEWLINE': 
		 		break
		yacc.restart()
	else:
		print("Syntax error at EOF")
Пример #19
0
def p_error(p):
    if not p:
        raise ParseError("Reached EOF when parsing file using idioipdae.")

    lines = p.lexer.lexdata.splitlines()
    this_line = lines[p.lineno - 1]

    # Add whole line.
    append_text(p.lexer, this_line + "\n")

    # Forward input to end of line
    while 1:
        tok = yacc.token()
        if not tok or tok.type == 'NEWLINE': break

    yacc.restart()
Пример #20
0
def p_error(p):
    global compilationInfo
    compilationInfo['errors'].append(p)
    if None == p:
        print >> sys.stderr, 'Syntax error (unexpected EOF)'
        compilationInfo['messages'].append('Syntax error: unexpected EOF')
        compilationInfo['lines'].append('END')
        compilationInfo['files'].append(currentFile)
    else:
        print >> sys.stderr, 'Syntax error at token:', p
        compilationInfo['messages'].append("Syntax error at token '%s' [%s]" % (p.value, p.type))
        compilationInfo['lines'].append(p.lineno)
        compilationInfo['files'].append(currentFile)
        while 1:
            tok = yacc.token()
            if not tok or tok.type == 'END': break
        yacc.restart()
Пример #21
0
def p_error(p):
    # print("Syntax Error: '{}' in line {}".format(p.value, p.lineno))
    discard = [p.value]
    while True:
        token = yacc.token()
        if token and token.type != 'NEWLINE':
            discard.append(token.value)
            continue
        else:
            val = '[NEWLINE]' if token else '[EOL]'
            discard.append(val)
            break
    # print('Discard: ', ''.join(discard))
    ErrorCollector.add_yacc_message(
        (p.value, p.lineno, ''.join(discard)),
    )
    yacc.restart()
Пример #22
0
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
Пример #23
0
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
Пример #24
0
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
Пример #25
0
def p_error(t):
	print "Sorry, what did you mean by %s, at line %d?"%(t.value,t.lexer.lineno)
	print "Sorry - Syntax error at token", t.value ,">>", t.type
	sys.exit()
	# Just discard the token and tell the parser it's okay.
	yacc.restart()
Пример #26
0
def p_error(p):
    print "Syntax error in input! %s" % (p)
    yacc.restart()
Пример #27
0
def p_error(p):
    perrors.append(p)
    while 1:
        tok = yacc.token()
        if not tok or tok.value == '}': break
    yacc.restart()
def p_error(p):
    if not p:
        print "There is a catastrophic error in your code. I cannot help you."
    else:
        print "Syntax error at line %s near %s" % (p.lineno, p.value)
        yacc.restart()
Пример #29
0
 def p_error(self, p):
     if p:
         logger.warn('Syntax Error: line %d near "%s"' % (p.lexer.lineno, p.value))
         yacc.restart()
     else:
         logger.warn('Syntax Error at the end of file or file is empty')
Пример #30
0
def parse(text):
	output = yacc.parse(text)
	yacc.restart()
	return output
Пример #31
0
def p_error(p):  # noqa:pep257
    if not p:
        print("There is a catastrophic error in your code. I cannot help you.")
    else:
        print("Syntax error at line %s near %s" % (p.lineno, p.value))
        yacc.restart()