Skip to content

How to make a recoverable indentation block parser #561

Open
@bingis-khan

Description

@bingis-khan

I'm writing an indentation parser and I want to recover from one certain type of error: indentation that is larger than reference indentation, but unequal to indentation set by the block parser.

Ex:

f ()
  x = 1
  y = 2
    z = 5
 pass
      n = 1
  return

As you can see, it's obvious that the statements are correct and belong to the same block. It's just that the indentation is all weird.

I want to report the error and continue parsing "block items" after this, including the incorrectly indented statement.
This would require me to catch the error some time during the execution of this function.

What would be the best approach to do that?

  • use indentedItems (which is not currently exported), get the indentation ref and call indentedItems after an error?
  • write a specific recoverableIndentBlock which handles this exact case? <-- I'll attempt this one

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions