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

math: implement assignment operators #77238

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

andrei8l
Copy link
Contributor

@andrei8l andrei8l commented Oct 21, 2024

Summary

None

Purpose of change

The math parser enforces an expression split in 1/2/3 strings as a design choice, in order to get neat(-ish) line breaks for long expressions. In practice though, most expressions are short and this design choice leads to a mess of commas and quotation marks.

Describe the solution

Store intermediary function nodes as prototypes and only resolve them when operators/parens/eof/whatever are resolved.
Add assignment operators.
Reduce the eoc-math glue to a glorified string concatenator.

In practice this means that:
Instead of this:

{ "math": [ "MORALE_MULTIPLIER", "=", "u_has_trait('SQUEAMISH') ? -2 : -1" ] },

you can write this:

{ "math": [ "MORALE_MULTIPLIER = u_has_trait('SQUEAMISH') ? -2 : -1" ] },

(it was already possible for comparison operators)

but you can also split it into as many strings as you want for the purpose of clarity or whatever:

      {
        "math": [ 
          "MORALE_MULTIPLIER",
          "=",
          "u_has_trait('SQUEAMISH')",
          "?",
          "-2",
          ":",
          "-1"
        ] 
      },

TODO:

  • more test units
  • fuzz test: I've been running this fuzz target (with this change) with this corpus extracted from data and test units for ~24 hours
  • figure out what broke: my head

Describe alternatives you've considered

N/A

Testing

Test units

Additional context

N/A

@github-actions github-actions bot added <Documentation> Design documents, internal info, guides and help. NPC / Factions NPCs, AI, Speech, Factions, Ownership Code: Tests Measurement, self-control, statistics, balancing. [C++] Changes (can be) made in C++. Previously named `Code` [Markdown] Markdown issues and PRs EOC: Effects On Condition Anything concerning Effects On Condition new contributor json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Oct 21, 2024
@andrei8l andrei8l marked this pull request as ready for review October 22, 2024 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. <Documentation> Design documents, internal info, guides and help. EOC: Effects On Condition Anything concerning Effects On Condition json-styled JSON lint passed, label assigned by github actions [Markdown] Markdown issues and PRs new contributor NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant