diff --git a/graphql_parser/README.md b/graphql_parser/README.md index b90fa864..a91d3e49 100644 --- a/graphql_parser/README.md +++ b/graphql_parser/README.md @@ -33,7 +33,7 @@ import 'package:graphql_parser/graphql_parser.dart'; doSomething(String text) { var tokens = scan(text); - var parser = new Parser(tokens); + var parser = Parser(tokens); if (parser.errors.isNotEmpty) { // Handle errors... diff --git a/graphql_parser/example/example.dart b/graphql_parser/example/example.dart index 5a3f1be4..aabba873 100644 --- a/graphql_parser/example/example.dart +++ b/graphql_parser/example/example.dart @@ -11,7 +11,7 @@ final String text = ''' main() { var tokens = scan(text); - var parser = new Parser(tokens); + var parser = Parser(tokens); var doc = parser.parseDocument(); var operation = doc.definitions.first as OperationDefinitionContext; diff --git a/graphql_parser/lib/src/language/ast/string_value.dart b/graphql_parser/lib/src/language/ast/string_value.dart index 1fa664fb..8789c886 100644 --- a/graphql_parser/lib/src/language/ast/string_value.dart +++ b/graphql_parser/lib/src/language/ast/string_value.dart @@ -24,7 +24,7 @@ class StringValueContext extends InputValueContext { } var codeUnits = text.codeUnits; - var buf = new StringBuffer(); + var buf = StringBuffer(); for (int i = 0; i < codeUnits.length; i++) { var ch = codeUnits[i]; @@ -35,9 +35,9 @@ class StringValueContext extends InputValueContext { c2 = codeUnits[++i], c3 = codeUnits[++i], c4 = codeUnits[++i]; - var hexString = new String.fromCharCodes([c1, c2, c3, c4]); + var hexString = String.fromCharCodes([c1, c2, c3, c4]); var hexNumber = int.parse(hexString, radix: 16); - buf.write(new String.fromCharCode(hexNumber)); + buf.write(String.fromCharCode(hexNumber)); continue; } @@ -64,7 +64,7 @@ class StringValueContext extends InputValueContext { buf.writeCharCode(next); } } else - throw new SyntaxError('Unexpected "\\" in string literal.', span); + throw SyntaxError('Unexpected "\\" in string literal.', span); } else { buf.writeCharCode(ch); } diff --git a/graphql_parser/lib/src/language/ast/variable.dart b/graphql_parser/lib/src/language/ast/variable.dart index e8fb4bdb..96222aee 100644 --- a/graphql_parser/lib/src/language/ast/variable.dart +++ b/graphql_parser/lib/src/language/ast/variable.dart @@ -14,5 +14,5 @@ class VariableContext extends InputValueContext { @override Object computeValue(Map variables) => variables[name]; - // new FileSpan(DOLLAR?.span?.start, NAME?.span?.end, toSource()); + // FileSpan(DOLLAR?.span?.start, NAME?.span?.end, toSource()); } diff --git a/graphql_parser/lib/src/language/lexer.dart b/graphql_parser/lib/src/language/lexer.dart index 85ff83c0..7d5d2658 100644 --- a/graphql_parser/lib/src/language/lexer.dart +++ b/graphql_parser/lib/src/language/lexer.dart @@ -4,14 +4,14 @@ import 'syntax_error.dart'; import 'token.dart'; import 'token_type.dart'; -final RegExp _comment = new RegExp(r'#[^\n]*'); -final RegExp _whitespace = new RegExp('[ \t\n\r]+'); -// final RegExp _boolean = new RegExp(r'true|false'); -final RegExp _number = new RegExp(r'-?[0-9]+(\.[0-9]+)?(E|e(\+|-)?[0-9]+)?'); -final RegExp _string = new RegExp( +final RegExp _comment = RegExp(r'#[^\n]*'); +final RegExp _whitespace = RegExp('[ \t\n\r]+'); +// final RegExp _boolean = RegExp(r'true|false'); +final RegExp _number = RegExp(r'-?[0-9]+(\.[0-9]+)?(E|e(\+|-)?[0-9]+)?'); +final RegExp _string = RegExp( r'"((\\(["\\/bfnrt]|(u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])))|([^"\\]))*"'); -final RegExp _blockString = new RegExp(r'"""(([^"])|(\\"""))*"""'); -final RegExp _name = new RegExp(r'[_A-Za-z][_0-9A-Za-z]*'); +final RegExp _blockString = RegExp(r'"""(([^"])|(\\"""))*"""'); +final RegExp _name = RegExp(r'[_A-Za-z][_0-9A-Za-z]*'); final Map _patterns = { '@': TokenType.ARROBA, @@ -42,7 +42,7 @@ final Map _patterns = { List scan(String text, {sourceUrl}) { List out = []; - var scanner = new SpanScanner(text, sourceUrl: sourceUrl); + var scanner = SpanScanner(text, sourceUrl: sourceUrl); while (!scanner.isDone) { List potential = []; @@ -54,14 +54,14 @@ List scan(String text, {sourceUrl}) { for (var pattern in _patterns.keys) { if (scanner.matches(pattern)) { - potential.add(new Token( + potential.add(Token( _patterns[pattern], scanner.lastMatch[0], scanner.lastSpan)); } } if (potential.isEmpty) { - var ch = new String.fromCharCode(scanner.readChar()); - throw new SyntaxError("Unexpected token '$ch'.", scanner.emptySpan); + var ch = String.fromCharCode(scanner.readChar()); + throw SyntaxError("Unexpected token '$ch'.", scanner.emptySpan); } else { // Choose longest token potential.sort((a, b) => b.text.length.compareTo(a.text.length)); diff --git a/graphql_parser/lib/src/language/parser.dart b/graphql_parser/lib/src/language/parser.dart index fff390f5..64bd6476 100644 --- a/graphql_parser/lib/src/language/parser.dart +++ b/graphql_parser/lib/src/language/parser.dart @@ -60,7 +60,7 @@ class Parser { def = parseDefinition(); } - return new DocumentContext()..definitions.addAll(defs); + return DocumentContext()..definitions.addAll(defs); } DefinitionContext parseDefinition() => @@ -69,7 +69,7 @@ class Parser { OperationDefinitionContext parseOperationDefinition() { var selectionSet = parseSelectionSet(); if (selectionSet != null) - return new OperationDefinitionContext(null, null, null, selectionSet); + return OperationDefinitionContext(null, null, null, selectionSet); else { if (nextName('mutation') || nextName('query') || @@ -80,11 +80,11 @@ class Parser { var dirs = parseDirectives(); var selectionSet = parseSelectionSet(); if (selectionSet != null) - return new OperationDefinitionContext( + return OperationDefinitionContext( TYPE, NAME, variables, selectionSet) ..directives.addAll(dirs); else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing selection set in fragment definition.', NAME?.span ?? TYPE.span)); return null; @@ -106,29 +106,29 @@ class Parser { var dirs = parseDirectives(); var selectionSet = parseSelectionSet(); if (selectionSet != null) - return new FragmentDefinitionContext( + return FragmentDefinitionContext( FRAGMENT, NAME, ON, typeCondition, selectionSet) ..directives.addAll(dirs); else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Expected selection set in fragment definition.', typeCondition.span)); return null; } } else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Expected type condition after "on" in fragment definition.', ON.span)); return null; } } else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Expected "on" after name "${NAME.text}" in fragment definition.', NAME.span)); return null; } } else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Expected name after "fragment" in fragment definition.', FRAGMENT.span)); return null; @@ -142,7 +142,7 @@ class Parser { var ELLIPSIS = current; if (next(TokenType.NAME, exclude: ['on'])) { var NAME = current; - return new FragmentSpreadContext(ELLIPSIS, NAME) + return FragmentSpreadContext(ELLIPSIS, NAME) ..directives.addAll(parseDirectives()); } else { _index--; @@ -162,11 +162,11 @@ class Parser { var directives = parseDirectives(); var selectionSet = parseSelectionSet(); if (selectionSet != null) { - return new InlineFragmentContext( + return InlineFragmentContext( ELLIPSIS, ON, typeCondition, selectionSet) ..directives.addAll(directives); } else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing selection set in inline fragment.', directives.isEmpty ? typeCondition.span @@ -174,13 +174,13 @@ class Parser { return null; } } else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing type condition after "on" in inline fragment.', ON.span)); return null; } } else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing "on" after "..." in inline fragment.', ELLIPSIS.span)); return null; } @@ -202,10 +202,10 @@ class Parser { eatCommas(); if (next(TokenType.RBRACE)) - return new SelectionSetContext(LBRACE, current) + return SelectionSetContext(LBRACE, current) ..selections.addAll(selections); else { - errors.add(new SyntaxError('Missing "}" after selection set.', + errors.add(SyntaxError('Missing "}" after selection set.', selections.isEmpty ? LBRACE.span : selections.last.span)); return null; } @@ -215,13 +215,13 @@ class Parser { SelectionContext parseSelection() { var field = parseField(); - if (field != null) return new SelectionContext(field); + if (field != null) return SelectionContext(field); var fragmentSpread = parseFragmentSpread(); if (fragmentSpread != null) - return new SelectionContext(null, fragmentSpread); + return SelectionContext(null, fragmentSpread); var inlineFragment = parseInlineFragment(); if (inlineFragment != null) - return new SelectionContext(null, null, inlineFragment); + return SelectionContext(null, null, inlineFragment); else return null; } @@ -232,7 +232,7 @@ class Parser { var args = parseArguments(); var directives = parseDirectives(); var selectionSet = parseSelectionSet(); - return new FieldContext(fieldName, selectionSet) + return FieldContext(fieldName, selectionSet) ..arguments.addAll(args ?? []) ..directives.addAll(directives); } else @@ -245,15 +245,15 @@ class Parser { if (next(TokenType.COLON)) { var COLON = current; if (next(TokenType.NAME)) - return new FieldNameContext( - null, new AliasContext(NAME1, COLON, current)); + return FieldNameContext( + null, AliasContext(NAME1, COLON, current)); else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing name after colon in alias.', COLON.span)); return null; } } else - return new FieldNameContext(NAME1); + return FieldNameContext(NAME1); } else return null; } @@ -271,10 +271,10 @@ class Parser { } if (next(TokenType.RPAREN)) - return new VariableDefinitionsContext(LPAREN, current) + return VariableDefinitionsContext(LPAREN, current) ..variableDefinitions.addAll(defs); else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing ")" after variable definitions.', LPAREN.span)); return null; } @@ -290,15 +290,15 @@ class Parser { var type = parseType(); if (type != null) { var defaultValue = parseDefaultValue(); - return new VariableDefinitionContext( + return VariableDefinitionContext( variable, COLON, type, defaultValue); } else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing type in variable definition.', COLON.span)); return null; } } else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing ":" in variable definition.', variable.span)); return null; } @@ -309,11 +309,11 @@ class Parser { TypeContext parseType() { var name = parseTypeName(); if (name != null) { - return new TypeContext(name, null, maybe(TokenType.EXCLAMATION)); + return TypeContext(name, null, maybe(TokenType.EXCLAMATION)); } else { var listType = parseListType(); if (listType != null) { - return new TypeContext(null, listType, maybe(TokenType.EXCLAMATION)); + return TypeContext(null, listType, maybe(TokenType.EXCLAMATION)); } else return null; } @@ -325,13 +325,13 @@ class Parser { var type = parseType(); if (type != null) { if (next(TokenType.RBRACKET)) { - return new ListTypeContext(LBRACKET, type, current); + return ListTypeContext(LBRACKET, type, current); } else { - errors.add(new SyntaxError('Missing "]" in list type.', type.span)); + errors.add(SyntaxError('Missing "]" in list type.', type.span)); return null; } } else { - errors.add(new SyntaxError('Missing type after "[".', LBRACKET.span)); + errors.add(SyntaxError('Missing type after "[".', LBRACKET.span)); return null; } } else @@ -359,10 +359,10 @@ class Parser { var COLON = current; var val = parseInputValue(); if (val != null) - return new DirectiveContext( + return DirectiveContext( ARROBA, NAME, COLON, null, null, null, val); else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing value or variable in directive after colon.', COLON.span)); return null; @@ -372,22 +372,22 @@ class Parser { var arg = parseArgument(); if (arg != null) { if (next(TokenType.RPAREN)) { - return new DirectiveContext( + return DirectiveContext( ARROBA, NAME, null, LPAREN, current, arg, null); } else { - errors.add(new SyntaxError('Missing \')\'', arg.value.span)); + errors.add(SyntaxError('Missing \')\'', arg.value.span)); return null; } } else { errors.add( - new SyntaxError('Missing argument in directive.', LPAREN.span)); + SyntaxError('Missing argument in directive.', LPAREN.span)); return null; } } else - return new DirectiveContext( + return DirectiveContext( ARROBA, NAME, null, null, null, null, null); } else { - errors.add(new SyntaxError('Missing name for directive.', ARROBA.span)); + errors.add(SyntaxError('Missing name for directive.', ARROBA.span)); return null; } } else @@ -410,7 +410,7 @@ class Parser { return out; else { errors - .add(new SyntaxError('Missing ")" in argument list.', LPAREN.span)); + .add(SyntaxError('Missing ")" in argument list.', LPAREN.span)); return null; } } else @@ -424,14 +424,14 @@ class Parser { var COLON = current; var val = parseInputValue(); if (val != null) - return new ArgumentContext(NAME, COLON, val); + return ArgumentContext(NAME, COLON, val); else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing value or variable in argument.', COLON.span)); return null; } } else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing colon after name in argument.', NAME.span)); return null; } @@ -447,9 +447,9 @@ class Parser { if (next(TokenType.DOLLAR)) { var DOLLAR = current; if (next(TokenType.NAME)) - return new VariableContext(DOLLAR, current); + return VariableContext(DOLLAR, current); else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing name for variable; found a lone "\$" instead.', DOLLAR.span)); return null; @@ -463,10 +463,10 @@ class Parser { var EQUALS = current; var value = parseInputValue(); if (value != null) { - return new DefaultValueContext(EQUALS, value); + return DefaultValueContext(EQUALS, value); } else { errors - .add(new SyntaxError('Missing value after "=" sign.', EQUALS.span)); + .add(SyntaxError('Missing value after "=" sign.', EQUALS.span)); return null; } } else @@ -476,14 +476,14 @@ class Parser { TypeConditionContext parseTypeCondition() { var name = parseTypeName(); if (name != null) - return new TypeConditionContext(name); + return TypeConditionContext(name); else return null; } TypeNameContext parseTypeName() { if (next(TokenType.NAME)) { - return new TypeNameContext(current); + return TypeNameContext(current); } else return null; } @@ -504,24 +504,24 @@ class Parser { } StringValueContext parseStringValue() => next(TokenType.STRING) - ? new StringValueContext(current) + ? StringValueContext(current) : (next(TokenType.BLOCK_STRING) - ? new StringValueContext(current, isBlockString: true) + ? StringValueContext(current, isBlockString: true) : null); NumberValueContext parseNumberValue() => - next(TokenType.NUMBER) ? new NumberValueContext(current) : null; + next(TokenType.NUMBER) ? NumberValueContext(current) : null; BooleanValueContext parseBooleanValue() => (nextName('true') || nextName('false')) - ? new BooleanValueContext(current) + ? BooleanValueContext(current) : null; EnumValueContext parseEnumValue() => - next(TokenType.NAME) ? new EnumValueContext(current) : null; + next(TokenType.NAME) ? EnumValueContext(current) : null; NullValueContext parseNullValue() => - nextName('null') ? new NullValueContext(current) : null; + nextName('null') ? NullValueContext(current) : null; ListValueContext parseListValue() { if (next(TokenType.LBRACKET)) { @@ -539,9 +539,9 @@ class Parser { eatCommas(); if (next(TokenType.RBRACKET)) { - return new ListValueContext(LBRACKET, current)..values.addAll(values); + return ListValueContext(LBRACKET, current)..values.addAll(values); } else { - errors.add(new SyntaxError('Unterminated list literal.', lastSpan)); + errors.add(SyntaxError('Unterminated list literal.', lastSpan)); return null; } } else @@ -565,9 +565,9 @@ class Parser { eatCommas(); if (next(TokenType.RBRACE)) { - return new ObjectValueContext(LBRACE, fields, current); + return ObjectValueContext(LBRACE, fields, current); } else { - errors.add(new SyntaxError('Unterminated object literal.', lastSpan)); + errors.add(SyntaxError('Unterminated object literal.', lastSpan)); return null; } } else { @@ -584,13 +584,13 @@ class Parser { var value = parseInputValue(); if (value != null) { - return new ObjectFieldContext(NAME, COLON, value); + return ObjectFieldContext(NAME, COLON, value); } else { - errors.add(new SyntaxError('Missing value after ":".', COLON.span)); + errors.add(SyntaxError('Missing value after ":".', COLON.span)); return null; } } else { - errors.add(new SyntaxError( + errors.add(SyntaxError( 'Missing ":" after name "${NAME.span.text}".', NAME.span)); return null; } diff --git a/graphql_parser/test/argument_test.dart b/graphql_parser/test/argument_test.dart index e5f8b764..e15262de 100644 --- a/graphql_parser/test/argument_test.dart +++ b/graphql_parser/test/argument_test.dart @@ -32,10 +32,10 @@ ArgumentContext parseArgument(String text) => parse(text).parseArgument(); List parseArgumentList(String text) => parse(text).parseArguments(); -Matcher isArgument(String name, value) => new _IsArgument(name, value); +Matcher isArgument(String name, value) => _IsArgument(name, value); Matcher isArgumentList(List arguments) => - new _IsArgumentList(arguments); + _IsArgumentList(arguments); class _IsArgument extends Matcher { final String name; diff --git a/graphql_parser/test/common.dart b/graphql_parser/test/common.dart index 728b96a8..e30cb713 100644 --- a/graphql_parser/test/common.dart +++ b/graphql_parser/test/common.dart @@ -1,3 +1,3 @@ import 'package:graphql_parser/graphql_parser.dart'; -Parser parse(String text) => new Parser(scan(text)); +Parser parse(String text) => Parser(scan(text)); diff --git a/graphql_parser/test/directive_test.dart b/graphql_parser/test/directive_test.dart index ff500c09..9dc30a4e 100644 --- a/graphql_parser/test/directive_test.dart +++ b/graphql_parser/test/directive_test.dart @@ -37,11 +37,11 @@ main() { DirectiveContext parseDirective(String text) => parse(text).parseDirective(); Matcher isDirective(String name, {Matcher valueOrVariable, Matcher argument}) => - new _IsDirective(name, + _IsDirective(name, valueOrVariable: valueOrVariable, argument: argument); Matcher isDirectiveList(List directives) => - new _IsDirectiveList(directives); + _IsDirectiveList(directives); class _IsDirective extends Matcher { final String name; diff --git a/graphql_parser/test/field_test.dart b/graphql_parser/test/field_test.dart index a0b3634e..30acb837 100644 --- a/graphql_parser/test/field_test.dart +++ b/graphql_parser/test/field_test.dart @@ -86,10 +86,10 @@ Matcher isField( Matcher arguments, Matcher directives, Matcher selectionSet}) => - new _IsField(fieldName, arguments, directives, selectionSet); + _IsField(fieldName, arguments, directives, selectionSet); Matcher isFieldName(String name, {String alias}) => - new _IsFieldName(name, alias); + _IsFieldName(name, alias); class _IsField extends Matcher { final Matcher fieldName, arguments, directives, selectionSet; diff --git a/graphql_parser/test/fragment_spread_test.dart b/graphql_parser/test/fragment_spread_test.dart index e40b4827..6fca400d 100644 --- a/graphql_parser/test/fragment_spread_test.dart +++ b/graphql_parser/test/fragment_spread_test.dart @@ -25,7 +25,7 @@ FragmentSpreadContext parseFragmentSpread(String text) => parse(text).parseFragmentSpread(); Matcher isFragmentSpread(String name, {Matcher directives}) => - new _IsFragmentSpread(name, directives); + _IsFragmentSpread(name, directives); class _IsFragmentSpread extends Matcher { final String name; diff --git a/graphql_parser/test/inline_fragment_test.dart b/graphql_parser/test/inline_fragment_test.dart index 5ad6fbca..1936e820 100644 --- a/graphql_parser/test/inline_fragment_test.dart +++ b/graphql_parser/test/inline_fragment_test.dart @@ -47,7 +47,7 @@ InlineFragmentContext parseInlineFragment(String text) => Matcher isInlineFragment(String name, {Matcher directives, Matcher selectionSet}) => - new _IsInlineFragment(name, directives, selectionSet); + _IsInlineFragment(name, directives, selectionSet); class _IsInlineFragment extends Matcher { final String name; diff --git a/graphql_parser/test/selection_set_test.dart b/graphql_parser/test/selection_set_test.dart index 438db5bd..9cf89624 100644 --- a/graphql_parser/test/selection_set_test.dart +++ b/graphql_parser/test/selection_set_test.dart @@ -56,7 +56,7 @@ SelectionSetContext parseSelectionSet(String text) => parse(text).parseSelectionSet(); Matcher isSelectionSet(List selections) => - new _IsSelectionSet(selections); + _IsSelectionSet(selections); class _IsSelectionSet extends Matcher { final List selections; diff --git a/graphql_parser/test/type_test.dart b/graphql_parser/test/type_test.dart index 1da1f4f8..86ad0043 100644 --- a/graphql_parser/test/type_test.dart +++ b/graphql_parser/test/type_test.dart @@ -49,10 +49,10 @@ main() { TypeContext parseType(String text) => parse(text).parseType(); Matcher isListType(Matcher innerType, {bool isNullable}) => - new _IsListType(innerType, isNullable: isNullable != false); + _IsListType(innerType, isNullable: isNullable != false); Matcher isType(String name, {bool isNullable}) => - new _IsType(name, nonNull: isNullable != true); + _IsType(name, nonNull: isNullable != true); class _IsListType extends Matcher { final Matcher innerType; diff --git a/graphql_parser/test/value_test.dart b/graphql_parser/test/value_test.dart index 5e07a23a..a5edaaaf 100644 --- a/graphql_parser/test/value_test.dart +++ b/graphql_parser/test/value_test.dart @@ -74,7 +74,7 @@ main() { InputValueContext parseValue(String text) => parse(text).parseInputValue(); -Matcher isValue(value) => new _IsValue(value); +Matcher isValue(value) => _IsValue(value); class _IsValue extends Matcher { final value; diff --git a/graphql_parser/test/variable_definition_test.dart b/graphql_parser/test/variable_definition_test.dart index 04f85987..f3380aea 100644 --- a/graphql_parser/test/variable_definition_test.dart +++ b/graphql_parser/test/variable_definition_test.dart @@ -42,7 +42,7 @@ VariableDefinitionContext parseVariableDefinition(String text) => Matcher isVariableDefinition(String name, {Matcher type, Matcher defaultValue}) => - new _IsVariableDefinition(name, type, defaultValue); + _IsVariableDefinition(name, type, defaultValue); class _IsVariableDefinition extends Matcher { final String name; diff --git a/graphql_parser/test/variable_test.dart b/graphql_parser/test/variable_test.dart index d4484666..eb9759f3 100644 --- a/graphql_parser/test/variable_test.dart +++ b/graphql_parser/test/variable_test.dart @@ -22,7 +22,7 @@ main() { }); } -Matcher isVariable(String name) => new _IsVariable(name); +Matcher isVariable(String name) => _IsVariable(name); class _IsVariable extends Matcher { final String name;