diff --git a/packages/combinator/example/basic_auth.dart b/packages/combinator/example/basic_auth.dart index 67cd8e7a..ec3784a8 100644 --- a/packages/combinator/example/basic_auth.dart +++ b/packages/combinator/example/basic_auth.dart @@ -18,7 +18,7 @@ final Parser> credentials = chain([ match(':'), string.opt(), ]).map>( - (r) => {'username': r.value![0]!, 'password': r.value![2]!}); + (r) => {'username': r.value![0], 'password': r.value![2]}); /// We can actually embed a parser within another parser. /// diff --git a/packages/combinator/example/calculator.dart b/packages/combinator/example/calculator.dart index d3074509..7f8607b7 100644 --- a/packages/combinator/example/calculator.dart +++ b/packages/combinator/example/calculator.dart @@ -24,7 +24,7 @@ Parser calculatorGrammar() { expr.space(), match(op).space() as Parser, expr.space(), - ]).map((r) => f(r.value![0]!, r.value![2]!)), + ]).map((r) => f(r.value![0], r.value![2])), ); } diff --git a/packages/combinator/lib/src/combinator/advance.dart b/packages/combinator/lib/src/combinator/advance.dart index e480123c..01506dc2 100644 --- a/packages/combinator/lib/src/combinator/advance.dart +++ b/packages/combinator/lib/src/combinator/advance.dart @@ -7,7 +7,7 @@ class _Advance extends Parser { _Advance(this.parser, this.amount); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { var result = parser._parse(args.increaseDepth()).change(parser: this); if (result.successful) args.scanner.position += amount; return result; diff --git a/packages/combinator/lib/src/combinator/any.dart b/packages/combinator/lib/src/combinator/any.dart index f5511458..616bf29d 100644 --- a/packages/combinator/lib/src/combinator/any.dart +++ b/packages/combinator/lib/src/combinator/any.dart @@ -21,7 +21,7 @@ class _Any extends Parser { _Any(this.parsers, this.backtrack, this.errorMessage, this.severity); @override - ParseResult _parse(ParseArgs args) { + ParseResult _parse(ParseArgs args) { var inactive = parsers .where((p) => !args.trampoline.isActive(p, args.scanner.position)); diff --git a/packages/combinator/lib/src/combinator/cache.dart b/packages/combinator/lib/src/combinator/cache.dart index 309a4c24..b07b38e0 100644 --- a/packages/combinator/lib/src/combinator/cache.dart +++ b/packages/combinator/lib/src/combinator/cache.dart @@ -1,13 +1,13 @@ part of lex.src.combinator; class _Cache extends Parser { - final Map> _cache = {}; + final Map> _cache = {}; final Parser parser; _Cache(this.parser); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { return _cache.putIfAbsent(args.scanner.position, () { return parser._parse(args.increaseDepth()); }).change(parser: this); diff --git a/packages/combinator/lib/src/combinator/chain.dart b/packages/combinator/lib/src/combinator/chain.dart index be07fa59..e2c5377f 100644 --- a/packages/combinator/lib/src/combinator/chain.dart +++ b/packages/combinator/lib/src/combinator/chain.dart @@ -3,9 +3,9 @@ part of lex.src.combinator; /// Expects to parse a sequence of [parsers]. /// /// If [failFast] is `true` (default), then the first failure to parse will abort the parse. -ListParser chain(Iterable> parsers, +ListParser chain(Iterable> parsers, {bool failFast: true, SyntaxErrorSeverity? severity}) { - return _Chain( + return _Chain( parsers, failFast != false, severity ?? SyntaxErrorSeverity.error); } @@ -17,7 +17,7 @@ class _Alt extends Parser { _Alt(this.parser, this.errorMessage, this.severity); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { var result = parser._parse(args.increaseDepth()); return result.successful ? result @@ -33,7 +33,7 @@ class _Alt extends Parser { } } -class _Chain extends ListParser { +class _Chain extends ListParser { final Iterable> parsers; final bool failFast; final SyntaxErrorSeverity severity; @@ -41,7 +41,7 @@ class _Chain extends ListParser { _Chain(this.parsers, this.failFast, this.severity); @override - ParseResult?> __parse(ParseArgs args) { + ParseResult> __parse(ParseArgs args) { var errors = []; var results = []; var spans = []; @@ -61,7 +61,10 @@ class _Chain extends ListParser { successful = false; } + //TODO: To be looked at + //if (result.value != null) { results.add(result.value); + //} if (result.span != null) { spans.add(result.span!); @@ -74,14 +77,14 @@ class _Chain extends ListParser { span = spans.reduce((a, b) => a.expand(b)); } - return ParseResult?>( + return ParseResult>( args.trampoline, args.scanner, this, successful, errors, span: span, - value: List.unmodifiable(results), + value: List.unmodifiable(results), ); } diff --git a/packages/combinator/lib/src/combinator/check.dart b/packages/combinator/lib/src/combinator/check.dart index a87d5f69..c15d7051 100644 --- a/packages/combinator/lib/src/combinator/check.dart +++ b/packages/combinator/lib/src/combinator/check.dart @@ -9,7 +9,7 @@ class _Check extends Parser { _Check(this.parser, this.matcher, this.errorMessage, this.severity); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { var matchState = {}; var result = parser._parse(args.increaseDepth()).change(parser: this); if (!result.successful) diff --git a/packages/combinator/lib/src/combinator/combinator.dart b/packages/combinator/lib/src/combinator/combinator.dart index f50df785..8f7429ae 100644 --- a/packages/combinator/lib/src/combinator/combinator.dart +++ b/packages/combinator/lib/src/combinator/combinator.dart @@ -7,6 +7,7 @@ import 'package:matcher/matcher.dart'; import 'package:source_span/source_span.dart'; import 'package:string_scanner/string_scanner.dart'; import 'package:tuple/tuple.dart'; +import 'package:optional/optional.dart'; import '../error.dart'; part 'any.dart'; @@ -67,9 +68,9 @@ class ParseArgs { /// A parser combinator, which can parse very complicated grammars in a manageable manner. abstract class Parser { - ParseResult __parse(ParseArgs args); + ParseResult __parse(ParseArgs args); - ParseResult _parse(ParseArgs args) { + ParseResult _parse(ParseArgs args) { var pos = args.scanner.position; if (args.trampoline.hasMemoized(this, pos)) @@ -86,7 +87,7 @@ abstract class Parser { } /// Parses text from a [SpanScanner]. - ParseResult parse(SpanScanner scanner, [int depth = 1]) { + ParseResult parse(SpanScanner scanner, [int depth = 1]) { var args = ParseArgs(Trampoline(), scanner, depth); return _parse(args); } @@ -105,7 +106,7 @@ abstract class Parser { // TODO: Type issue /// Runs the given function, which changes the returned [ParseResult] into one relating to a [U] object. - Parser change(ParseResult Function(ParseResult) f) { + Parser change(ParseResult Function(ParseResult) f) { return _Change(this, f); } @@ -128,7 +129,7 @@ abstract class Parser { } /// Transforms the parse result using a unary function. - Parser map(U Function(ParseResult) f) { + Parser map(U Function(ParseResult) f) { return _Map(this, f); } @@ -171,7 +172,7 @@ abstract class Parser { Parser or(Parser other) => any([this, other]); /// Parses this sequence one or more times. - ListParser plus() => times(1, exact: false); + ListParser plus() => times(1, exact: false); /// Safely escapes this parser when an error occurs. /// @@ -207,11 +208,11 @@ abstract class Parser { }); } - Parser surroundedByCurlyBraces({T? defaultValue}) => opt() + Parser surroundedByCurlyBraces({required T defaultValue}) => opt() .surroundedBy(match('{').space(), match('}').space()) .map((r) => r.value ?? defaultValue); - Parser surroundedBySquareBrackets({T? defaultValue}) => opt() + Parser surroundedBySquareBrackets({required T defaultValue}) => opt() .surroundedBy(match('[').space(), match(']').space()) .map((r) => r.value ?? defaultValue); @@ -336,7 +337,9 @@ class Trampoline { } bool isActive(Parser parser, int position) { - if (!_active.containsKey(parser)) return false; + if (!_active.containsKey(parser)) { + return false; + } var q = _active[parser]!; if (q.isEmpty) return false; //return q.contains(position); diff --git a/packages/combinator/lib/src/combinator/compare.dart b/packages/combinator/lib/src/combinator/compare.dart index b26e719c..4ee0b813 100644 --- a/packages/combinator/lib/src/combinator/compare.dart +++ b/packages/combinator/lib/src/combinator/compare.dart @@ -7,8 +7,8 @@ class _Compare extends ListParser { _Compare(this.parser, this.compare); @override - ParseResult?> __parse(ParseArgs args) { - ParseResult?> result = parser._parse(args.increaseDepth()); + ParseResult> __parse(ParseArgs args) { + ParseResult> result = parser._parse(args.increaseDepth()); if (!result.successful) return result; result = result.change( diff --git a/packages/combinator/lib/src/combinator/fold_errors.dart b/packages/combinator/lib/src/combinator/fold_errors.dart index 6d3be765..6d15c69a 100644 --- a/packages/combinator/lib/src/combinator/fold_errors.dart +++ b/packages/combinator/lib/src/combinator/fold_errors.dart @@ -7,7 +7,7 @@ class _FoldErrors extends Parser { _FoldErrors(this.parser, this.equal); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { var result = parser._parse(args.increaseDepth()).change(parser: this); var errors = result.errors.fold>([], (out, e) { if (!out.any((b) => equal(e, b))) out.add(e); diff --git a/packages/combinator/lib/src/combinator/longest.dart b/packages/combinator/lib/src/combinator/longest.dart index 65a907bc..fa9124e7 100644 --- a/packages/combinator/lib/src/combinator/longest.dart +++ b/packages/combinator/lib/src/combinator/longest.dart @@ -16,7 +16,7 @@ class _Longest extends Parser { _Longest(this.parsers, this.errorMessage, this.severity); @override - ParseResult _parse(ParseArgs args) { + ParseResult _parse(ParseArgs args) { var inactive = parsers .toList() .where((p) => !args.trampoline.isActive(p, args.scanner.position)); @@ -27,7 +27,7 @@ class _Longest extends Parser { int replay = args.scanner.position; var errors = []; - var results = >[]; + var results = >[]; for (var parser in inactive) { var result = parser._parse(args.increaseDepth()); @@ -59,10 +59,10 @@ class _Longest extends Parser { } @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { int replay = args.scanner.position; var errors = []; - var results = >[]; + var results = >[]; for (var parser in parsers) { var result = parser._parse(args.increaseDepth()); diff --git a/packages/combinator/lib/src/combinator/map.dart b/packages/combinator/lib/src/combinator/map.dart index 638afbb6..4dfb326d 100644 --- a/packages/combinator/lib/src/combinator/map.dart +++ b/packages/combinator/lib/src/combinator/map.dart @@ -2,14 +2,14 @@ part of lex.src.combinator; class _Map extends Parser { final Parser parser; - final U Function(ParseResult) f; + final U Function(ParseResult) f; _Map(this.parser, this.f); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { var result = parser._parse(args.increaseDepth()); - return ParseResult( + return ParseResult( args.trampoline, args.scanner, this, @@ -34,12 +34,12 @@ class _Map extends Parser { class _Change extends Parser { final Parser parser; - final ParseResult Function(ParseResult) f; + final ParseResult Function(ParseResult) f; _Change(this.parser, this.f); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { return f(parser._parse(args.increaseDepth())).change(parser: this); } diff --git a/packages/combinator/lib/src/combinator/max_depth.dart b/packages/combinator/lib/src/combinator/max_depth.dart index 2475262c..42befcff 100644 --- a/packages/combinator/lib/src/combinator/max_depth.dart +++ b/packages/combinator/lib/src/combinator/max_depth.dart @@ -7,7 +7,7 @@ class _MaxDepth extends Parser { _MaxDepth(this.parser, this.cap); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { if (args.depth > cap) { return ParseResult(args.trampoline, args.scanner, this, false, []); } diff --git a/packages/combinator/lib/src/combinator/negate.dart b/packages/combinator/lib/src/combinator/negate.dart index bb956287..b507bdcc 100644 --- a/packages/combinator/lib/src/combinator/negate.dart +++ b/packages/combinator/lib/src/combinator/negate.dart @@ -8,7 +8,7 @@ class _Negate extends Parser { _Negate(this.parser, this.errorMessage, this.severity); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { var result = parser._parse(args.increaseDepth()).change(parser: this); if (!result.successful) { diff --git a/packages/combinator/lib/src/combinator/opt.dart b/packages/combinator/lib/src/combinator/opt.dart index dc1d7d15..12083ed7 100644 --- a/packages/combinator/lib/src/combinator/opt.dart +++ b/packages/combinator/lib/src/combinator/opt.dart @@ -7,7 +7,7 @@ class _Opt extends Parser { _Opt(this.parser, this.backtrack); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { var replay = args.scanner.position; var result = parser._parse(args.increaseDepth()); @@ -35,9 +35,9 @@ class _ListOpt extends ListParser { _ListOpt(this.parser, this.backtrack); @override - ParseResult?> __parse(ParseArgs args) { + ParseResult> __parse(ParseArgs args) { var replay = args.scanner.position; - ParseResult?> result = parser._parse(args.increaseDepth()); + ParseResult> result = parser._parse(args.increaseDepth()); if (!result.successful) args.scanner.position = replay; diff --git a/packages/combinator/lib/src/combinator/reduce.dart b/packages/combinator/lib/src/combinator/reduce.dart index e14c6390..29f1f1f3 100644 --- a/packages/combinator/lib/src/combinator/reduce.dart +++ b/packages/combinator/lib/src/combinator/reduce.dart @@ -7,8 +7,8 @@ class _Reduce extends Parser { _Reduce(this.parser, this.combine); @override - ParseResult __parse(ParseArgs args) { - ParseResult?> result = parser._parse(args.increaseDepth()); + ParseResult __parse(ParseArgs args) { + ParseResult> result = parser._parse(args.increaseDepth()); if (!result.successful) return ParseResult( diff --git a/packages/combinator/lib/src/combinator/reference.dart b/packages/combinator/lib/src/combinator/reference.dart index 2c6a58be..737b94d4 100644 --- a/packages/combinator/lib/src/combinator/reference.dart +++ b/packages/combinator/lib/src/combinator/reference.dart @@ -15,14 +15,14 @@ class Reference extends Parser { } @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { if (_parser == null) throw StateError('There is no parser assigned to this reference.'); return _parser!._parse(args); } @override - ParseResult _parse(ParseArgs args) { + ParseResult _parse(ParseArgs args) { if (_parser == null) throw StateError('There is no parser assigned to this reference.'); return _parser!._parse(args); diff --git a/packages/combinator/lib/src/combinator/repeat.dart b/packages/combinator/lib/src/combinator/repeat.dart index 12ebb22a..c8b9891d 100644 --- a/packages/combinator/lib/src/combinator/repeat.dart +++ b/packages/combinator/lib/src/combinator/repeat.dart @@ -12,12 +12,12 @@ class _Repeat extends ListParser { this.backtrack, this.severity); @override - ParseResult?> __parse(ParseArgs args) { + ParseResult> __parse(ParseArgs args) { var errors = []; var results = []; var spans = []; int success = 0, replay = args.scanner.position; - ParseResult result; + ParseResult result; do { result = parser._parse(args.increaseDepth()); @@ -51,7 +51,7 @@ class _Repeat extends ListParser { } else if (success > count && exact) { if (backtrack) args.scanner.position = replay; - return ParseResult?>(args.trampoline, args.scanner, this, false, [ + return ParseResult>(args.trampoline, args.scanner, this, false, [ SyntaxError( severity, tooMany, diff --git a/packages/combinator/lib/src/combinator/safe.dart b/packages/combinator/lib/src/combinator/safe.dart index 35083120..a2542295 100644 --- a/packages/combinator/lib/src/combinator/safe.dart +++ b/packages/combinator/lib/src/combinator/safe.dart @@ -10,7 +10,7 @@ class _Safe extends Parser { _Safe(this.parser, this.backtrack, this.errorMessage, this.severity); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { var replay = args.scanner.position; try { diff --git a/packages/combinator/lib/src/combinator/value.dart b/packages/combinator/lib/src/combinator/value.dart index 51fc9218..b0612073 100644 --- a/packages/combinator/lib/src/combinator/value.dart +++ b/packages/combinator/lib/src/combinator/value.dart @@ -2,12 +2,12 @@ part of lex.src.combinator; class _Value extends Parser { final Parser parser; - final T Function(ParseResult) f; + final T Function(ParseResult) f; _Value(this.parser, this.f); @override - ParseResult __parse(ParseArgs args) { + ParseResult __parse(ParseArgs args) { var result = parser._parse(args.increaseDepth()).change(parser: this); return result.successful ? result.change(value: f(result)) : result; } diff --git a/packages/combinator/pubspec.yaml b/packages/combinator/pubspec.yaml index 1ba7ae13..95fec8f4 100644 --- a/packages/combinator/pubspec.yaml +++ b/packages/combinator/pubspec.yaml @@ -15,5 +15,6 @@ dependencies: source_span: ^1.8.1 string_scanner: ^1.1.0 tuple: ^2.0.0 + optional: ^6.0.0-nullsafety.2 dev_dependencies: test: ^1.17.3 \ No newline at end of file diff --git a/packages/combinator/test/list_test.dart b/packages/combinator/test/list_test.dart index 8db60137..a9e53ab1 100644 --- a/packages/combinator/test/list_test.dart +++ b/packages/combinator/test/list_test.dart @@ -11,11 +11,11 @@ main() { var numbers = number.plus(); test('sort', () { - var parser = numbers.sort((a, b) => a!.compareTo(b!)); + var parser = numbers.sort((a, b) => a.compareTo(b)); expect(parser.parse(scan('21,2,3,34,20')).value, [2, 3, 20, 21, 34]); }); test('reduce', () { - var parser = numbers.reduce((a, b) => a! + b!); + var parser = numbers.reduce((a, b) => a + b); expect(parser.parse(scan('21,2,3,34,20')).value, 80); expect(parser.parse(scan('not numbers')).value, isNull); }); diff --git a/packages/framework/lib/src/core/driver.dart b/packages/framework/lib/src/core/driver.dart index 0cec0133..efa2e958 100644 --- a/packages/framework/lib/src/core/driver.dart +++ b/packages/framework/lib/src/core/driver.dart @@ -139,7 +139,8 @@ abstract class Driver< pipeline.handlers, resolved.fold>( {}, (out, r) => out..addAll(r.allParams)), - (resolved.isEmpty ? null : resolved.first.parseResult)!, + //(resolved.isEmpty ? null : resolved.first.parseResult), + resolved.first.parseResult, pipeline, ); } diff --git a/packages/framework/pubspec.yaml b/packages/framework/pubspec.yaml index 22be5852..47286fb7 100644 --- a/packages/framework/pubspec.yaml +++ b/packages/framework/pubspec.yaml @@ -22,10 +22,11 @@ dependencies: ref: sdk-2.12.x_nnbd path: packages/model angel_route: - git: - url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x_nnbd - path: packages/route + path: ../route +# git: +# url: https://github.com/dukefirehawk/angel.git +# ref: sdk-2.12.x_nnbd +# path: packages/route charcode: ^1.2.0 combinator: git: diff --git a/packages/route/lib/src/router.dart b/packages/route/lib/src/router.dart index e4f1cdb4..a14cbabd 100644 --- a/packages/route/lib/src/router.dart +++ b/packages/route/lib/src/router.dart @@ -311,7 +311,7 @@ class Router { if (parseResult != null) { if (parseResult.successful && scanner.isDone) { var tailResult = parseResult.value?.tail ?? ''; - print(tailResult); + //print(tailResult); var result = RoutingResult( parseResult: parseResult, params: parseResult.value!.params, @@ -334,13 +334,13 @@ class Router { /// Returns the result of [resolve] with [path] passed as /// both `absolute` and `relative`. - Iterable> resolveAbsolute(String path, + Iterable> resolveAbsolute(String path, {String method = 'GET', bool strip = true}) => resolveAll(path, path, method: method, strip: strip); /// Finds every possible [Route] that matches the given path, /// with the given method. - Iterable> resolveAll(String absolute, String relative, + Iterable> resolveAll(String absolute, String relative, {String method = 'GET', bool strip = true}) { if (_useCache == true) { return _cache.putIfAbsent('$method$absolute', diff --git a/packages/route/lib/src/routing_result.dart b/packages/route/lib/src/routing_result.dart index e757d7f4..351d235b 100644 --- a/packages/route/lib/src/routing_result.dart +++ b/packages/route/lib/src/routing_result.dart @@ -3,7 +3,7 @@ part of angel_route.src.router; /// Represents a complex result of navigating to a path. class RoutingResult { /// The parse result that matched the given sub-path. - final ParseResult parseResult; + final ParseResult parseResult; /// A nested instance, if a sub-path was matched. final Iterable> nested; @@ -47,10 +47,10 @@ class RoutingResult { } /// All handlers on this sub-path and its children. - List get allHandlers { - final handlers = []; + List get allHandlers { + final handlers = []; - void crawl(RoutingResult result) { + void crawl(RoutingResult result) { handlers.addAll(result.handlers); if (result.nested.isNotEmpty == true) { diff --git a/packages/route/pubspec.yaml b/packages/route/pubspec.yaml index 527a12bc..cdea689c 100644 --- a/packages/route/pubspec.yaml +++ b/packages/route/pubspec.yaml @@ -7,11 +7,11 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: combinator: -# path: ../combinator - git: - url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x_nnbd - path: packages/combinator + path: ../combinator +# git: +# url: https://github.com/dukefirehawk/angel.git +# ref: sdk-2.12.x_nnbd +# path: packages/combinator string_scanner: ^1.0.0 dev_dependencies: build_runner: ^1.11.5