fix: some bugfixes with fragment parser logic, ref: NOISSUE

This commit is contained in:
Simon Diesenreiter 2024-12-03 21:32:02 +01:00
parent c1705d9f96
commit 09bbba1293
8 changed files with 25 additions and 25 deletions

View File

@ -17,23 +17,7 @@ on:
workflow_dispatch:
jobs:
linter:
strategy:
fail-fast: false
matrix:
dotnet-version: [9.0.X]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Run linter
run: make lint
tests_linux:
needs: linter
strategy:
fail-fast: false
matrix:

View File

@ -230,7 +230,7 @@ public class TextParserTests
.EndOptions()
.Build();
var parser = new TextParser<FragmentSchemaContext>(schema);
var parser = TextParser.Create(schema);
var fragmentData = parser
.SetInputText(testInput5)
.Parse()

View File

@ -31,7 +31,7 @@ class FixedRepetitionBlock : BuildingBlockBase
this.context = this.inputSchema.CreateContext();
}
}
return result.SingleOrDefault();
return result.Single();
}
public override bool CanParseWord(InputProvider inputs)

View File

@ -22,7 +22,7 @@ class GreedyRepetitionBlock : BuildingBlockBase
{
this.context = this.inputSchema.CreateContext();
}
return result.SingleOrDefault();
return result.Single();
}
public override bool CanParseWord(InputProvider inputs)

View File

@ -100,6 +100,10 @@ public class FragmentSchemaBuilder : RepetitionSchemaBuilder<FragmentSchemaBuild
throw new Exception("Invalid repetition definitions!");
}
var oldSchemaBuilder = currentBuilder.UpperLayerBuilder;
if (oldSchemaBuilder == null)
{
throw new Exception("Something went terribly wrong!");
}
var currentRegex = "(" + currentBuilder.fragmentRegex + ")";
switch (currentBuilder.RepetitionType)

View File

@ -55,22 +55,26 @@ public class InputSchemaBuilder : RepetitionSchemaBuilder<InputSchemaBuilder, In
{
throw new Exception("Invalid repetition definitions!");
}
var oldInputSchemaBuilder = currentBuilder.UpperLayerBuilder;
var oldSchemaBuilder = currentBuilder.UpperLayerBuilder;
if (oldSchemaBuilder == null)
{
throw new Exception("Something went terribly wrong!");
}
var currentSchema = currentBuilder.Build();
switch (currentBuilder.RepetitionType)
{
case RepetitionType.FixedRepetition:
oldInputSchemaBuilder.schema.AddBuildingBlock(new FixedRepetitionBlock(currentSchema, currentBuilder.NumRepetition));
oldSchemaBuilder.schema.AddBuildingBlock(new FixedRepetitionBlock(currentSchema, currentBuilder.NumRepetition));
break;
case RepetitionType.GreedyRepetition:
oldInputSchemaBuilder.schema.AddBuildingBlock(new GreedyRepetitionBlock(currentSchema));
oldSchemaBuilder.schema.AddBuildingBlock(new GreedyRepetitionBlock(currentSchema));
break;
default:
throw new Exception("Unrecognized RepetitionType");
}
return oldInputSchemaBuilder;
return oldSchemaBuilder;
}
public InputSchema Build()

View File

@ -5,6 +5,14 @@ using System.Collections.Generic;
using Parsing.Schema;
using Parsing.Tokenization;
public static class TextParser
{
public static TextParser<TContext> Create<TContext>(ISchema<TContext> schema, string[]? delimiters = null, bool removeEmptyEntries = true) where TContext : ISchemaContext
{
return new TextParser<TContext>(schema, delimiters, removeEmptyEntries);
}
}
public class TextParser<T> : TokenConverter where T : ISchemaContext
{
private LineParser<T> lineParser;

View File

@ -56,7 +56,7 @@ public static class DataManipulationHelpers
{
if (data.Count < 2)
{
return data[0] ?? default(TType);
return data[0];
}
TType result = data[0];
for (int i = 1; i < data.Count; i++)