Skip to content

Unordered parsing? #71

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

You must be logged in to vote

This is not something that is typically specified in the grammar itself. Instead it is validated either while building your model (see example below), or in a separate pass after the model has been created:

// ...
final fragment = string('STAGE:').token() & entry.plus();
final start = fragment.map((values) => new Fragment(values[0], values[1]));

class Fragment {
  final Token startToken;
  final List<Entry> entries;

  Fragment(this.startToken, this.entries) {
    final keys = entries.map(entry => entry.key);
    if (keys.toSet().length != keys.length) {
      throw new Exception('Repeated entries at ${startToken.start}: $keys');
    }
  }
}

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by renggli
Comment options

You must be logged in to vote
0 replies
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
Converted from issue

This discussion was converted from issue #71 on December 08, 2020 19:56.