How to use the ply.yacc.token function in ply

To help you get started, we’ve selected a few ply examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dabeaz / ply / test / yacc_error7.py View on Github external
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
github asimihsan / notes / src / programming_languages / ps6 / htmlgrammar.py View on Github external
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)
github alexkasko / krakatau-java / krakatau-lib / src / main / resources / Lib / Krakatau / assembler / parse.py View on Github external
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()
github openembedded / bitbake / lib / bb / pysh / pyshyacc.py View on Github external
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))
github intel / luv-yocto / bitbake / lib / bb / pysh / pyshyacc.py View on Github external
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))
github openembedded / openembedded-core / bitbake / lib / bb / pysh / pyshyacc.py View on Github external
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))
github alibaba / AliOS-Things-Linux-Edition / bitbake / lib / bb / pysh / pyshyacc.py View on Github external
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))
github openbmc / openbmc / import-layers / yocto-poky / bitbake / lib / bb / pysh / pyshyacc.py View on Github external
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))
github google / capirca / capirca / lib / policy.py View on Github external
def p_error(p):
  """."""
  next_token = yacc.token()
  if next_token is None:
    use_token = 'EOF'
  else:
    use_token = repr(next_token.value)

  if p:
    raise ParseError(' ERROR on "%s" (type %s, line %d, Next %s)'
                     % (p.value, p.type, p.lineno, use_token))
  else:
    raise ParseError(' ERROR you likely have unablanaced "{"\'s')