Add "exclude" to Parser.next to explicitly ignore "on" when necessary

This commit is contained in:
Tobe O 2019-03-31 16:29:10 -04:00
parent de6c9f5bef
commit 2a01c249b1
2 changed files with 11 additions and 8 deletions

View file

@ -16,8 +16,9 @@ class Parser {
Token get current => _current;
bool next(TokenType type) {
if (peek()?.type == type) {
bool next(TokenType type, {Iterable<String> exclude}) {
var tok = peek();
if (tok?.type == type && exclude?.contains(tok.span.text) != true) {
_current = tokens[++_index];
return true;
}
@ -27,7 +28,6 @@ class Parser {
bool nextName(String name) {
var tok = peek();
if (tok?.type == TokenType.NAME && tok.span.text == name) {
return next(TokenType.NAME);
}
@ -140,7 +140,7 @@ class Parser {
FragmentSpreadContext parseFragmentSpread() {
if (next(TokenType.ELLIPSIS)) {
var ELLIPSIS = current;
if (next(TokenType.NAME)) {
if (next(TokenType.NAME, exclude: ['on'])) {
var NAME = current;
return new FragmentSpreadContext(ELLIPSIS, NAME)
..directives.addAll(parseDirectives());

View file

@ -73,10 +73,13 @@ class _IsSelectionSet extends Matcher {
bool matches(item, Map matchState) {
var set =
item is SelectionSetContext ? item : parseSelectionSet(item.toString());
print('Item: $set has ${set.selections.length} selection(s):');
for (var s in set.selections) {
print(' * $s (${s.span.text})');
}
// if (set != null) {
// print('Item: $set has ${set.selections.length} selection(s):');
// for (var s in set.selections) {
// print(' * $s (${s.span.text})');
// }
// }
if (set == null) return false;
if (set.selections.length != selections.length) return false;