Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d68b70fa5 | |||
| e41d93e301 | |||
| 19fdbe4dac | |||
| ec1e65c03b | |||
| f6701df12d | |||
| 610b628081 | |||
| f480334eee | |||
| 8608e4ddd1 | |||
| 7133ec1560 | |||
| 2f92f59a50 | |||
| 97a4da7531 | |||
| c577f15f91 | |||
| b4d55ddfc0 | |||
| f51aad91fa | |||
| cab7ac35ae | |||
| 86bb120e32 | |||
| c728509978 | |||
| 7bd2429a43 | |||
| d41d9f1791 | |||
| 1a8a82c106 | |||
| 414c74be84 | |||
| f8c00da2b8 | |||
| d4ac62c592 | |||
| 0f533c2018 | |||
| 2067fe06fc | |||
| cc0f0a24d9 | |||
| c41d665ab8 | |||
| 2fbdafa0e9 | |||
| f942954678 | |||
| 4c67e8efb0 | |||
| e83e99758a | |||
| 81ac797b4c | |||
| e9aa60524c | |||
| 7e5ab9f799 | |||
| fc137ebd03 | |||
| 1b2e9ad1ee | |||
| 550c8280a6 |
@@ -57,12 +57,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
REPOSITORY_OWNER=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $1}')
|
REPOSITORY_OWNER=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $1}')
|
||||||
REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $2}' | tr '-' '_')
|
REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $2}' | tr '-' '_')
|
||||||
REPOSITORY_SOURCE_NAME=gitea-repo
|
|
||||||
if [ -z "$(dotnet nuget config get all | grep "/packages/${REPOSITORY_OWNER}/nuget/index.json")" ]; then
|
|
||||||
dotnet nuget add source --name $REPOSITORY_SOURCE_NAME https://git.disi.dev/api/packages/$REPOSITORY_OWNER/nuget/index.json
|
|
||||||
else
|
|
||||||
QUOTED_REPOSITORY_SOURCE_NAME=$(dotnet nuget config get all | grep "/packages/${REPOSITORY_OWNER}/nuget/index.json" | awk '{print $2}' | awk -F= '{print $2}')
|
|
||||||
REPOSITORY_SOURCE_NAME=${QUOTED_REPOSITORY_SOURCE_NAME:1:-1}
|
|
||||||
fi
|
|
||||||
dotnet pack --include-symbols --include-source -p:PackageVersion=$(cat $REPOSITORY_NAME/VERSION) TextParser.sln
|
dotnet pack --include-symbols --include-source -p:PackageVersion=$(cat $REPOSITORY_NAME/VERSION) TextParser.sln
|
||||||
dotnet nuget push -k $GITEA_PAT --source $REPOSITORY_SOURCE_NAME $REPOSITORY_NAME/bin/Release/$REPOSITORY_NAME.$(cat $REPOSITORY_NAME/VERSION).symbols.nupkg
|
echo "dotnet nuget push -k ${GITEA_PAT:0:-15} $REPOSITORY_NAME/bin/Release/$REPOSITORY_NAME.$(cat $REPOSITORY_NAME/VERSION).symbols.nupkg"
|
||||||
|
dotnet nuget push -k $GITEA_PAT $REPOSITORY_NAME/bin/Release/$REPOSITORY_NAME.$(cat $REPOSITORY_NAME/VERSION).symbols.nupkg
|
||||||
|
|||||||
174
HISTORY.md
174
HISTORY.md
@@ -4,6 +4,180 @@ Changelog
|
|||||||
|
|
||||||
(unreleased)
|
(unreleased)
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- More debug outputs, refs NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
|
||||||
|
0.11.7 (2025-10-26)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Simplify push script, refs NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.11.6 (2025-10-26)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Bugfix, refs NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.11.5 (2025-10-26)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Fix default push NuGet source, refs NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.11.4 (2025-10-26)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Set default push NuGet source, refs NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.11.3 (2025-10-26)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Reenable all NuGet sources, refs NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.11.2 (2025-10-26)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Even more debug output during releases, refs NOISSUE. [Simon
|
||||||
|
Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.11.1 (2025-10-26)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- More debug output during releases, refs NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
- Ci: reenable one of the NuGet sources, refs NOISSUE. [Simon
|
||||||
|
Diesenreiter]
|
||||||
|
|
||||||
|
|
||||||
|
0.11.0 (2025-10-26)
|
||||||
|
-------------------
|
||||||
|
- Revert "feat: add two dimensional data walker, refs: NOISSUE" [Simon
|
||||||
|
Diesenreiter]
|
||||||
|
|
||||||
|
This reverts commit 414c74be84aecd3aff2f7abbb6cab88f50034d84.
|
||||||
|
- Ci: disable nuget feeds for now, refs NOISSUE. [Simon Diesenreiter]
|
||||||
|
- Feat: add two dimensional data walker, refs: NOISSUE. [Simon
|
||||||
|
Diesenreiter]
|
||||||
|
|
||||||
|
|
||||||
|
0.10.0 (2024-12-13)
|
||||||
|
-------------------
|
||||||
|
- Feat: add support for custom token types and longs, ref: NOISSUE.
|
||||||
|
[Simon Diesenreiter]
|
||||||
|
|
||||||
|
|
||||||
|
0.9.3 (2024-12-13)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Remove duplicate TokenConverter definition, ref: NOISSUE. [Simon
|
||||||
|
Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.9.2 (2024-12-13)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- More bugfixes, ref: NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.9.1 (2024-12-13)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Fix build issues, ref: NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.9.0 (2024-12-13)
|
||||||
|
------------------
|
||||||
|
- Feat: add filter option to TokenConverter, ref: NOISSUE. [Simon
|
||||||
|
Diesenreiter]
|
||||||
|
|
||||||
|
|
||||||
|
0.8.0 (2024-12-12)
|
||||||
|
------------------
|
||||||
|
- Feat: adding sensible index constructors refs: NOISSUE. [Simon
|
||||||
|
Diesenreiter]
|
||||||
|
|
||||||
|
|
||||||
|
0.7.2 (2024-12-05)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Add some missing API methods, ref: NOISSUE. [Simon Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.7.1 (2024-12-05)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Fix
|
||||||
|
~~~
|
||||||
|
- Allow for parsing single chars as input, ref: NOISSUE. [Simon
|
||||||
|
Diesenreiter]
|
||||||
|
|
||||||
|
Other
|
||||||
|
~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
0.7.0 (2024-12-05)
|
||||||
|
------------------
|
||||||
- Feat: implement generic data set manipulator, ref: NOISSUE. [Simon
|
- Feat: implement generic data set manipulator, ref: NOISSUE. [Simon
|
||||||
Diesenreiter]
|
Diesenreiter]
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ public class TextParserTests
|
|||||||
private const string testInput9 = @"2 4 6 4 1
|
private const string testInput9 = @"2 4 6 4 1
|
||||||
3 5 4 7 6
|
3 5 4 7 6
|
||||||
4 6 8 3 9";
|
4 6 8 3 9";
|
||||||
|
private const string testInput10 = @"abc
|
||||||
|
bca
|
||||||
|
cab";
|
||||||
|
private const string testInput11 = @"2 x y 4 x y 6 x y 4 x y 1 x y";
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LineParser_TestSimpleRepetition()
|
public void LineParser_TestSimpleRepetition()
|
||||||
@@ -389,4 +393,54 @@ public class TextParserTests
|
|||||||
Assert.Equal(Direction.SE, searchResults[4].Direction);
|
Assert.Equal(Direction.SE, searchResults[4].Direction);
|
||||||
Assert.Equal(Direction.W, searchResults[5].Direction);
|
Assert.Equal(Direction.W, searchResults[5].Direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TextParser_TestReadingChars()
|
||||||
|
{
|
||||||
|
var schemaBuilder = new InputSchemaBuilder();
|
||||||
|
var schema = schemaBuilder
|
||||||
|
.Repeat()
|
||||||
|
.Expect(InputType.Char)
|
||||||
|
.EndRepetition()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var parser = new TextParser<InputSchemaContext>(schema);
|
||||||
|
var row = parser
|
||||||
|
.SetInputText(testInput10)
|
||||||
|
.Parse()
|
||||||
|
.AsListRows<string>();
|
||||||
|
|
||||||
|
Assert.Equal(3, row.Count);
|
||||||
|
Assert.Equal("a", row[0][0]);
|
||||||
|
Assert.Equal(3, row[0].Count);
|
||||||
|
Assert.Equal(3, row[1].Count);
|
||||||
|
Assert.Equal(3, row[2].Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TextParser_TestFilter()
|
||||||
|
{
|
||||||
|
var schemaBuilder = new InputSchemaBuilder();
|
||||||
|
var schema = schemaBuilder
|
||||||
|
.Repeat()
|
||||||
|
.Expect(InputType.Integer)
|
||||||
|
.Expect(InputType.Char)
|
||||||
|
.Expect(InputType.Char)
|
||||||
|
.EndRepetition()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var parser = new TextParser<InputSchemaContext>(schema);
|
||||||
|
var numbers = parser
|
||||||
|
.SetInputText(testInput11)
|
||||||
|
.Parse()
|
||||||
|
.Filter(InputType.Integer)
|
||||||
|
.AsSingleStream<int>();
|
||||||
|
|
||||||
|
Assert.Equal(5, numbers.Count);
|
||||||
|
Assert.Equal(2, numbers[0]);
|
||||||
|
Assert.Equal(4, numbers[1]);
|
||||||
|
Assert.Equal(6, numbers[2]);
|
||||||
|
Assert.Equal(4, numbers[3]);
|
||||||
|
Assert.Equal(1, numbers[4]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,4 +20,24 @@ public static class DataManipulationHelpers
|
|||||||
{
|
{
|
||||||
return reducer(data);
|
return reducer(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<TNewType> TransformData<TType, TNewType>(this List<TType> data, Func<TType, TNewType> transformer)
|
||||||
|
{
|
||||||
|
var newList = new List<TNewType>();
|
||||||
|
foreach (TType dataItem in data)
|
||||||
|
{
|
||||||
|
newList.Add(transformer(dataItem));
|
||||||
|
}
|
||||||
|
return newList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<TNewType> TransformData<TType, TNewType>(this List<List<TType>> data, Func<List<TType>, TNewType> transformer)
|
||||||
|
{
|
||||||
|
var newList = new List<TNewType>();
|
||||||
|
foreach (List<TType> dataItemList in data)
|
||||||
|
{
|
||||||
|
newList.Add(transformer(dataItemList));
|
||||||
|
}
|
||||||
|
return newList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,22 @@ namespace Parsing.Data;
|
|||||||
|
|
||||||
public class SearchResult<TIndexType>
|
public class SearchResult<TIndexType>
|
||||||
{
|
{
|
||||||
|
public SearchResult(IDataIndex<TIndexType> dataIndex)
|
||||||
|
{
|
||||||
|
this.DataIndex = dataIndex;
|
||||||
|
}
|
||||||
|
|
||||||
public IDataIndex<TIndexType>? DataIndex { get; set; }
|
public IDataIndex<TIndexType>? DataIndex { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DirectionalSearchResult<TIndexType> : SearchResult<TIndexType>
|
public class DirectionalSearchResult<TIndexType> : SearchResult<TIndexType>
|
||||||
{
|
{
|
||||||
|
public DirectionalSearchResult(IDataIndex<TIndexType> dataIndex, Direction direction, int length): base(dataIndex)
|
||||||
|
{
|
||||||
|
this.Direction = direction;
|
||||||
|
this.Length = length;
|
||||||
|
}
|
||||||
|
|
||||||
public Direction Direction { get; set; }
|
public Direction Direction { get; set; }
|
||||||
public int Length { get; set; }
|
public int Length { get; set; }
|
||||||
}
|
}
|
||||||
@@ -111,10 +122,7 @@ public abstract class DataSetManipulatorBase<TCollectedType, TDataType, TIndexTy
|
|||||||
}
|
}
|
||||||
if (searchIndex == data.Count)
|
if (searchIndex == data.Count)
|
||||||
{
|
{
|
||||||
var result = new DirectionalSearchResult<TIndexType>();
|
var result = new DirectionalSearchResult<TIndexType>(currentPosition, direction, searchIndex);
|
||||||
result.DataIndex = currentPosition;
|
|
||||||
result.Direction = direction;
|
|
||||||
result.Length = searchIndex;
|
|
||||||
results.Add(result);
|
results.Add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +131,7 @@ public abstract class DataSetManipulatorBase<TCollectedType, TDataType, TIndexTy
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DirectionalSearchResult<TIndexType>> FindInSet(List<TDataType> data)
|
public List<DirectionalSearchResult<TIndexType>> FindInSet(List<TDataType> data, Direction directions)
|
||||||
{
|
{
|
||||||
var result = new List<DirectionalSearchResult<TIndexType>>();
|
var result = new List<DirectionalSearchResult<TIndexType>>();
|
||||||
|
|
||||||
@@ -131,11 +139,16 @@ public abstract class DataSetManipulatorBase<TCollectedType, TDataType, TIndexTy
|
|||||||
var startingPoints = this.FindInSet(data[0]);
|
var startingPoints = this.FindInSet(data[0]);
|
||||||
foreach (var startingPoint in startingPoints)
|
foreach (var startingPoint in startingPoints)
|
||||||
{
|
{
|
||||||
foreach (var results in this.FindAtPosition(startingPoint.DataIndex, data))
|
foreach (var results in this.FindAtPosition(startingPoint.DataIndex, data, directions))
|
||||||
{
|
{
|
||||||
result.AddRange(results);
|
result.AddRange(results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DirectionalSearchResult<TIndexType>> FindInSet(List<TDataType> data)
|
||||||
|
{
|
||||||
|
return this.FindInSet(data, this.ValidDirections());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -49,8 +49,7 @@ public class DefaultOneDimensionalManipulator<TDataType> : DataSetManipulatorBas
|
|||||||
{
|
{
|
||||||
if (EqualityComparer<TDataType>.Default.Equals(this.dataSet[i], data))
|
if (EqualityComparer<TDataType>.Default.Equals(this.dataSet[i], data))
|
||||||
{
|
{
|
||||||
var singleResult = new SearchResult<int>();
|
var singleResult = new SearchResult<int>(new DefaultPositionalDataIndex(i));
|
||||||
singleResult.DataIndex = new DefaultPositionalDataIndex(i);
|
|
||||||
results.Add(singleResult);
|
results.Add(singleResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ public class DefaultTwoDimensionalManipulator<TDataType> : DataSetManipulatorBas
|
|||||||
{
|
{
|
||||||
if (EqualityComparer<TDataType>.Default.Equals(this.dataSet[this.dataSet.Count - y - 1][x], data))
|
if (EqualityComparer<TDataType>.Default.Equals(this.dataSet[this.dataSet.Count - y - 1][x], data))
|
||||||
{
|
{
|
||||||
var singleResult = new SearchResult<int>();
|
var singleResult = new SearchResult<int>(new DefaultPositionalDataIndex(x, y));
|
||||||
singleResult.DataIndex = new DefaultPositionalDataIndex(x, y);
|
|
||||||
results.Add(singleResult);
|
results.Add(singleResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class TokenConverter
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<T> AsGenericCollection<T, U>() where T : ICollection<U>, new()
|
private List<T> AsGenericCollection<T, U>() where T : List<U>, new()
|
||||||
{
|
{
|
||||||
List<T> returnData = new List<T>();
|
List<T> returnData = new List<T>();
|
||||||
foreach (var tokenRow in this.rawTokens)
|
foreach (var tokenRow in this.rawTokens)
|
||||||
@@ -25,11 +25,15 @@ public class TokenConverter
|
|||||||
{
|
{
|
||||||
throw new Exception("No token was provided, but token was expected!");
|
throw new Exception("No token was provided, but token was expected!");
|
||||||
}
|
}
|
||||||
IValueToken<U>? valueToken = token as IValueToken<U>;
|
|
||||||
if (valueToken == null)
|
if (!token.GetType().IsAssignableTo(typeof(IValueToken<U>)))
|
||||||
{
|
{
|
||||||
throw new Exception("Provided token is not a ValueToken");
|
Console.WriteLine(token.GetText());
|
||||||
|
Type t = token.GetType();
|
||||||
|
throw new Exception("Provided token is not a ValueToken - type: " + t.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IValueToken<U> valueToken = token as IValueToken<U>;
|
||||||
newRow.Add(valueToken.GetValue());
|
newRow.Add(valueToken.GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,4 +160,26 @@ public class TokenConverter
|
|||||||
|
|
||||||
return newList;
|
return newList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TokenConverter Filter(params InputType[] inputTypes)
|
||||||
|
{
|
||||||
|
var newTokenListList = new List<List<IToken>>();
|
||||||
|
|
||||||
|
foreach(var tokenList in this.rawTokens)
|
||||||
|
{
|
||||||
|
var newTokenList = new List<IToken>();
|
||||||
|
foreach(var token in tokenList)
|
||||||
|
{
|
||||||
|
if(inputTypes.Contains(token.GetInputType()))
|
||||||
|
{
|
||||||
|
newTokenList.Add(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newTokenListList.Add(newTokenList);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rawTokens = newTokenListList;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,13 @@
|
|||||||
public enum BlockType
|
public enum BlockType
|
||||||
{
|
{
|
||||||
Integer = 1,
|
Integer = 1,
|
||||||
String = 2,
|
Char = 2,
|
||||||
|
String = 4,
|
||||||
// technically not a block type but keeping it here for consistency/having all types in one place
|
// technically not a block type but keeping it here for consistency/having all types in one place
|
||||||
Fragment = 4,
|
Fragment = 8,
|
||||||
FixedRepetition = 8,
|
FixedRepetition = 16,
|
||||||
GreedyRepetition = 16,
|
GreedyRepetition = 32,
|
||||||
NonZeroRepetition = 32,
|
NonZeroRepetition = 64,
|
||||||
|
Custom = 128,
|
||||||
|
Long = 256,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ abstract class BuildingBlockBase : IBuildingBlock
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract IToken ParseWord(InputProvider inputs);
|
public abstract List<IToken> ParseWord(InputProvider inputs);
|
||||||
|
|
||||||
public abstract bool CanParseWord(InputProvider inputs);
|
public abstract bool CanParseWord(InputProvider inputs);
|
||||||
|
|
||||||
|
|||||||
49
TextParser/Schema/BuildingBlocks/CharBlock.cs
Normal file
49
TextParser/Schema/BuildingBlocks/CharBlock.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
namespace Parsing.Schema.BuildingBlocks;
|
||||||
|
|
||||||
|
using Parsing.Tokenization;
|
||||||
|
|
||||||
|
class CharBlock : BuildingBlockBase
|
||||||
|
{
|
||||||
|
|
||||||
|
public CharBlock()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<IToken> ParseWord(InputProvider inputs)
|
||||||
|
{
|
||||||
|
var tokenList = new List<IToken>();
|
||||||
|
foreach (char c in inputs.YieldWord())
|
||||||
|
{
|
||||||
|
tokenList.Add(new StringToken(c.ToString()));
|
||||||
|
}
|
||||||
|
return tokenList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanParseWord(InputProvider inputs)
|
||||||
|
{
|
||||||
|
string word = string.Empty;
|
||||||
|
using (inputs.GetLookaheadContext())
|
||||||
|
{
|
||||||
|
word = inputs.YieldWord();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.CanParseWord(word);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanParseWord(string word)
|
||||||
|
{
|
||||||
|
// Here we need to ensure we are not matching any non-string tokens, since string can match pretty much anything
|
||||||
|
IntegerBlock intBlock = new IntegerBlock();
|
||||||
|
if (intBlock.CanParseWord(word))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override BlockType GetBlockType()
|
||||||
|
{
|
||||||
|
return BlockType.String;
|
||||||
|
}
|
||||||
|
}
|
||||||
42
TextParser/Schema/BuildingBlocks/CustomInputBlock.cs
Normal file
42
TextParser/Schema/BuildingBlocks/CustomInputBlock.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
namespace Parsing.Schema.BuildingBlocks;
|
||||||
|
|
||||||
|
using Parsing.Tokenization;
|
||||||
|
|
||||||
|
class CustomInputBlock<T> : BuildingBlockBase
|
||||||
|
{
|
||||||
|
|
||||||
|
private InputType definedInputType;
|
||||||
|
private Func<string, T> wordConverter;
|
||||||
|
|
||||||
|
public CustomInputBlock(InputType definedInputType, Func<string, T> wordConverter)
|
||||||
|
{
|
||||||
|
this.definedInputType = definedInputType;
|
||||||
|
this.wordConverter = wordConverter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<IToken> ParseWord(InputProvider inputs)
|
||||||
|
{
|
||||||
|
return new List<IToken>() { new CustomToken<T>(inputs.YieldWord(), this.definedInputType, this.wordConverter) };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanParseWord(InputProvider inputs)
|
||||||
|
{
|
||||||
|
string word = string.Empty;
|
||||||
|
using (inputs.GetLookaheadContext())
|
||||||
|
{
|
||||||
|
word = inputs.YieldWord();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.CanParseWord(word);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanParseWord(string word)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override BlockType GetBlockType()
|
||||||
|
{
|
||||||
|
return BlockType.Custom;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ class FixedRepetitionBlock : BuildingBlockBase
|
|||||||
this.context = this.inputSchema.CreateContext();
|
this.context = this.inputSchema.CreateContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IToken ParseWord(InputProvider inputs)
|
public override List<IToken> ParseWord(InputProvider inputs)
|
||||||
{
|
{
|
||||||
var result = inputSchema.ProcessNextWord(context, inputs);
|
var result = inputSchema.ProcessNextWord(context, inputs);
|
||||||
if (context.HasFinished)
|
if (context.HasFinished)
|
||||||
@@ -31,7 +31,7 @@ class FixedRepetitionBlock : BuildingBlockBase
|
|||||||
this.context = this.inputSchema.CreateContext();
|
this.context = this.inputSchema.CreateContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.Single();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanParseWord(InputProvider inputs)
|
public override bool CanParseWord(InputProvider inputs)
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ class GreedyRepetitionBlock : BuildingBlockBase
|
|||||||
this.context = this.inputSchema.CreateContext();
|
this.context = this.inputSchema.CreateContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IToken ParseWord(InputProvider inputs)
|
public override List<IToken> ParseWord(InputProvider inputs)
|
||||||
{
|
{
|
||||||
var result = inputSchema.ProcessNextWord(context, inputs);
|
var result = inputSchema.ProcessNextWord(context, inputs);
|
||||||
if (!this.CanParseWord(inputs))
|
if (!this.CanParseWord(inputs))
|
||||||
{
|
{
|
||||||
this.context = this.inputSchema.CreateContext();
|
this.context = this.inputSchema.CreateContext();
|
||||||
}
|
}
|
||||||
return result.Single();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanParseWord(InputProvider inputs)
|
public override bool CanParseWord(InputProvider inputs)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using Parsing.Tokenization;
|
|||||||
|
|
||||||
public interface IBuildingBlock
|
public interface IBuildingBlock
|
||||||
{
|
{
|
||||||
public IToken ParseWord(InputProvider inputs);
|
public List<IToken> ParseWord(InputProvider inputs);
|
||||||
|
|
||||||
public bool CanParseWord(InputProvider inputs);
|
public bool CanParseWord(InputProvider inputs);
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ class IntegerBlock : BuildingBlockBase
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IToken ParseWord(InputProvider inputs)
|
public override List<IToken> ParseWord(InputProvider inputs)
|
||||||
{
|
{
|
||||||
return new IntegerToken(inputs.YieldWord());
|
return new List<IToken>() { new IntegerToken(inputs.YieldWord()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanParseWord(InputProvider inputs)
|
public override bool CanParseWord(InputProvider inputs)
|
||||||
|
|||||||
35
TextParser/Schema/BuildingBlocks/LongBlock.cs
Normal file
35
TextParser/Schema/BuildingBlocks/LongBlock.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
namespace Parsing.Schema.BuildingBlocks;
|
||||||
|
|
||||||
|
using Parsing.Tokenization;
|
||||||
|
|
||||||
|
class LongBlock : BuildingBlockBase
|
||||||
|
{
|
||||||
|
|
||||||
|
public LongBlock()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<IToken> ParseWord(InputProvider inputs)
|
||||||
|
{
|
||||||
|
return new List<IToken>() { new LongToken(inputs.YieldWord()) };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanParseWord(InputProvider inputs)
|
||||||
|
{
|
||||||
|
using (inputs.GetLookaheadContext())
|
||||||
|
{
|
||||||
|
return this.CanParseWord(inputs.YieldWord());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanParseWord(string word)
|
||||||
|
{
|
||||||
|
long number = 0;
|
||||||
|
return long.TryParse(word, out number);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override BlockType GetBlockType()
|
||||||
|
{
|
||||||
|
return BlockType.Long;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,9 @@ class StringBlock : BuildingBlockBase
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IToken ParseWord(InputProvider inputs)
|
public override List<IToken> ParseWord(InputProvider inputs)
|
||||||
{
|
{
|
||||||
return new StringToken(inputs.YieldWord());
|
return new List<IToken>() { new StringToken(inputs.YieldWord()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanParseWord(InputProvider inputs)
|
public override bool CanParseWord(InputProvider inputs)
|
||||||
@@ -28,6 +28,12 @@ class StringBlock : BuildingBlockBase
|
|||||||
public override bool CanParseWord(string word)
|
public override bool CanParseWord(string word)
|
||||||
{
|
{
|
||||||
// Here we need to ensure we are not matching any non-string tokens, since string can match pretty much anything
|
// Here we need to ensure we are not matching any non-string tokens, since string can match pretty much anything
|
||||||
|
LongBlock longBlock = new LongBlock();
|
||||||
|
if (longBlock.CanParseWord(word))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
IntegerBlock intBlock = new IntegerBlock();
|
IntegerBlock intBlock = new IntegerBlock();
|
||||||
if (intBlock.CanParseWord(word))
|
if (intBlock.CanParseWord(word))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,15 +28,13 @@ public class InputSchema : ISchema<InputSchemaContext>
|
|||||||
public List<IToken> ProcessNextWord(InputSchemaContext currentContext, InputProvider inputs)
|
public List<IToken> ProcessNextWord(InputSchemaContext currentContext, InputProvider inputs)
|
||||||
{
|
{
|
||||||
var nextBlock = this.buildingBlocks[currentContext.lastProcessedBlockIndex];
|
var nextBlock = this.buildingBlocks[currentContext.lastProcessedBlockIndex];
|
||||||
var token = nextBlock.ParseWord(inputs);
|
var tokens = nextBlock.ParseWord(inputs);
|
||||||
if (!nextBlock.IsRepetitionType() || nextBlock.CheckIsDoneParsingAndReset(inputs))
|
if (!nextBlock.IsRepetitionType() || nextBlock.CheckIsDoneParsingAndReset(inputs))
|
||||||
{
|
{
|
||||||
currentContext.lastProcessedBlockIndex++;
|
currentContext.lastProcessedBlockIndex++;
|
||||||
currentContext.HasFinished = currentContext.lastProcessedBlockIndex >= this.buildingBlocks.Count;
|
currentContext.HasFinished = currentContext.lastProcessedBlockIndex >= this.buildingBlocks.Count;
|
||||||
}
|
}
|
||||||
var newTokenList = new List<IToken>();
|
return tokens;
|
||||||
newTokenList.Add(token);
|
|
||||||
return newTokenList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanProcessNextWord(InputSchemaContext currentContext, InputProvider inputs)
|
public bool CanProcessNextWord(InputSchemaContext currentContext, InputProvider inputs)
|
||||||
|
|||||||
@@ -21,6 +21,27 @@ public class InputSchemaBuilder : RepetitionSchemaBuilder<InputSchemaBuilder, In
|
|||||||
case InputType.Integer:
|
case InputType.Integer:
|
||||||
block = new IntegerBlock();
|
block = new IntegerBlock();
|
||||||
break;
|
break;
|
||||||
|
case InputType.Long:
|
||||||
|
block = new LongBlock();
|
||||||
|
break;
|
||||||
|
case InputType.Char:
|
||||||
|
block = new CharBlock();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Unrecognized InputType");
|
||||||
|
}
|
||||||
|
schema.AddBuildingBlock(block);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputSchemaBuilder Expect<T>(InputType type, InputType definedInputType, Func<string, T> wordConverter)
|
||||||
|
{
|
||||||
|
IBuildingBlock block;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case InputType.Custom:
|
||||||
|
block = new CustomInputBlock<T>(definedInputType, wordConverter);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception("Unrecognized InputType");
|
throw new Exception("Unrecognized InputType");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,7 @@ public enum InputType
|
|||||||
Integer = BlockType.Integer,
|
Integer = BlockType.Integer,
|
||||||
String = BlockType.String,
|
String = BlockType.String,
|
||||||
Fragment = BlockType.Fragment,
|
Fragment = BlockType.Fragment,
|
||||||
|
Char = BlockType.Char,
|
||||||
|
Custom = BlockType.Custom,
|
||||||
|
Long = BlockType.Long,
|
||||||
}
|
}
|
||||||
|
|||||||
34
TextParser/Tokenization/CustomToken.cs
Normal file
34
TextParser/Tokenization/CustomToken.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
namespace Parsing.Tokenization;
|
||||||
|
|
||||||
|
using Parsing.Schema;
|
||||||
|
|
||||||
|
public class CustomToken<T> : IValueToken<T>
|
||||||
|
{
|
||||||
|
private string word;
|
||||||
|
|
||||||
|
private InputType definedInputType;
|
||||||
|
|
||||||
|
private Func<string, T> wordConverter;
|
||||||
|
|
||||||
|
public CustomToken(string word, InputType definedInputType, Func<string, T> wordConverter)
|
||||||
|
{
|
||||||
|
this.word = word;
|
||||||
|
this.wordConverter = wordConverter;
|
||||||
|
this.definedInputType = definedInputType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetText()
|
||||||
|
{
|
||||||
|
return word;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetValue()
|
||||||
|
{
|
||||||
|
return wordConverter(word);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputType GetInputType()
|
||||||
|
{
|
||||||
|
return this.definedInputType;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
TextParser/Tokenization/LongToken.cs
Normal file
28
TextParser/Tokenization/LongToken.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
namespace Parsing.Tokenization;
|
||||||
|
|
||||||
|
using Parsing.Schema;
|
||||||
|
|
||||||
|
public class LongToken : IValueToken<long>
|
||||||
|
{
|
||||||
|
private string word;
|
||||||
|
|
||||||
|
public LongToken(string word)
|
||||||
|
{
|
||||||
|
this.word = word;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetText()
|
||||||
|
{
|
||||||
|
return word;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long GetValue()
|
||||||
|
{
|
||||||
|
return long.Parse(word);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputType GetInputType()
|
||||||
|
{
|
||||||
|
return InputType.Long;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
0.7.0
|
0.11.8
|
||||||
|
|||||||
@@ -8,4 +8,8 @@
|
|||||||
<add key="gitea-homelab" value="https://git.disi.dev/api/packages/Homelab/nuget/index.json" />
|
<add key="gitea-homelab" value="https://git.disi.dev/api/packages/Homelab/nuget/index.json" />
|
||||||
<add key="gitea-artifacts" value="https://git.disi.dev/api/packages/Artifacts/nuget/index.json" />
|
<add key="gitea-artifacts" value="https://git.disi.dev/api/packages/Artifacts/nuget/index.json" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
|
|
||||||
|
<config>
|
||||||
|
<add key="DefaultPushSource" value="https://git.disi.dev/api/packages/Projects/nuget/index.json" />
|
||||||
|
</config>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
Reference in New Issue
Block a user