generated from Templates/Dotnet_Library
Compare commits
No commits in common. "main" and "0.9.3" have entirely different histories.
@ -4,21 +4,12 @@ Changelog
|
|||||||
|
|
||||||
(unreleased)
|
(unreleased)
|
||||||
------------
|
------------
|
||||||
- Feat: add support for custom token types and longs, ref: NOISSUE.
|
|
||||||
[Simon Diesenreiter]
|
|
||||||
|
|
||||||
|
|
||||||
0.9.3 (2024-12-13)
|
|
||||||
------------------
|
|
||||||
|
|
||||||
Fix
|
Fix
|
||||||
~~~
|
~~~
|
||||||
- Remove duplicate TokenConverter definition, ref: NOISSUE. [Simon
|
- Remove duplicate TokenConverter definition, ref: NOISSUE. [Simon
|
||||||
Diesenreiter]
|
Diesenreiter]
|
||||||
|
|
||||||
Other
|
|
||||||
~~~~~
|
|
||||||
|
|
||||||
|
|
||||||
0.9.2 (2024-12-13)
|
0.9.2 (2024-12-13)
|
||||||
------------------
|
------------------
|
||||||
|
@ -13,7 +13,7 @@ public class TokenConverter
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<T> AsGenericCollection<T, U>() where T : List<U>, new()
|
private List<T> AsGenericCollection<T, U>() where T : ICollection<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,15 +25,11 @@ 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 (!token.GetType().IsAssignableTo(typeof(IValueToken<U>)))
|
if (valueToken == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine(token.GetText());
|
throw new Exception("Provided token is not a ValueToken");
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +161,7 @@ public class TokenConverter
|
|||||||
{
|
{
|
||||||
var newTokenListList = new List<List<IToken>>();
|
var newTokenListList = new List<List<IToken>>();
|
||||||
|
|
||||||
foreach(var tokenList in this.rawTokens)
|
foreach(var tokenList in rawTokens)
|
||||||
{
|
{
|
||||||
var newTokenList = new List<IToken>();
|
var newTokenList = new List<IToken>();
|
||||||
foreach(var token in tokenList)
|
foreach(var token in tokenList)
|
||||||
|
@ -11,6 +11,4 @@ public enum BlockType
|
|||||||
FixedRepetition = 16,
|
FixedRepetition = 16,
|
||||||
GreedyRepetition = 32,
|
GreedyRepetition = 32,
|
||||||
NonZeroRepetition = 64,
|
NonZeroRepetition = 64,
|
||||||
Custom = 128,
|
|
||||||
Long = 256,
|
|
||||||
}
|
}
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -28,12 +28,6 @@ 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))
|
||||||
{
|
{
|
||||||
|
@ -21,9 +21,6 @@ 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:
|
case InputType.Char:
|
||||||
block = new CharBlock();
|
block = new CharBlock();
|
||||||
break;
|
break;
|
||||||
@ -34,21 +31,6 @@ public class InputSchemaBuilder : RepetitionSchemaBuilder<InputSchemaBuilder, In
|
|||||||
return this;
|
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:
|
|
||||||
throw new Exception("Unrecognized InputType");
|
|
||||||
}
|
|
||||||
schema.AddBuildingBlock(block);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputSchemaBuilder Repeat(int repetitionCount)
|
public InputSchemaBuilder Repeat(int repetitionCount)
|
||||||
{
|
{
|
||||||
// add another layer of parsing
|
// add another layer of parsing
|
||||||
|
@ -7,6 +7,4 @@ public enum InputType
|
|||||||
String = BlockType.String,
|
String = BlockType.String,
|
||||||
Fragment = BlockType.Fragment,
|
Fragment = BlockType.Fragment,
|
||||||
Char = BlockType.Char,
|
Char = BlockType.Char,
|
||||||
Custom = BlockType.Custom,
|
|
||||||
Long = BlockType.Long,
|
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
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.10.0
|
0.9.3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user