Skip to content

Introduction of expression based language#185

Merged
MichaelHillcox merged 21 commits into
devfrom
feature/expression-engine
Apr 21, 2026
Merged

Introduction of expression based language#185
MichaelHillcox merged 21 commits into
devfrom
feature/expression-engine

Conversation

@MichaelHillcox
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread common/src/main/java/dev/ftb/mods/ftblibrary/expression/Lexer.java Outdated
Comment thread common/src/main/java/dev/ftb/mods/ftblibrary/expression/ProviderInvoker.java Outdated
Comment thread common/src/main/java/dev/ftb/mods/ftblibrary/expression/ExpressionParser.java Outdated
Comment thread common/src/test/java/dev/ftb/mods/ftblibrary/expression/ExpressionEngineTest.java Outdated
MichaelHillcox and others added 16 commits April 19, 2026 14:30
…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
Copy link
Copy Markdown
Contributor

@desht desht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I added a couple of comments for trivial changes.

@MichaelHillcox MichaelHillcox merged commit d28ca0e into dev Apr 21, 2026
1 check passed
@MichaelHillcox MichaelHillcox deleted the feature/expression-engine branch April 21, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants