Skip to content

Let a unary operator take a unary expression - #26

Open
mbrunnen wants to merge 1 commit into
Open-MBEE:mainfrom
mbrunnen:nested-unary-operators
Open

mbrunnen wants to merge 1 commit into
Open-MBEE:mainfrom
mbrunnen:nested-unary-operators

Conversation

@mbrunnen

@mbrunnen mbrunnen commented Nov 7, 2026

Copy link
Copy Markdown

Fixes #25.

parse_unary now parses the operand of a unary operator as another unary
expression, so - -x, ~~x and not not b parse. KerML 1.0 gives the
operand as an ArgumentMember, so any expression
(8.2.5.8.1 Operator Expressions).
The Pilot's KerMLExpressions.xtext narrows it to ExtentExpression.

How to test

$ cargo test -p sysmlv2-parser --test integration unary_operators_nest
$ printf 'package P { attribute a = - -x; }\n' | sysmlv2 parse -

Look closely at

  • The recursion goes through descend, so the nesting bound still applies
    to a long run of operators.
  • Precedence does not change: - -2 ** 3 parses as (-(-2)) ** 3, as
    -2 ** 3 parses as (-2) ** 3.
  • sysmlv2 fmt prints -(-x) as --x. That text now parses again, so
    fmt no longer refuses such a file. No baseline changes.
  • The CHANGELOG.md entry is under a new Unreleased heading. Move or drop
    it as you prefer.

KerML 8.2.5.8.1 gives the operand of a UnaryOperatorExpression as an
ArgumentMember, so any expression, and `- -x` and `not not b` are valid.
The parser followed the Pilot's Xtext, which narrows the operand to an
ExtentExpression. The formatter prints `-(-x)` as `--x`, so it refused
such a file.
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.

Nested unary operators do not parse: - -x, ~~x, not not b

1 participant