Parse token+position with parser combinators

132 views
Skip to first unread message

Simon Schäfer

unread,
Sep 12, 2012, 6:17:40 PM9/12/12
to scala-user
I want to know if it is possible to parse tokens + their position +
their length with Scalas parser combinators.

I tried to use JavaTokenParsers but they seem not be the best way to
achieve what I want. My current progress: https://gist.github.com/3709623

Main problems are the ugly notation of the tokens and wrong
determination of positions (I can't find out a way to get the length of
identifiers without adding count of whitespace).

StandardTokenParsers are better to parse tokens, I assume, but they
neither offer a simple way to return the position of a token.

Need I to build may own position based token parser? If yes, does
someone know some projects/examples which already tried to do the same?

Luke Vilnis

unread,
Sep 12, 2012, 6:59:15 PM9/12/12
to Simon Schäfer, scala-user
Could you accomplish what you want by copying RegexParsers and modifying to include the (start, end) info from the regex match groups?

Simon Schäfer

unread,
Sep 12, 2012, 8:18:24 PM9/12/12
to scala...@googlegroups.com
Nice tip! I didn't think at that. I got it to work:
https://gist.github.com/3709623

Not quite perfect. Probably I need to copy the contents of
RegexParsers/JavaTokenParsers and edit them with my changes but when
that will be the only problem I come to, that's a good solution. Thanks!

On Thu 13 Sep 2012 12:59:15 AM CEST, Luke Vilnis wrote:
> Could you accomplish what you want by copying RegexParsers and
> modifying to include the (start, end) info from the regex match groups?
>
> On Wed, Sep 12, 2012 at 6:17 PM, Simon Schäfer <ma...@antoras.de
> <mailto:ma...@antoras.de>> wrote:
>
> I want to know if it is possible to parse tokens + their position
> + their length with Scalas parser combinators.
>
> I tried to use JavaTokenParsers but they seem not be the best way
> to achieve what I want. My current progress:
> https://gist.github.com/__3709623 <https://gist.github.com/3709623>
Reply all
Reply to author
Forward
0 new messages