49 lines
1.1 KiB
C#
49 lines
1.1 KiB
C#
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;
|
|
}
|
|
} |