Menu

infinite loop with delimitedList and lineEnd

2006-04-11
2013-05-14
  • Erick Tryzelaar

    Erick Tryzelaar - 2006-04-11

    got a bug where pyparsing enters into an infinite loop with the following code.

    lineEnds = OneOrMore(lineEnd).suppress()
    line = delimitedList(Word(alphas), lineEnds)

    line.parseString('a')

    Strangely, if I redefine lineEnd to be Literal('\n'), it runs fine. Any idea what's going on?

    -e

     
    • Paul McGuire

      Paul McGuire - 2006-04-11

      The problem is that LineEnd also matches the end-of-string.  The bug that you have hit is that, when matching on end-of-string, LineEnd does not advance the parse location.  So the current release will match the end-of-string as an infinite number of LineEnd's.

      Overwriting with a Literal("\n") is okay, as long as you know that the file ends with a terminating \n, or if your BNF is such that it does not care about the string ending case.

      I've corrected this in the current pyparsing code, so that LineEnd will only match a single time as the end-of-string.

      -- Paul

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.