-
Notifications
You must be signed in to change notification settings - Fork 0
/
Token.cs
57 lines (47 loc) · 1.58 KB
/
Token.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using DevLab.JmesPath.Tokens;
using StarodubOleg.GPPG.Runtime;
namespace DevLab.JmesPath
{
internal class Token
{
public Token(TokenType type, string rawText)
{
Type = type;
RawText = rawText;
}
public TokenType Type { get; }
public string RawText { get; }
public virtual object Value => RawText;
public LexLocation Location { get; set; }
public static Token Create(TokenType tokenType, string yytext)
{
switch (tokenType)
{
case TokenType.error:
break;
case TokenType.EOF:
break;
case TokenType.T_NUMBER:
return new NumberToken(yytext);
case TokenType.T_LSTRING:
return new LiteralStringToken(yytext);
case TokenType.T_QSTRING:
return new QuotedStringToken(yytext);
case TokenType.T_RSTRING:
return new RawStringToken(yytext);
case TokenType.T_LBRACKET:
case TokenType.T_RBRACKET:
case TokenType.T_USTRING:
default:
return new Token(tokenType, yytext);
}
System.Diagnostics.Debug.Assert(false);
throw new NotSupportedException();
}
public override string ToString()
{
return $"{RawText} ({Type})";
}
}
}