Skip to content

feat: math expressions in input fields#1106

Draft
lucasser wants to merge 2 commits intorefinedmods:developfrom
lucasser:feat/GH-834/expressions-in-input-no-error-handling
Draft

feat: math expressions in input fields#1106
lucasser wants to merge 2 commits intorefinedmods:developfrom
lucasser:feat/GH-834/expressions-in-input-no-error-handling

Conversation

@lucasser
Copy link
Copy Markdown
Contributor

Implements #199

@lucasser lucasser force-pushed the feat/GH-834/expressions-in-input-no-error-handling branch 2 times, most recently from f6b2638 to 3720b7b Compare August 11, 2025 21:25
@lucasser lucasser requested a review from raoulvdberge August 11, 2025 21:26
@lucasser lucasser force-pushed the feat/GH-834/expressions-in-input-no-error-handling branch 2 times, most recently from 73e9574 to 5d2c8d7 Compare August 12, 2025 12:44
@lucasser
Copy link
Copy Markdown
Contributor Author

I added an ifValidOrElse method to ParsedValue to use instead of ifpresentorelse, idk if that works. Other than everything should be fixed.

@lucasser lucasser force-pushed the feat/GH-834/expressions-in-input-no-error-handling branch 6 times, most recently from 0a3390b to 15bb80f Compare August 19, 2025 14:24
@lucasser lucasser force-pushed the feat/GH-834/expressions-in-input-no-error-handling branch from 15bb80f to 9869bac Compare August 24, 2025 16:02
@lucasser lucasser force-pushed the feat/GH-834/expressions-in-input-no-error-handling branch from 9869bac to 844026a Compare September 21, 2025 17:19
@raoulvdberge raoulvdberge added this to the v2.0.x milestone Oct 9, 2025
@lucasser lucasser force-pushed the feat/GH-834/expressions-in-input-no-error-handling branch from 844026a to 5c598ca Compare October 21, 2025 15:00
@lucasser lucasser requested a review from raoulvdberge October 25, 2025 06:22
@lucasser lucasser force-pushed the feat/GH-834/expressions-in-input-no-error-handling branch from 5c598ca to f79e188 Compare October 26, 2025 17:33
@lucasser lucasser force-pushed the feat/GH-834/expressions-in-input-no-error-handling branch from f79e188 to daeee48 Compare January 28, 2026 15:36
@raoulvdberge
Copy link
Copy Markdown
Contributor

Please rebase on develop so I can get another look at this

@lucasser lucasser marked this pull request as draft April 17, 2026 04:08
@lucasser lucasser force-pushed the feat/GH-834/expressions-in-input-no-error-handling branch from daeee48 to 626ea91 Compare April 17, 2026 04:08
@lucasser lucasser force-pushed the feat/GH-834/expressions-in-input-no-error-handling branch from 626ea91 to 6ed6e76 Compare April 17, 2026 04:09
Copy link
Copy Markdown
Contributor

@raoulvdberge raoulvdberge left a comment

Choose a reason for hiding this comment

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

And rebase on develop please

return Optional.ofNullable(value);
}

public boolean isValid() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the only use for ParseValue to indicate out of boundness? I don't care about reporting that error back to the user, so can we remove this class please?

* Evaluate a math expression inside a string.
*/

public class Evaluator {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MathExpressionEvaluator and then we can remove the comment on top of this class.


public Evaluator(final Source source) {
if (source.content().isEmpty()) {
throw new EvaluatorException("");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No message?

lexer = new Lexer(source, LexerTokenMappings.ARITHMETIC_MAPPINGS);
lexer.scan();
} catch (LexerException e) {
throw new EvaluatorException("unrecognized character");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Always pass exception context along

Suggested change
throw new EvaluatorException("unrecognized character");
throw new EvaluatorException("unrecognized character", e);

parser = new Parser(applyUnits(lexer.getTokens()), ParserOperatorMappings.ARITHMETIC_MAPPINGS);
parser.parse();
} catch (ParserException e) {
throw new EvaluatorException("syntax error");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Context

@FieldsAndMethodsAreNonnullByDefault
package com.refinedmods.refinedstorage.query.evaluator;

import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this exists in develop anymore?

Comment thread CHANGELOG.md
### Added

- You can now configure Refined Storage to not require energy. Controllers are not necessary in this case. Creative variants of items will be hidden and items will function without energy.
- Support for entering math expressions when requesting a craft, creating a pattern, and configuring a detector.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Support for entering math expressions when requesting a craft, creating a pattern, and configuring a detector.
- Support for entering math expressions when requesting autocrafting, creating a processing pattern, and configuring a detector.


import static org.junit.jupiter.api.Assertions.assertEquals;

class EvaluatorTest {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where are the tests for the units?

return e.getMessage();
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see any exception edge cases being tested. You probably want to run mutation testing here to check what you're missing!

public class Evaluator {
private final Source source;
private final List<Node> nodes = new ArrayList<>();
private final Map<String, Double> unitMap = Map.of(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can be static?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants