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

Predicate parser, arithmetic parser improvements and bug fixes #9

Merged
merged 27 commits into from
Oct 5, 2020

Conversation

masked-rpgmaker
Copy link
Member

@masked-rpgmaker masked-rpgmaker commented Oct 5, 2020

Changelog:

  • Sync with latest version from the archetype;
  • Add some tests (yay /o/);
  • Fix a bug on operator precedence where it wouldn't be updated for deeply nested operations;
  • Implement game variable references into the arithmetic parser under the syntax v[<id>]. For instance:
const { expression, evaluate } = Schach.Parsing.Arithmetic;

let { parsed } = expression().run("v[5] + v[1 + v[3]]");

$gameVariables.setValue(5, 10);
$gameVariables.setValue(3, 5);

$gameVariables.setValue(6, 15);
evaluate(parsed); // < 25

$gameVariables.setValue(6, 20);
evaluate(parsed); // < 30
  • Implement free variables provided at runtime under the syntax #<name>. For instance:
const { expression, evaluate } = Schach.Parsing.Arithmetic;

let { parsed } = expression().run("2^#x - #y");
evaluate(parsed, { variables: { x: 5, y: -10 } }); // < 42
  • Implement functions into the arithmetic parser. Functions can be either built-in (for a complete list see evaluate.ts) or provided at runtime. Runtime functions override the built-in ones. For instance:
const { expression, evaluate } = Schach.Parsing.Arithmetic;

let { parsed } = expression().run("max(sqrt(100), f(#x))"); // max and sqrt are built-in

evaluate(parsed, {
  variables: { x: 5 },
  functions: { f: n => 40 * n }
});
// < 200

Related issues:

@masked-rpgmaker masked-rpgmaker changed the title Development Predicate parser, arithmetic parser improvements and bug fixes Oct 5, 2020
@masked-rpgmaker masked-rpgmaker merged commit 4a3de4d into master Oct 5, 2020
@masked-rpgmaker masked-rpgmaker added the bug Something isn't working label Oct 5, 2020
@masked-rpgmaker masked-rpgmaker added the enhancement New feature or request label Oct 5, 2020
@masked-rpgmaker masked-rpgmaker added this to the v1.0.0 milestone Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
1 participant