Skip to content

Support math expressions in numeric YAML parameters - #390

Open
tylerjw wants to merge 3 commits into
PickNikRobotics:mainfrom
tylerjw:tyler/381-yaml-math
Open

tylerjw wants to merge 3 commits into
PickNikRobotics:mainfrom
tylerjw:tyler/381-yaml-math

Conversation

@tylerjw

@tylerjw tylerjw commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #381.

Allow numeric YAML defaults such as default_value: "${pi/2}" to be evaluated during generation. The same arithmetic works in numeric array elements, fixed-size arrays, and validator arguments, and produces consistent C++, Python, Markdown, and RST output.

The evaluator accepts numeric literals, pi, tau, e, parentheses, unary signs, and +, -, *, /, //, %. It walks an allowlisted syntax tree without executing Python code. String parameters remain literal, and invalid expressions report the parameter name. Also correct the scalar type-error diagnostic so a floating-point expression assigned to an integer parameter reports a generation error.

Validation: all 52 generator tests pass, including 32 new arithmetic, rejection, type-checking, and output-equivalence cases.

@tylerjw

tylerjw commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author

@Timple does this do what you were hoping for?

@Timple

Timple commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

It is!
Super!

@christophfroehlich christophfroehlich left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great, thanks! Can we add some expressions to the examples please (both c++ and python)?

@mergify

mergify Bot commented Oct 6, 2026

Copy link
Copy Markdown

This pull request is in conflict. Could you fix it @tylerjw?

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.

Feature request: math in the yaml

3 participants