Skip to content

Parser for Variables saved in a Map #177

Closed Answered by renggli
nank1ro asked this question in Q&A
Discussion options

You must be logged in to vote

I am not entirely sure I understand the question, or the input language you are trying to parse.

That said, with the continuation parser you can dynamically create new parsers at parse-time. The following example first only parses first and second; and then in the last line after changing the list of variables it also accepts third:

final variables = ['first', 'second'];
final parser = failure<String>().callCC((continuation, context) => variables
      .map((each) => each.toParser())
      .toChoiceParser()
      .parseOn(context));

expect(parser, isParseSuccess('first'));
expect(parser, isParseSuccess('second'));
expect(parser, isParseFailure('third'));

variables.add('third');
expect(p…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nank1ro
Comment options

Answer selected by nank1ro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants