diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 762ce2c..dcbc120 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -8,11 +8,10 @@ on: jobs: build: runs-on: ubuntu-latest + container: + image: dart:stable steps: - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v1 - with: - sdk: stable - name: Update submodules run: git submodule update --init --recursive - name: Print Dart version @@ -24,6 +23,6 @@ jobs: - name: Analyzer run: dart analyze --fatal-infos --fatal-warnings - name: Tests - run: dart test --coverage=coverage + run: dart test --coverage=.coverage - name: Coverage - run: dart run coverage:format_coverage -l -c -i coverage --report-on=lib --packages=.packages | dart run check_coverage:check_coverage + run: dart run coverage:format_coverage -l -c -i .coverage --report-on=lib --packages=.dart_tool/package_config.json | dart run check_coverage:check_coverage diff --git a/.gitignore b/.gitignore index 9403bdd..8a811df 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,4 @@ doc/api/ *.js.map # test_coverage -test/.test_coverage.dart -coverage -coverage_badge.svg \ No newline at end of file +.coverage diff --git a/CHANGELOG.md b/CHANGELOG.md index cc91a91..77df0b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.4.1] - 2022-06-14 +### Added +- Lower case hex support + +### Changed +- Updated CTS to latest + ## [0.4.0] - 2022-03-21 ### Changed - Dart 2.16 @@ -102,6 +109,7 @@ Previously, no modification would be made and no errors/exceptions thrown. ### Added - Basic design draft +[0.4.1]: https://github.com/f3ath/jessie/compare/0.4.0...0.4.1 [0.4.0]: https://github.com/f3ath/jessie/compare/0.3.1...0.4.0 [0.3.1]: https://github.com/f3ath/jessie/compare/0.3.0...0.3.1 [0.3.0]: https://github.com/f3ath/jessie/compare/0.2.0...0.3.0 diff --git a/README.md b/README.md index 1a7d5a7..b88c3fa 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,8 @@ must be specified in the square brackets and prefixed by `?`. It also must be al ## Data manipulation Each `JsonPathMatch` produced by the `.read()` method contains the `.pointer` property which is a valid [JSON Pointer] -and can be used to write/append/remove the referenced value. If you're looking for data manipulation only, -take a look at this [JSON Pointer implementation]. +and can be used to write/append/remove the referenced value. If you want the data manipulation only, +consider the [JSON Pointer implementation]. ## References - [Standard development](https://github.com/ietf-wg-jsonpath/draft-ietf-jsonpath-base) diff --git a/cts b/cts index ab56e44..ece7b77 160000 --- a/cts +++ b/cts @@ -1 +1 @@ -Subproject commit ab56e44bf7ea9997f2f3a10bbc60ee317c151a61 +Subproject commit ece7b77659e7fe971047794aa99109d61a258ffe diff --git a/lib/src/child_match.dart b/lib/src/child_match.dart index 11d0b18..830ccc1 100644 --- a/lib/src/child_match.dart +++ b/lib/src/child_match.dart @@ -8,13 +8,13 @@ class ChildMatch implements JsonPathMatch { /// Child match for an array element ChildMatch.index(int index, this.parent) : value = parent.value[index], - path = parent.path + '[' + index.toString() + ']', + path = '${parent.path}[$index]', pointer = JsonPointerSegment(index.toString(), parent.pointer); /// Child match for an object child ChildMatch.child(String key, this.parent) : value = parent.value[key], - path = parent.path + '[' + quote(key) + ']', + path = '${parent.path}[${quote(key)}]', pointer = JsonPointerSegment(key, parent.pointer); /// The value diff --git a/lib/src/grammar/expression.dart b/lib/src/grammar/expression.dart index a57586e..2474b9a 100644 --- a/lib/src/grammar/expression.dart +++ b/lib/src/grammar/expression.dart @@ -6,19 +6,19 @@ import 'package:petitparser/petitparser.dart'; import 'package:json_path/src/it.dart' as it; Parser _build() { - final _true = string('true').map(it.to(true)); - final _false = string('false').map(it.to(false)); - final _null = string('null').map(it.to(null)); + final trueLiteral = string('true').map(it.to(true)); + final falseLiteral = string('false').map(it.to(false)); + final nullLiteral = string('null').map(it.to(null)); - final _literal = (_false | - _true | - _null | + final literal = (falseLiteral | + trueLiteral | + nullLiteral | integer | doubleQuotedString | singleQuotedString) .map((value) => (match) => value); - final _index = (char('[') & + final index = (char('[') & (integer | doubleQuotedString | singleQuotedString) & char(']')) .map((_) => _[1]) @@ -30,66 +30,65 @@ Parser _build() { } }); - final _dotName = (char('.') & dotString).map(it.last).map((key) => (v) { + final dotName = (char('.') & dotString).map(it.last).map((key) => (v) { if (v is Map && v.containsKey(key)) { return v[key]; } }); - final _nodeFilter = (_index | _dotName) + final nodeFilter = (index | dotName) .plus() .map( (value) => value.reduce((value, element) => (v) => element(value(v)))) .map((value) => (match) => value(match.value)); - final _currentObject = char('@').map((_) => (match) => match.value); + final currentObject = char('@').map((_) => (match) => match.value); - final _node = - (_currentObject & _nodeFilter.optional()).map(it.lastWhere(it.isNotNull)); + final node = + (currentObject & nodeFilter.optional()).map(it.lastWhere(it.isNotNull)); - final _term = undefined(); + final term = undefined(); - final _parens = - (char('(').trim() & _term & char(')').trim()).map((_) => _[1]); + final parens = (char('(').trim() & term & char(')').trim()).map((_) => _[1]); - final _operand = _parens | _literal | _node; + final operand = parens | literal | node; - final _eq = string('==') + final eq = string('==') .map<_BinaryOp>(it.to((algebra, left, right) => algebra.eq(left, right))); - final _ne = string('!=') + final ne = string('!=') .map<_BinaryOp>(it.to((algebra, left, tight) => algebra.ne(left, tight))); - final _ge = string('>=') + final ge = string('>=') .map<_BinaryOp>(it.to((algebra, left, right) => algebra.ge(left, right))); - final _gt = string('>') + final gt = string('>') .map<_BinaryOp>(it.to((algebra, left, right) => algebra.gt(left, right))); - final _le = string('<=') + final le = string('<=') .map<_BinaryOp>(it.to((algebra, left, right) => algebra.le(left, right))); - final _lt = string('<') + final lt = string('<') .map<_BinaryOp>(it.to((algebra, left, right) => algebra.lt(left, right))); - final _or = string('||') + final or = string('||') .map<_BinaryOp>(it.to((algebra, left, right) => algebra.or(left, right))); - final _and = string('&&').map<_BinaryOp>( + final and = string('&&').map<_BinaryOp>( it.to((algebra, left, right) => algebra.and(left, right))); - final _binaryOperator = _eq | _ne | _ge | _gt | _le | _lt | _or | _and; + final binaryOperator = eq | ne | ge | gt | le | lt | or | and; - final _expression = (_operand & _binaryOperator.trim() & _operand) + final expression = (operand & binaryOperator.trim() & operand) .map((value) => (JsonPathMatch match) { final op = value[1]; return op( match.context.algebra, value.first(match), value.last(match)); }); - _term.set(_expression | _operand); + term.set(expression | operand); - return (string('?(') & _term & char(')')).map((_) => _[1]).map( + return (string('?(') & term & char(')')).map((_) => _[1]).map( (eval) => (match) => match.context.algebra.isTruthy(eval(match))); } diff --git a/lib/src/grammar/strings.dart b/lib/src/grammar/strings.dart index cd1671f..8b3fa31 100644 --- a/lib/src/grammar/strings.dart +++ b/lib/src/grammar/strings.dart @@ -30,7 +30,7 @@ final _unicodeBoundary = String.fromCharCode(0xFFFF); final _doubleUnescaped = range(' ', '!') | range('#', '[') | range(']', _unicodeBoundary); -final _hexDigit = anyOf('0123456789ABCDEF'); +final _hexDigit = anyOf('0123456789ABCDEFabcdef'); final _unicodeSymbol = (string(r'\u') & _hexDigit.repeat(4).flatten()) .map((value) => String.fromCharCode(int.parse(value.last, radix: 16))); diff --git a/pubspec.yaml b/pubspec.yaml index f391d6d..6e4c1c6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: json_path -version: 0.4.0 +version: 0.4.1 description: Implementation of JSONPath expressions like "$.store.book[2].price". Reads and writes values in parsed JSON objects. homepage: "https://github.com/f3ath/jessie" @@ -11,11 +11,10 @@ dependencies: petitparser: ^5.0.0 dev_dependencies: - lints: ^1.0.1 - test: ^1.20.1 - path: ^1.8.1 + lints: ^2.0.0 + test: ^1.21.1 + path: ^1.8.2 check_coverage: ^0.0.4 - cider: ^0.1.0 cider: link_template: