Skip to content

Feature/pascal case - #24

Open
rdeininger wants to merge 4 commits into
mainfrom
feature/PascalCase
Open

Feature/pascal case#24
rdeininger wants to merge 4 commits into
mainfrom
feature/PascalCase

Conversation

@rdeininger

Copy link
Copy Markdown
Collaborator

Changes Summary

1. OCL Function Handling Refactor

  • Moved built-in OCL functions (oclIsKindOf, oclIsTypeOf, oclAsType, oclIsUndefined,
    oclIsInvalid) out of the basicExpression rule and into the function rule in the
    ANTLR4 grammar (antlr4/OCL.g4) and the corresponding visitor logic in
    OclToCSharpConverter.cs.

2. Grammar Fix for let/if in Logical Expressions

  • Fixed the OCL grammar so that let-in expressions and if-then-else expressions are
    correctly parsed as the right-hand side of logical operators (implies, and, or, xor).
  • Previously these caused parse errors or incorrect ASTs in expressions like:
    x implies let y = ... in ...
    x implies if ... then ... else ... endif

3. OCL Grammar Refactor

  • Consolidated and cleaned up grammar rules to remove ambiguity and improve
    parse coverage for complex nested expressions.
  • Improved test data in testdata/Consolidated_OCLAndCSharp.md and
    testdata/SysML_OCLAndCSharp.md with additional edge-case OCL inputs.

4. PascalCase Property and Method Conversion

  • Per C# coding guidelines, all OCL property and method names in the generated
    C# output are now converted to PascalCase.
  • Lambda parameter names and let-binding variable names remain camelCase
    (they are local variables, not C# members).

Implementation details (OclToCSharpConverter.cs):

  • Added _localVariables HashSet for tracking lambda/let variable scopes.
  • Added ToPascalCase(string) helper: uppercases the first character unless the
    name is a local variable or already starts with an uppercase letter.
  • Applied ToPascalCase at all identifier emission points:
    • VisitIdentifier
    • VisitExpression (derivation form LHS)
    • VisitBasicExpression (member access, qualified_name segments)
    • BuildDotMethodCall (including keyword-token operations like isUnique)
    • BuildArrowGenericCall, BuildArrowSimpleOrChained
    • BuildOclAsType, BuildArrowOclAsType, BuildSelectByKind, BuildAtAccess
  • Local variable scope tracked in: BuildCollectionOp, BuildReject, BuildOne,
    BuildClosure, BuildIsUnique, BuildIterate, VisitLetExpression.
  • ApplyImplicitSelf regex patterns updated from [a-z_] to [A-Za-z_] so they
    correctly match PascalCased identifiers.
  • Fixed qualified_name handler to strip OCL _'keyword' syntax (e.g. _'in' → In).
  • Fixed ->at(expr).member: the optional trailing member access after ->at() was
    previously dropped; it is now included in the output (e.g.
    foo->at(1).bar → foo.ElementAt(0).Bar).

Test data updates:

  • testdata/Consolidated_OCLAndCSharp.md: all 35 C# blocks regenerated.
  • testdata/SysML_OCLAndCSharp.md: all 611 C# blocks regenerated.
  • src/Ocl2CSharp.Tests/OclToCSharpConverterTests.cs: ~100+ hardcoded expected
    values updated to PascalCase.

@rdeininger
rdeininger requested review from danielsiegl and a lite review from Copilot August 12, 2026 11:17
@rdeininger
rdeininger requested review from philippkalenda and removed request for Copilot August 17, 2026 06:49
Comment thread src/Ocl2CSharp/OclToCSharpConverter.cs Outdated
@@ -378,8 +395,8 @@ public override string VisitBasicExpression(OCLParser.BasicExpressionContext con
var sep = context.GetChild(1).GetText();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

possible NullRef?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

possibly check all other usage of GetChild

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.

2 participants