Skip to content

fix: formatter roundtrip for group qualifications, intervals, and expressions (#300)#304

Merged
ronaldtse merged 4 commits into
mainfrom
fix/issue-300-formatter-roundtrip
May 14, 2026
Merged

fix: formatter roundtrip for group qualifications, intervals, and expressions (#300)#304
ronaldtse merged 4 commits into
mainfrom
fix/issue-300-formatter-roundtrip

Conversation

@ronaldtse
Copy link
Copy Markdown
Contributor

Summary

Fixes #300expressir format now produces output that can be re-parsed and produces the same model (structural content is stable across format iterations).

Root Cause

The formatter was outputting NOT {interval} which is ambiguous in EXPRESS — the parser sees NOT followed by { and cannot match it as an interval expression. The original code wraps intervals in parens: NOT ({interval}).

Changes

Formatter fixes

  • Interval + unary expression: Wrap interval operands in parens when inside NOT
  • Binary expression precedence: Use >= for same-precedence parenthesization
  • AGGREGATE OF: Format with OF type when base_type is present
  • Empty SELECT: Handle SELECT types with no items
  • Binary literals: Value already includes % prefix

Builder fixes

  • Shorthand variables: Fix double-wrapping of variable_id keys
  • Procedure parameters: Same fix for formal parameters and procedure head parameters
  • CASE statements: Proper case label and otherwise_statement handling
  • AGGREGATE OF: Add builder support
  • Type builder: Replace hash+define_method with explicit methods to fix autoload ordering
  • Registry: Remove all send calls, remove duplicate registrations

Model fixes

  • Remove HasWhereRules from Function/Procedure (EXPRESS spec compliance)
  • Harden remark_attacher to use safe_get_collection for where_rules

Tests

  • Add formatter_roundtrip_spec.rb with 10 test cases covering all fixed bugs
  • Regenerate YAML and .exp fixtures to match improved builder output

Verification

  • syntax.exp: roundtrips with structural content identical
  • mathematical_functions_schema.exp (15K+ lines): roundtrips with structural content identical
  • 103 specs pass, 0 failures
  • Rubocop clean on all changed files

ronaldtse added 4 commits May 14, 2026 14:49
…ve send calls

- Fix shorthand variable declarations (slo, shi : INTEGER) expanding
  correctly by unwrapping double-nested variable_id keys in
  constant_builder and procedure_decl_builder
- Fix CASE statement building: proper case label handling and
  otherwise_statement assignment
- Add AGGREGATE OF type builder support
- Replace type_builder hash+define_method with explicit method
  definitions to avoid autoload ordering issues
- Remove all send calls from builder_registry, use direct method calls
- Remove duplicate subtype constraint registrations
- Fix Model::ModelElement resolution in builder.rb

Fixes #300
…REGATE, SELECT, binary literals

- Wrap interval operands in parens when inside unary expression
  (NOT {interval} -> NOT ({interval})) to avoid parser ambiguity
- Use >= comparison for same-precedence binary expression parens
  so (4 + 2) + 1 is explicit rather than 4 + 2 + 1
- Format AGGREGATE type with OF <base_type> when present
- Handle empty SELECT types in formatter
- Fix binary literal formatting (value already includes % prefix)

Fixes #300
…cher

Function and Procedure cannot have WHERE clauses per ISO 10303-11.
Removed incorrect include HasWhereRules from both models.
Changed remark_attacher to use safe_get_collection for where_rules
access to handle models that include the concern without the attribute.
Add formatter_roundtrip_spec.rb covering:
- NOT + interval parenthesization
- Shorthand variable declarations
- Procedure VAR parameters
- Group qualification with index qualifiers
- Binary expression same-precedence parens
- Binary literals
- Full syntax.exp structural content stability

Regenerate YAML and .exp fixtures to match improved builder output.
@ronaldtse ronaldtse merged commit 85a7aa5 into main May 14, 2026
3 checks passed
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.

expressir format seems to discard group qualifications from identifiers

1 participant