Skip to content

Commit

Permalink
Make the loopback variable public in expression builder (#168)
Browse files Browse the repository at this point in the history
* Make the loopback variable public in expression builder

* Make the loopback variable in ExpressionBuilder a getter

* Add the get keyword
  • Loading branch information
joranmulderij committed Feb 29, 2024
1 parent cfa6b3a commit 20ba2c1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/src/expression/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ class ExpressionBuilder<T> {
final List<ExpressionGroup<T>> _groups = [];
final SettableParser<T> _loopback = undefined();

/// The parser for this expression builder. Can be used to loop back to this
/// parser.
SettableParser<T> get loopback => _loopback;

/// Defines a new primitive, literal, or value [parser].
void primitive(Parser<T> parser) => _primitives.add(parser);

/// Creates a new group of operators that share the same priority.
@useResult
ExpressionGroup<T> group() {
final group = ExpressionGroup<T>(_loopback);
final group = ExpressionGroup<T>(loopback);
_groups.add(group);
return group;
}
Expand All @@ -94,15 +98,15 @@ class ExpressionBuilder<T> {
buildChoice(primitives),
(parser, group) => group.build(parser),
);
// Replace all uses of `_loopback` with `parser`. Do not use `resolve()`
// Replace all uses of `loopback` with `parser`. Do not use `resolve()`
// because that might try to resolve unrelated parsers outside of the scope
// of the `ExpressionBuilder` and cause infinite recursion.
for (final parent in allParser(parser)) {
parent.replace(_loopback, parser);
parent.replace(loopback, parser);
}
// Also update the loopback parser, just in case somebody keeps a reference
// to it (not that anybody should do that).
_loopback.set(parser);
loopback.set(parser);
return parser;
}
}

0 comments on commit 20ba2c1

Please sign in to comment.