50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
namespace Parsing.Schema.BuildingBlocks;
|
|
|
|
using Parsing.Tokenization;
|
|
|
|
class StringBlock : BuildingBlockBase
|
|
{
|
|
|
|
public StringBlock()
|
|
{
|
|
}
|
|
|
|
public override List<IToken> ParseWord(InputProvider inputs)
|
|
{
|
|
return new List<IToken>() { new StringToken(inputs.YieldWord()) };
|
|
}
|
|
|
|
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
|
|
LongBlock longBlock = new LongBlock();
|
|
if (longBlock.CanParseWord(word))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
IntegerBlock intBlock = new IntegerBlock();
|
|
if (intBlock.CanParseWord(word))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override BlockType GetBlockType()
|
|
{
|
|
return BlockType.String;
|
|
}
|
|
} |