Skip to content

Conversation

@kentquirk
Copy link
Member

Description

I'm trying to write an OTTL plugin for syntax coloring. I needed to write an OTTL grammar, and while doing so I realized there are bugs in OTTL's handling of numeric expressions.

In particular, the OTTL math expression parser did not correctly handle unary signs for plus
and minus. Expressions like "3+-5" would not parse correctly. Additionally,
floating point constants that had a decimal point but no fractional digits
(e.g., "3.") were not handled properly and could crash the parser. This change
moves the sign handling out of the lexer and into the parser.

  • Correctly parse unary plus and minus operators in mathematical expressions.
  • Unary plus is a no-op, but is explicitly handled.
  • Handle floating point constants that have a decimal point but no fractional digits (e.g.,
    3.). These are now parsed as valid floating point numbers.
  • Many tests were added to verify correct parsing and evaluation of these cases.

Link to tracking issue

#45222

Testing

Both lexer and parser tests were added to the ottl package.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add the .yaml extension to this file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Doh. Sorry about that.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants