Introduction of expression based language#185
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Introduces a new expression-language subsystem (dev.ftb.mods.ftblibrary.expression) to parse and evaluate boolean expressions against pluggable, namespaced “context providers” (e.g. std.*, level.*, player.*) intended for conditional logic use-cases across FTB mods.
Changes:
- Added lexer/parser + AST node model for a small boolean expression language with comparisons and typed literals (including
BigInteger). - Added an evaluation engine and reflection-based provider invocation with basic argument coercion.
- Added baseline context providers (
std,level,player) and a comprehensive JUnit test suite for parsing/evaluation.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/ExpressionEngine.java | Core entry point that parses and evaluates expressions using registered providers |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/ExpressionParser.java | Recursive-descent parser that produces an AST (Node) |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/Lexer.java | Tokenizer for identifiers, keywords, operators, strings, and numeric literals |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/Node.java | Sealed AST node definitions for operators, comparisons, literals, and provider calls |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/ProviderInvoker.java | Reflection wrapper around providers; handles method discovery, invocation, coercion |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/Token.java | Token record + token type enum used by lexer/parser |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/exceptions/ExpressionEvalException.java | Runtime exception for evaluation errors |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/exceptions/ExpressionParseException.java | Runtime exception for lex/parse errors |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/package-info.java | Applies @NullMarked to the expression package |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/provider/ContextProvider.java | Base class for namespaced providers |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/provider/StdContextProvider.java | Standard provider (std) with basic helpers like isModLoaded |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/provider/LevelContextProvider.java | level provider with day/night/raining helpers |
| common/src/main/java/dev/ftb/mods/ftblibrary/expression/provider/PlayerContextProvider.java | player provider with op/tag/name helpers (stage currently stubbed) |
| common/src/test/java/dev/ftb/mods/ftblibrary/expression/ExpressionEngineTest.java | Unit tests covering parsing, operators, comparisons, providers, reflection/coercion |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…erInvoker.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…sionEngineTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…sionParser.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…erInvoker.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
chore: removed the is and is not and not keywords as they were the same and == / != fix: failing unit tests
…ding feat: more context features
desht
reviewed
Apr 21, 2026
desht
approved these changes
Apr 21, 2026
Contributor
desht
left a comment
There was a problem hiding this comment.
Looks good to me, I added a couple of comments for trivial changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is, although relatively comprehensive, a simple expression evaluation system built around the concept of "context providers" that can optionally support namespaced methods to check against.
I've mocked in some very basic context providers for the level and the player as well as a std provider for core systems.
Out of the box we support most Java native primitive types as well as BigInts to allow builtin expression evaluation without the need for the std helpers.
This is an early concept with passing tests but I'm open to suggestions and improvements.
Right now we have 2 use cases for this. FTB Library itself can use this system for the sidebar conditionals. Then FTB Ranks can also benefit from this for it's conditional system as well. The breaking point in a new feature of Pack Companion also calls for this system so it made sense to bite the bullet and build up a more comprehensive system over the current: Define field, test field per the json specs.