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
17 changes: 15 additions & 2 deletions AnyText/AnyText.Core/ParsePositionDelta.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
namespace NMF.AnyText
using System;

namespace NMF.AnyText
{
/// <summary>
/// Denotes a delta between parser positions
/// </summary>
/// <param name="Line">the line delta</param>
/// <param name="Col">the column delta</param>
public record struct ParsePositionDelta(int Line, int Col)
public record struct ParsePositionDelta(int Line, int Col) : IComparable<ParsePositionDelta>
{
/// <summary>
/// Calculates the larger of two diffs
Expand Down Expand Up @@ -35,6 +37,17 @@ public static ParsePositionDelta Smaller(ParsePositionDelta delta1, ParsePositio
return delta1;
}

/// <inheritdoc />
public int CompareTo(ParsePositionDelta other)
{
var ret = Line.CompareTo(other.Line);
if (ret != 0)
{
return ret;
}
return Col.CompareTo(other.Col);
}

/// <summary>
/// Determines whether the first delta is larger than the second
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions AnyText/AnyText.Core/Rules/FailedChoiceRuleApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ public override RuleApplication Recover(RuleApplication currentRoot, ParseContex
{
if (Rule is ChoiceRule choice)
{
for (var i = 0; i < choice.Alternatives.Length; i++)
foreach (var fail in _innerFailures.OrderByDescending(f => f.ExaminedTo))
{
var fail = _innerFailures.FirstOrDefault(app => app.Rule == choice.Alternatives[i].Rule);
if (fail == null) continue;
var recovery = fail.Recover(currentRoot, context, out position);
if (recovery.IsPositive)
{
Expand Down
5 changes: 5 additions & 0 deletions AnyText/AnyText.Core/Rules/FailedSequenceRuleApplication.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace NMF.AnyText.Rules
{
Expand Down Expand Up @@ -94,6 +95,10 @@ internal override IEnumerable<CompletionEntry> SuggestCompletions(ParsePosition

public override void AddParseErrors(ParseContext context)
{
if (_successfulApplications.Count > 0)
{
_successfulApplications.Last().AddParseErrors(context);
}
if (_furtherFails != null)
{
foreach (var fail in _furtherFails)
Expand Down
5 changes: 4 additions & 1 deletion AnyText/AnyText.Core/Rules/StarRuleApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ internal override IEnumerable<CompletionEntry> SuggestCompletions(ParsePosition

public override void AddParseErrors(ParseContext context)
{
Stopper?.AddParseErrors(context);
if (Stopper != null && Stopper.CurrentPosition.Line < context.Input.Length)
{
Stopper.AddParseErrors(context);
}
base.AddParseErrors(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ private static CodeExpression CreateParserExpression(IParserExpression parserExp
return choiceExpression;
case INegativeLookaheadExpression negative:
return new CodeObjectCreateExpression(typeof(NegativeLookaheadRule).ToTypeReference(), CreateParserExpression(negative.Inner, negative.FormattingInstructions, ruleTransformation, assignTransformation, context));
case IPositiveLookaheadExpression positive:
return new CodeObjectCreateExpression(typeof(PositiveLookaheadRule).ToTypeReference(), CreateParserExpression(positive.Inner, positive.FormattingInstructions, ruleTransformation, assignTransformation, context));
}
throw new NotSupportedException();
}
Expand Down Expand Up @@ -1077,6 +1079,7 @@ private static CodeMemberMethod CreateSetValue(CodeTypeReference semanticType, C

private static CodeMemberMethod CreateGetValue(IAssignExpression input, CodeTypeReference semanticType, CodeTypeReference propertyType, CodeArgumentReferenceExpression semanticElementRef, CodePropertyReferenceExpression property)
{
var feature = CodeGenerator._trace.LookupFeature(input);
var getValue = new CodeMemberMethod
{
Name = "GetValue",
Expand All @@ -1094,6 +1097,10 @@ private static CodeMemberMethod CreateGetValue(IAssignExpression input, CodeType
["context"] = "the parsing context"
});
CodeExpression getValueReturn = property;
if (feature != null && feature.LowerBound == 0 && input.Assigned is RuleExpression ruleExpression && ruleExpression.Rule is EnumRule)
{
getValueReturn = new CodeMethodInvokeExpression(getValueReturn, nameof(Nullable<int>.GetValueOrDefault));
}
getValue.Statements.Add(new CodeMethodReturnStatement(getValueReturn));
return getValue;
}
Expand Down
3 changes: 2 additions & 1 deletion AnyText/AnyText.history
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ patch: if a rule application is found, do not increase the deletion index
patch: improve code lenses for synchronizations
major: changed extension API for indentation-aware, create API to propagate context changes
patch: do not check whether rule application is memoized if it is only interesting to see whether the line is obsolete
patch: adapt metamodel code to changed interface
patch: adapt metamodel code to changed interface
patch: improve error reporting
Loading