Scala Programming Language
  1. Scala Programming Language
  2. SI-5192

Parsers.Parser doesn't provide an easy way to override no success messages

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0
    • Component/s: None
    • Labels:
      None

      Description

      Parsers.Parser don't provide an easy way to override error messages. The common idiom for that is unsuspectingly very fragile. I suggest adding two new method, withFailureMessage and withErrorMessage, to provide that functionality. As for the problem, I'll let the comment in my proposed API describe it:

      The semantics are slightly different than those obtained by doing | failure(msg), in that the message produced by this method will always replace the message produced, which is not guaranteed by that idiom.

      For example, parser p below will always produce the designated failure message, while q will not produce it if sign is parsed but number is not.

      def p = sign.? ~ number withFailureMessage  "Number expected!"
      def q = sign.? ~ number | failure("Number expected!")
      

        Activity

        Hide
        Daniel Sobral added a comment -

        This is implemented by pull request https://github.com/scala/scala/pull/114.

        Show
        Daniel Sobral added a comment - This is implemented by pull request https://github.com/scala/scala/pull/114 .
        Hide
        Daniel Sobral added a comment -

        The proposed patch was accepted, this issue can be closed.

        Show
        Daniel Sobral added a comment - The proposed patch was accepted, this issue can be closed.

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Daniel Sobral
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development