Skip to content

Problem with custom failure message in parser combinator library #3212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scabug opened this issue Mar 25, 2010 · 2 comments
Closed

Problem with custom failure message in parser combinator library #3212

scabug opened this issue Mar 25, 2010 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented Mar 25, 2010

Not able to generate a custom failure message in the parser combinator library. For a rule like ..

def buy_sell: Parser[BuySell] =
  "to" ~> "buy" ^^^ BUY      |
  "to" ~> "sell" ^^^ SELL     |
  failure("buy or sell expected")

If the input has something (say "bought") other than "buy" or "sell", then the message that gets printed is the default one ..

``sell_ expected but identifier bought found

The main parse call is like the following :-

val str = //.. the string to parse
val tokens = new lexical.Scanner(str)
phrase(order)(tokens) match {
  case Success(order, _) =>
    println(order)
  case Failure(msg, _) => println("Failure: " + msg)
  case Error(msg, _) => println("Error: " + msg)
}

I posted this to scala-user and Martin Odersky responded here - [http://thread.gmane.org/gmane.comp.lang.scala.user/24426/focus=24510] and asked to file a ticket.

@scabug
Copy link
Author

scabug commented Mar 25, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3212?orig=1
Reporter: Debasish Ghosh (debasishg)

@scabug
Copy link
Author

scabug commented Jul 17, 2015

@SethTisue said:
The parser combinators library is now community-maintained. Issues with it are now tracked at scala/scala-parser-combinators#61 instead of here in the Scala JIRA.

Interested community members: if you consider this issue significant, feel free to open a new issue for it on GitHub, with links in both directions.

@scabug scabug closed this as completed Jul 17, 2015
Philippus added a commit to Philippus/scala-parser-combinators that referenced this issue Jun 27, 2018
SethTisue added a commit to scala/scala-parser-combinators that referenced this issue Jul 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants