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
Parser.withSource() parser #16
Conversation
Parser<T>.withSource() parser applies this parser and returns its result along with matches string. .token() parser could be used instead of .withSource(), however sometimes WithSource is more convenient, because global string object has to be stored somewhere to resolve token into string. Also, WithSource class is type-parameterized, unlike Token.
Hi Stepan, Regards, |
Yes, use case seems to be the same as in #5: I need to get the source of parser along with result of parser, for example, to perform syntax highlighting. As far as I understood, official recommendation is to use Token. With Token Parser cannot be created with static function, and has refer string stored outside. See comments in this code:
Lack of (BTW, now I think better |
Another alternative suggested in the thread, is to use the Parsers.INDEX static Parser<WithSource> withSource(Parser parser) { The only difference is that it's a static method, not a Parser instance On Wed, Feb 19, 2014 at 12:15 PM, Stepan Koltsov
|
@fluentfuture |
That's right. It assumes that you already have the raw string at the time Can you help us understand your use of the source string a bit more? How is On Wed, Feb 19, 2014 at 1:15 PM, Stepan Koltsov notifications@github.comwrote:
|
@fluentfuture everything can be implemented with indices. It just less convenient: I have to explicitly pass original string to parser construction code. |
So, I'm just imagining a syntax highlighter. It's possibly too simplistic Parser parser = or( class Colored { render(Parser<List> parser, String text) { On Wed, Feb 19, 2014 at 1:48 PM, Stepan Koltsov notifications@github.comwrote:
|
Parser<T>.withSource()
parser applies this parser and returns itsresult along with matches string.
.token()
parser could be used instead of.withSource()
, howeversometimes
WithSource
is more convenient, because global stringobject has to be stored somewhere to resolve token into string.
Also,
WithSource
class is type-parameterized, unlike Token.