Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="NoTargetRuleResolver.cs" company="Starion Group S.A.">
//
//
// Copyright 2022-2026 Starion Group S.A.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// </copyright>
// ------------------------------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ public TextualNotationRule FindRule(string ruleName)
/// </summary>
public HashSet<string> EmittedHandCodedCalls { get; } = [];

/// <summary>
/// Gets or sets a pending cursor move statement to be emitted inside the innermost
/// consumption block of <c>ProcessNonTerminalElement</c>. This is set by
/// <c>ProcessAssignmentElement</c> for <c>+=</c> assignments inside optional groups
/// (<c>?</c> quantifier), ensuring the cursor only advances when the element was
/// actually consumed by the builder call.
/// </summary>
public string PendingCursorMove { get; set; }

/// <summary>
/// Determines whether the next sibling element is a terminal that uses <c>AppendLine</c>
/// (e.g., <c>{</c>, <c>}</c>, <c>;</c>), in which case a trailing space would be unnecessary.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="RuleProcessor.CollectionProcessing.cs" company="Starion Group S.A.">
//
//
// Copyright 2022-2026 Starion Group S.A.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// </copyright>
// ------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -66,14 +66,14 @@ private void EmitCollectionNonTerminalLoop(EncodedTextWriter writer, IClass umlC
{
var cursorDefinition = new CursorDefinition { DefinedForProperty = targetProperty };
var propertyAccessName = targetProperty.QueryPropertyNameBasedOnUmlProperties();
writer.WriteSafeString($"var {cursorDefinition.CursorVariableName} = cursorCache.GetOrCreateCursor({ruleGenerationContext.CurrentVariableName}.Id, \"{targetProperty.Name}\", {ruleGenerationContext.CurrentVariableName}.{propertyAccessName});{Environment.NewLine}");
writer.WriteSafeString($"var {cursorDefinition.CursorVariableName} = writerContext.CursorCache.GetOrCreateCursor({ruleGenerationContext.CurrentVariableName}.Id, \"{targetProperty.Name}\", {ruleGenerationContext.CurrentVariableName}.{propertyAccessName});{Environment.NewLine}");
ruleGenerationContext.DefinedCursors.Add(cursorDefinition);
cursorVariableName = cursorDefinition.CursorVariableName;
}

var perItemCall = ResolveBuilderCall(umlClass, nonTerminalElement, typeTarget, ruleGenerationContext);
var perItemCall = this.ResolveBuilderCall(umlClass, nonTerminalElement, typeTarget, ruleGenerationContext);

var whileTypeExclusion = ResolveCollectionWhileTypeCondition(cursorVariableName, umlClass, referencedRule, ruleGenerationContext);
var whileTypeExclusion = this.ResolveCollectionWhileTypeCondition(cursorVariableName, umlClass, referencedRule, ruleGenerationContext);

string whileCondition;

Expand Down Expand Up @@ -116,7 +116,7 @@ private void EmitCollectionNonTerminalLoop(EncodedTextWriter writer, IClass umlC

if (assignmentTargetTypes?.Count == 1)
{
var contentTypeGuard = ResolveContentTypeGuard(cursorVariableName, referencedRule, propertyName, umlClass, ruleGenerationContext);
var contentTypeGuard = this.ResolveContentTypeGuard(cursorVariableName, referencedRule, propertyName, umlClass, ruleGenerationContext);

if (!string.IsNullOrWhiteSpace(contentTypeGuard))
{
Expand Down Expand Up @@ -149,7 +149,7 @@ private void EmitCollectionNonTerminalLoop(EncodedTextWriter writer, IClass umlC
var previousName = ruleGenerationContext.CurrentVariableName;
ruleGenerationContext.CallerRule = nonTerminalElement;

ProcessAlternatives(writer, umlClass, referencedRule.Alternatives, ruleGenerationContext);
this.ProcessAlternatives(writer, umlClass, referencedRule.Alternatives, ruleGenerationContext);

ruleGenerationContext.CallerRule = previousCaller;
ruleGenerationContext.CurrentVariableName = previousName;
Expand All @@ -164,7 +164,7 @@ private void EmitCollectionNonTerminalLoop(EncodedTextWriter writer, IClass umlC

var handCodedRuleName = nonTerminalElement.TextualNotationRule?.RuleName ?? nonTerminalElement.Name;

EmitHandCodedFallback(writer, handCodedRuleName, ruleGenerationContext, deduplicate: true);
this.EmitHandCodedFallback(writer, handCodedRuleName, ruleGenerationContext, true);
writer.WriteSafeString(Environment.NewLine);
}

Expand Down Expand Up @@ -302,7 +302,7 @@ private string ResolveContentTypeGuard(string cursorVariableName, TextualNotatio

if (innerRule != null)
{
return ResolveContentTypeGuard(cursorVariableName, innerRule, outerPropertyName, umlClass, ruleGenerationContext);
return this.ResolveContentTypeGuard(cursorVariableName, innerRule, outerPropertyName, umlClass, ruleGenerationContext);
}
}

Expand Down Expand Up @@ -350,7 +350,7 @@ private string ResolveBuilderCall(IClass umlClass, NonTerminalElement nonTermina
{
if (typeTarget == ruleGenerationContext.NamedElementToGenerate.Name)
{
return $"Build{nonTerminalElement.Name}({ruleGenerationContext.CurrentVariableName}, cursorCache, stringBuilder);";
return $"Build{nonTerminalElement.Name}({ruleGenerationContext.CurrentVariableName}, writerContext, stringBuilder);";
}

var targetType = RuleQueryUtilities.FindNamedElement(umlClass.Cache, typeTarget);
Expand All @@ -359,13 +359,13 @@ private string ResolveBuilderCall(IClass umlClass, NonTerminalElement nonTermina
{
if (umlClass.QueryAllGeneralClassifiers().Contains(targetClass))
{
return $"{targetType.Name}TextualNotationBuilder.Build{nonTerminalElement.Name}({ruleGenerationContext.CurrentVariableName}, cursorCache, stringBuilder);";
return $"{targetType.Name}TextualNotationBuilder.Build{nonTerminalElement.Name}({ruleGenerationContext.CurrentVariableName}, writerContext, stringBuilder);";
}

return null;
}

return $"Build{nonTerminalElement.Name}({ruleGenerationContext.CurrentVariableName}, cursorCache, stringBuilder);";
return $"Build{nonTerminalElement.Name}({ruleGenerationContext.CurrentVariableName}, writerContext, stringBuilder);";
}

/// <summary>
Expand Down Expand Up @@ -422,7 +422,7 @@ private bool TryEmitOptionalCondition(EncodedTextWriter writer, NonTerminalEleme
return false;
}

var condition = GenerateInlineOptionalCondition(referencedRule, targetClass, ruleGenerationContext.AllRules, variableName);
var condition = this.GenerateInlineOptionalCondition(referencedRule, targetClass, ruleGenerationContext.AllRules, variableName);

if (condition == null)
{
Expand Down
Loading
Loading