Skip to content
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

Make the loopback variable public in expression builder #168

Merged
merged 3 commits into from
Feb 29, 2024
Merged
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
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;
}
}
Loading