Menu

#28 indentedBlock does not work with enablePackrat

open
nobody
None
5
2008-10-29
2008-10-29
Eike Welk
No

Packrat parsing seems to interfere with the indentedBlock parser. Some
legitimate input is no longer recognized when packrat parsing is
switched on.

A script to demonstrate the problem is here:
http://pastebin.com/f5b006f4d

When line 7 is uncommented an exception is raised while parsing the
3rd example 'program'.

Maybe I'm using indentedBlock somehow wrongly?

A patch is attached to the bug report, that solves this bug for me. It adds a data attribute "self.noPackrat" to "ParserElement". It switches off packrat parsing for this specific parser when it is set to True. "ParserElement._parseCache" is modified to respect the new attribute.

Discussion

  • Eike Welk

    Eike Welk - 2008-10-29

    File Added: diff_indented_block_fix.txt

     
  • Eike Welk

    Eike Welk - 2008-10-29

    The patch which solves the bug for me.

     
  • Eike Welk

    Eike Welk - 2008-10-29

    File Added: example_indented_block.py

     
  • Eike Welk

    Eike Welk - 2008-10-29

    The test script. To have complete bug description here.

     
  • Paul McGuire

    Paul McGuire - 2008-11-05

    Very likely an incompatibility between packratting and indentedBlock. Thanks for the patch, I'll give it a look over.

    -- Paul

     
  • Eike Welk

    Eike Welk - 2008-11-06

    To explain the patch a bit more:

    Packrat parsing assumes, that a parser always creates the same result for a given input. But this assumption is wrong for the "PEER" parser in "indentedBlock". It changes its mind after backtracking at the end of a block.

    1. - At the end of an indented block, when the indent decreases, "PEER" creates a parse error. This is the reason for the block to end. "UNDENT" then removes one entry from the parse-stack.
    2. - The parser for the enclosing block, with the lower indent, then asks "PEER" to parse the same input again. "PEER" is now supposed to succeed because the parse-stack has changed. This however can't work with packrat parsing because "PEER"'s parse result on this input has been stored in the cache. Instead of asking "PEER" for a second time to parse the input, the parse error will be retrieved and raised again.

    Therefore I have added some infrastructure to exempt individual parsers from caching their results. Maybe these changes are also useful for other parsers that don't work with packrat parsing. (Maybe you know of other parsers that are incompatible with packrat parsing.)

    -- Eike

     
  • Nobody/Anonymous

    Sourceforge.. Nifty :)

     

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.