Skip to content

misc!: Improve the codebase and add tests. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
## 2.0.0 (Work in progress)

- Additions:
- Exceptions:
- `MissingKeyException` - Thrown when a key is not present.
- `ParserException` - Thrown at various points during the parsing of
expressions.
- Changes:
- Removed `sprint` dependency.
- BREAKING: Instead of logging an error, the package will now throw an
exception.
- Improved enums:
- The members of all enums have been converted to `camelCase`.
- 'Operations' have been renamed to 'matchers'.
- Several matchers were renamed and/or received aliases:
- `Default` is now known as `always` in the private API.
- `Always`, `Fallback` and `Otherwise` are now synonymous with
`Default`.
-
- `=` and `==` are now synonymous with `Equals`.
- `Greater` has been renamed to `IsGreater`.
- `Greater`, `GT`, `GTR` and `>` are now synonymous with `IsGreater`.
- `GreaterOrEqual` has been renamed to `IsGreaterOrEqual`.
- `GreaterOrEqual`, `GTE` and `>=` are now synonymous with
`IsGreaterOrEqual`.
- `Lesser` has been renamed to `IsLesser`.
- `Lesser`, `LS`, `LSS` and `<` are now synonymous with `IsLesser`.
- `LesserOrEqual` has been renamed to `IsLesserOrEqual`.
- `LesserOrEqual`, `LSE` and `<=` are now synonymous with
`IsLesserOrEqual`.
- `In` has been renamed to `IsInGroup`.
- `In`, 'IsIn' and 'InGroup' are now synonymous with `IsInGroup`.
- `NotIn` has been renamed to `IsNotInGroup`.
- `NotIn`, `!In`, `IsNotIn`, `NotInGroup` and `!InGroup` are now
synonymous with `IsNotInGroup`.
- `InRange` has been renamed to `IsInRange`.
- `InRange` is now synonymous with `IsInRange`.
- `NotInRange` has been renamed to `IsNotInRange`.
- `NotInRange` and `!InRange` are now synonymous with `IsNotInRange`.
- Reorganised project:
- Removed `lexer.dart`, moving the declarations therein to:
- `choices.dart`: `getChoices()`, `constructCondition()`,
`constructMathematicalCondition()`, `constructSetCondition()`,
`isNumeric()`, `isInRange()`.
- `symbols.dart`: `getSymbols()`.
- `tokens.dart`: `getTokens()`.
- Reduced `Token` to a simple data class by:
- Removing unused funtions: `isExternal()`.
- Moving its parser-related methods into `parser.dart`:
- Into `Parser`: `parse()` (as `parseToken()`), `parseExternal()`,
`parseExpression()`, `parseParameter()`, `parsePositionalParameter()`.
- As standalone functions: `isExpression()`, `isInteger()`.
- Renamed declarations of `Parser`:
- `parseKey()` -> `process()`.
- `parse()` -> `_process()`.
- `parseToken()` -> `_parseToken()`.
- `parseExternal()` -> `_processExternalClause()`.
- `parseExpression()` -> `_processExpressionClause()`.
- `parseParameter()` -> `_processParameterClause()`.
- `parsePositionalParameter()` -> `_processPositionalParameter()`.

## 1.2.0

- Updated SDK version from `2.12.0` to `2.17.0`.
Expand Down Expand Up @@ -37,7 +98,7 @@

## 1.0.1

- Added `In` and `NotIn` operations.
- Added `In` and `NotIn` matchers.

## 1.0.0

Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Table of Contents

- [The Syntax](#the-syntax)
- [Case Operations](#case-operations)
- [Case Matchers](#case-matchers)

## The Syntax

Expand Down Expand Up @@ -45,34 +45,34 @@ expressions small and understandable.

`[{temperature} ~ Lesser(15):Too cold./Lesser(30):Temperate./Default:It's too hot!]`

### Case Operations
### Case Matchers

The parser supports several comparison operations, which can be used to match a
parameter to a case.
The parser supports several case matchers, which can be used to match the
control variable to an argument.

String-exclusive operations:
String-exclusive matchers:

- `StartsWith`
- `EndsWith`
- `Contains`

Indifferent operations:
Indifferent matchers:

- `Equals` *
- `In`
- `NotIn`
- `InRange`
- `NotInRange`
- `IsIn`
- `IsNotIn`
- `IsInRange`
- `IsNotInRange`

Number-exclusive operations:
Number-exclusive matchers:

- `Greater`
- `GreaterOrEqual`
- `Lesser`
- `LesserOrEqual`
- `IsGreater`
- `IsGreaterOrEqual`
- `IsLesser`
- `IsLesserOrEqual`

Other:

- `Default`
- `Always`

* If no operation has been defined, the operation will default to 'Equals'
* If no matcher has been defined, the matcher will default to 'Equals'
2 changes: 1 addition & 1 deletion example/polish/expressions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ordinalMasculineSingularInstrumental": "[{number} ~ 1:pierwszym/2:drugim/3:trzecim/4:czwartym/5:piątym/GreaterOrEqual(6):{number}[{number} ~ EndsWith(2,3):im/Default:ym]]"
"ordinalMasculineSingularInstrumental": "[{number} ~ 1:pierwszym/2:drugim/3:trzecim/4:czwartym/5:piątym/GreaterOrEqual(6):{number}-[{number} ~ EndsWith(2,3):im/Default:ym]]"
}
4 changes: 2 additions & 2 deletions example/translation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'utils.dart';
/// the given key.
class Translation {
/// The parser utilised by the translation service.
final Parser parser = Parser(quietMode: false);
final Parser parser = Parser();

/// Load the strings corresponding to the language code provided.
void load(Language language) => parser.load(
Expand All @@ -21,7 +21,7 @@ class Translation {
Map<String, Object> named = const <String, Object>{},
Set<Object> positional = const <Object>{},
}) =>
parser.parseKey(key, named: named, positional: positional);
parser.process(key, named: named, positional: positional);
}

enum Language { english, polish, romanian }
Loading