42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
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;
|
|
}
|
|
} |