add: DelimiterSemanticToken and tests

This commit is contained in:
2024-03-09 21:44:37 +08:00
parent f6a4ad4a44
commit e92b02a208
7 changed files with 104 additions and 12 deletions

View File

@@ -33,19 +33,32 @@ public class DelimiterSemanticToken : SemanticToken
public static bool TryParse(uint linePos, uint characterPos, LinkedListNode<char> now,
out DelimiterSemanticToken? token)
{
switch (now.Value)
Dictionary<char, DelimiterType> delimiterMap = new()
{
case ',':
token = new DelimiterSemanticToken
{
LinePos = linePos, CharacterPos = characterPos,
LiteralValue = ",", DelimiterType = DelimiterType.Comma
};
return true;
default:
token = null;
return false;
{ ',', DelimiterType.Comma },
{ '.', DelimiterType.Period },
{ ':', DelimiterType.Colon },
{ ';', DelimiterType.Semicolon },
{ '(', DelimiterType.LeftParenthesis },
{ ')', DelimiterType.RightParenthesis },
{ '[', DelimiterType.LeftSquareBracket },
{ ']', DelimiterType.RightSquareBracket }
};
if (!delimiterMap.TryGetValue(now.Value, out DelimiterType value))
{
token = null;
return false;
}
token = new DelimiterSemanticToken
{
LinePos = linePos,
CharacterPos = characterPos,
LiteralValue = new string([now.Value]),
DelimiterType = value
};
return true;
}
}