Skip to content

Parsing fails when the top node of the grammar isn't used just on top #90

Open

Description

@j-jzk

Suppose the following code:

val bfParser = lesana<List<BfStatement>> {
    val command = NodeID<BfStatement>("command")
    val commandList = include(list(command))

    command to def(re("<+")) { BfStatement.Left(it.v1.length) }
    // ...

    command to def(re("\\["), commandList, re("\\]")) { (_, cmds, _) -> BfStatement.Loop(cmds) }

    ignoreRegexes("[^+\\-<>.,[\\]]")

    setTopNode(commandList)
}.getLesana()

When a [...] loop is encountered, the parser returns just the insides of the loop. This is because when it finishes parsing the loop, it sees the top node type at the top of the stack, so it assumes the parsing is finished. No warning is issued to the programmer about this.

We should mitigate this issue or at least throw an error when we detect a configuration like this.

Activity

  1. added this to the 1.0 milestone on Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions