scala / scala/scala-parser-combinators

`|||` parser reports error on only one of the explored branches

Open
#565 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
679
Forks
131
Avg merge
8h 25m
Merged PRs (30d)
3

Description

When both branches of a ||| combinator produce a Failure as a result, the resulting error message is the one coming from the branch that matched the longest chain. This can lead to confusing error messages in situations like this one:

lazy val parser = (intKeyword ~ ...) ||| (doubleKeyword ~ ...)

where the parser outputs an error message like expected 'int'. I think that it would be much less confusing to issue an error message that contains all the possible tokens: expected 'int' or 'double'.

Am I using the API the wrong way, or is there no way of configuring the parser to output such error messages? In the latter case, the addition of such a feature would be much appreciated.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the ||| combinator and its handling of Failure results for the two example branches. Add a regression test using the intKeyword and doubleKeyword parser shape, and consider the work complete when failures from both branches produce an error mentioning both expected tokens.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.