Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
def p_error(t):
        if tag_stack[0] != []: 
                print "HTML Syntax Error: <" + tag_stack[0][0] + "> on line " + str(tag_stack[0][1]) + " never closed" 
        else: 
                tok = yacc.token() 
                print "HTML Syntax Error: Near Token " + str(tok) 
        exit(1) 
Ejemplo n.º 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()
Ejemplo n.º 7
0
def p_error(t):
        if tag_stack[0] != []:
                print("HTML Syntax Error: <" + tag_stack[0][0] + "> on line " + str(tag_stack[0][1]) + " never closed")
        else:
                tok = yacc.token()
                print("HTML Syntax Error: Near Token " + str(tok))
        exit(1)
Ejemplo n.º 8
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()
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
def p_error(p):
    # Error production
    tok = yacc.token()
    if tok is None:
        syntax_error('Unexpected end of file')
    else:
        syntax_error('Unexpected token "%s"' % tok.value, lineno = tok.lineno)
Ejemplo n.º 11
0
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()
Ejemplo n.º 12
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
Ejemplo n.º 13
0
def p_error(p):
    if p is None:
        print "Syntax error: unexpected EOF"
    else: #remember to subtract 1 from line number since we had a newline at the start of the file
        print "Syntax error at line {}: unexpected token {!r}".format(p.lineno-1, p.value)

    #Ugly hack since Ply doesn't provide any useful error information
    import inspect
    frame = inspect.currentframe()
    cvars = frame.f_back.f_locals
    print 'Expected:', ', '.join(cvars['actions'][cvars['state']].keys())
    print 'Found:', cvars['ltype']
    print 'Current stack:', cvars['symstack']

    #Discard the rest of the input so that Ply doesn't attempt error recovery
    from ply import yacc
    tok = yacc.token()
    while tok is not None:
        tok = yacc.token()
Ejemplo n.º 14
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')
Ejemplo n.º 15
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()
Ejemplo n.º 16
0
def p_error(p):
    msg = []
    w = msg.append
    w('%r\n' % p)
    w('followed by:\n')
    for i in range(5):
        n = yacc.token()
        if not n:
            break
        w('  %r\n' % n)
    raise sherrors.ShellSyntaxError(''.join(msg))
Ejemplo n.º 17
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
Ejemplo n.º 18
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
Ejemplo n.º 19
0
def p_error(p):
    if p is None:
        print "Syntax error: unexpected EOF"
    else:  #remember to subtract 1 from line number since we had a newline at the start of the file
        print "Syntax error at line {}: unexpected token {!r}".format(
            p.lineno - 1, p.value)

    #Ugly hack since Ply doesn't provide any useful error information
    import inspect
    frame = inspect.currentframe()
    cvars = frame.f_back.f_locals
    print 'Expected:', ', '.join(cvars['actions'][cvars['state']].keys())
    print 'Found:', cvars['ltype']
    print 'Current stack:', cvars['symstack']

    #Discard the rest of the input so that Ply doesn't attempt error recovery
    from ply import yacc
    tok = yacc.token()
    while tok is not None:
        tok = yacc.token()
Ejemplo n.º 20
0
def p_error(p):
    msg = []
    w = msg.append
    w('%r\n' % p)
    w('followed by:\n')
    for i in range(5):
        n = yacc.token()
        if not n:
            break
        w('  %r\n' % n)
    raise sherrors.ShellSyntaxError(''.join(msg))
Ejemplo n.º 21
0
    def p_error(self, p):
        self.errors += 1
        message = "Line {line}: Syntax error at '{value}'. "
        logging.error(message.format(line=p.lineno, value=p.value))

        # Panic mode に突入, 特定のトークンまで読み飛ばす
        while True:
            token = yacc.token()
            if not token or token.type in ('SEMICOLON', 'RBRACE',):
                break
        # 構文解析を再開
        self.parser.restart()
Ejemplo n.º 22
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()
Ejemplo n.º 23
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")
Ejemplo n.º 24
0
def p_error(t):
    i = 0
    cad = ''
    while True:
        tok = yacc.token()
        if not tok or not i < 5:
            break
        i += 1
        cad += str(tok.value) + " "
    mensaje_error = "Caracter invalido '{c}' cerca de {cad}".format(
        c=t.value,
        cad=cad)  #Esto se hace ya que el parser sigue incrementando lineno
    raise ParseError(mensaje_error)
Ejemplo n.º 25
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()
Ejemplo n.º 26
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()
Ejemplo n.º 27
0
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
Ejemplo n.º 28
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()
Ejemplo n.º 29
0
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"
Ejemplo n.º 30
0
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"
Ejemplo n.º 31
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
Ejemplo n.º 32
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
Ejemplo n.º 33
0
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
Ejemplo n.º 34
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
Ejemplo n.º 35
0
	def p_error(self, p):
		next_t = yacc.token()
		raise ParseError("invalid code before %s (at line %s)" % (repr(next_t.value), next_t.lineno))
Ejemplo n.º 36
0
def p_error(p):
    if p:
        print(yacc.token())
    else:
        print("error at EOF")
Ejemplo n.º 37
0
def p_error(p):
    print "Syntax error in input! " + str(p) + " " + str(yacc.token())
Ejemplo n.º 38
0
def p_error(p):
    print("Error:",p)
    print("Next token:",yacc.token())
    assert 0
Ejemplo n.º 39
0
def p_error(p):
    print "Syntax error in input! " + str(p) + " " + str(yacc.token())
Ejemplo n.º 40
0
def p_error(p):
    perrors.append(p)
    while 1:
        tok = yacc.token()
        if not tok or tok.value == '}': break
    yacc.restart()
Ejemplo n.º 41
0
 def p_error(self, p):
     print "Syntax error in input on line %d, column %d." % (p.lineno,
                                                             p.lexpos)
     # print "Error at token: %r" % self.parser.token()
     print "Error at token: %r" % yacc.token()
Ejemplo n.º 42
0
 def p_error(t):
     print("Error before token %s." % yacc.token())
Ejemplo n.º 43
0
def p_error(p):
    print("Error:", p)
    print("Next token:", yacc.token())
    assert 0
Ejemplo n.º 44
0
 def p_error(self, p):
     raise TypeError('Error on %s and %s, next: %s' % (p.value, p.type, yacc.token()))