-
Notifications
You must be signed in to change notification settings - Fork 181
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
New ore filter implementation #1561
Conversation
…rted any char, any char or more & inverted any char or more; fix some tokens getting included in literals
…, encapsulate inverted/next field
# Conflicts: # src/main/java/gregtech/GregTechMod.java
- 'inversion' -> 'not'/'negation'; Turns out 'logical inversion' means completely different thing oops - 'nothing' -> 'empty' - 'something' -> 'nonempty' - 'impossible' -> 'nothing'
- using $ without providing any compilation flags produces error - consecutive compilation flag blocks at the beginning correctly displays "compilation flags in middle of expression" error - fixed $ not getting formatted if the compilation flag is terminated with EOF
Good work on this PR! Just now I am testing it so I will leave few comments on what I think needs addressing. |
src/main/java/gregtech/common/gui/widget/CompileStatusWidget.java
Outdated
Show resolved
Hide resolved
src/main/java/gregtech/common/gui/widget/OreFilterTestSlot.java
Outdated
Show resolved
Hide resolved
src/main/java/gregtech/common/gui/widget/orefilter/ItemOreFilterTestSlot.java
Outdated
Show resolved
Hide resolved
src/main/java/gregtech/common/gui/widget/orefilter/OreFilterTestSlot.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this PR! I feel that now it is completed. Implementation looks reasonable and new behavior is great. From ingame test no problem with upgrading old filters found and adding new filters now is way easier.
src/main/java/gregtech/common/covers/filter/OreDictionaryItemFilter.java
Outdated
Show resolved
Hide resolved
…avor of cringe double breakers
What
This PR replaces previous ore dictionary filter system with a brand new implementation of ore filter expression parser and interpreter. This PR features a newly designed language based on previous ore filter expression, with a cheeky name "oreglob". (ore + glob)
Implementation Details
Language Specification
Grammar of the lauguage in EBNF is as follows.
This grammar set is very similar to previous ore filter expression, for example:
|
denotes logicalOR
.&
denotes logicalAND
.^
denotes logicalXOR
.!
denotes logical negation.*
denotes wildcard; i.e. 0 or more characters.A number of changes and additions are also present, namely:
a | b & c
anda & b | c
, logicalAND
is computed first in both scenario.!
has an additional rule to prevent possible case of confusion.!
token, it will be grouped as one match before negation; for example,!*plate*
is equivalent to!(*plate*)
.(
directly follows after!
, the following matches after enclosing parenthesis are not grouped. For example,!(ore)Gold
does not mean!(oreGold)
; it is a syntactic sugar to treat negation on a group as same as negation inside a group. (!(a)
==(!a)
)?
, matches any one character. Using this, if you want input with 1 or more characters, then you could write this:?*
()
denotes nothing, i.e. zero characters. This is logically equivalent to!(?*)
.\
) allows keyword characters to be included in literals.Outside of grammars, the language contains some behavior changes, including:
ingotiron
can matchingotIron
and so on. Users can opt-out from this and make the match case sensitive again, by inserting$c
(compilation flag) at the start of expression.*
as expression will start to match items with no oredict.A simple parser,
OreGlobParser
, was created using top-down approach.Interpreter Design
The interpreter, which inspired by this article, uses set of states to track the match result. Match is considered as success if any of the final output state is equal to input string's length, indicating the state chewed through entire string while evaluating each OreGlob nodes.
More detailed explanation is written on
NodeInterpreter
.User Convenience Feature.
The goal of OreGlob is not just to clean up quirks of old implementation, but generally provide much nicer usability for users including those without extensive knowledge on programming languages. One way of achieving such goal is literally telling players the compiled result of expressions and errors.
The compiler may output error and warnings along with OreGlob instance, which can be displayed by text. The OreGlob instance itself can be translated to formatted string, which looks like below.
API layer
I have tried to hide implementation detail behind abstraction layer as much as possible, to account for future rewrite potential. For now, only 7 classes are defined in API package, with 3 of them being inner classes.
UI changes
Ore filter UI has been redesigned to accommodate new features available with OreGlob, as well as to provide better quality-of-life features.
Potential Compatibility Issues
As the new language spec contains numerous behavior changes, it is possible that some of the setups will behave differently. Users should be notified about this potential issue before updating.