generated from Templates/Dotnet_Library
fix: some bugfixes with fragment parser logic, ref: NOISSUE
This commit is contained in:
parent
c1705d9f96
commit
09bbba1293
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -31,7 +31,7 @@ class FixedRepetitionBlock : BuildingBlockBase
|
||||
this.context = this.inputSchema.CreateContext();
|
||||
}
|
||||
}
|
||||
return result.SingleOrDefault();
|
||||
return result.Single();
|
||||
}
|
||||
|
||||
public override bool CanParseWord(InputProvider inputs)
|
||||
|
@ -22,7 +22,7 @@ class GreedyRepetitionBlock : BuildingBlockBase
|
||||
{
|
||||
this.context = this.inputSchema.CreateContext();
|
||||
}
|
||||
return result.SingleOrDefault();
|
||||
return result.Single();
|
||||
}
|
||||
|
||||
public override bool CanParseWord(InputProvider inputs)
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
|
@ -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++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user