Skip to content

Add ability to defined new parser combinators #323

New issue

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

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

Already on GitHub? # to your account

Open
scabug opened this issue Oct 1, 2009 · 2 comments
Open

Add ability to defined new parser combinators #323

scabug opened this issue Oct 1, 2009 · 2 comments

Comments

@scabug
Copy link

scabug commented Oct 1, 2009

The current parser combinators library is flexible but lacks the ability to easily define new combinators.
For example, in a
grammar that supports JavaTokensParser.wholeNumber and JavaTokensParser.floatingPointNumber literals and an e .. e expression,
1..2 is ambiguous; and 1. is parsed as a floating
point literal.

    import scala.util.parsing.combinator.JavaTokenParsers
    object R extends JavaTokenParsers with Application{
      def RANGE = ":"
      def range_expression = value_expression~RANGE~value_expression
      def value_expression = /* other stuff eventually working down to */ literal_expression
      def literal_expression = ( stringLiteral | floatingPointNumber | wholeNumber | ident )
      println(parseAll(range_expression, "1" + RANGE + "n"))
    }

I'm using 2.7.6-final and want to define a new combinator similar to ANTLR's lookahead guard.

   (Integer "..") => Integer // Prevent 1..2 from being tokenized as 1. followed by .2

Obviously, I can't use => in Scala, but I would like to define something like

  a<~~b

which will parse a and b but reset the Input to just after where a was found. In the 2.8 trunk there is a similar guard(Parser) combinator that is used as a<~guard(b) but that is not yet available.

Currently, it is not easy to add new combinators because other parsers/combinators return type Parser which does not see new combinators. I suppose implicits may help, or http://scala.sygneca.com/patterns/pimp-my-library
but something built into the framework would be better, if possible.

@scabug
Copy link
Author

scabug commented Oct 1, 2009

@scabug
Copy link
Author

scabug commented Oct 1, 2009

@DavidBiesack said:
Adriaan Moors adriaan.moors@cs.kuleuven.be said in email

Yep, feel free to file a ticket to request this enhancement and assign it to
me so it won't be forgotten.

but I can't find an Adriaan in the list of users

Changed component to Standard Library

@scabug scabug closed this as completed Jul 17, 2015
@SethTisue SethTisue transferred this issue from scala/bug Nov 19, 2020
@scala scala deleted a comment from scabug Nov 19, 2020
@SethTisue SethTisue reopened this Nov 19, 2020
@scala scala deleted a comment from scabug Jan 26, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants