Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Literals empty list causes IndexError #8

Closed
wnissen opened this issue Dec 21, 2011 · 2 comments
Closed

Literals empty list causes IndexError #8

wnissen opened this issue Dec 21, 2011 · 2 comments

Comments

@wnissen
Copy link

wnissen commented Dec 21, 2011

If i set:

literals = []

I get:

Traceback (most recent call last):
File "Translator.py", line 379, in
lexer = lex(outputText)
File "Translator.py", line 105, in lex
lexer = lex.lex(reflags=re.VERBOSE, module=LexerPassThrough)
File "ply/lex.py", line 920, in lex
IndexError: list index out of range

Below is a suggested possible patch.

*** lex.py.old  Wed Dec 21 10:44:55 2011
--- lex.py  Wed Dec 21 10:45:28 2011
***************
*** 917,923 ****

      # Get literals specification
      if isinstance(linfo.literals,(list,tuple)):
!         lexobj.lexliterals = type(linfo.literals[0])().join(linfo.literals)
      else:
          lexobj.lexliterals = linfo.literals

--- 917,926 ----

      # Get literals specification
      if isinstance(linfo.literals,(list,tuple)):
!         if linfo.literals:
!             lexobj.lexliterals = type(linfo.literals[0])().join(linfo.literals)
!         else:
!             lexobj.lexliterals = ""
      else:
          lexobj.lexliterals = linfo.literals

I could also see calling iter(linfo.literals) , which would be more Pythonic than an explicit check for list/tuple, but that's maybe going too far.

@dabeaz
Copy link
Owner

dabeaz commented Apr 18, 2012

Fixed in PLY-3.5 (in progress).

@dabeaz dabeaz closed this as completed Apr 18, 2012
@wnissen
Copy link
Author

wnissen commented Apr 18, 2012

Thanks! Ply was exactly what I needed to write a robust quickie translator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants