-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.cs
More file actions
47 lines (43 loc) · 1.46 KB
/
Token.cs
File metadata and controls
47 lines (43 loc) · 1.46 KB
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
namespace GameDialog.Lang
{
/// <summary>
/// Represents a single token in the source code.
/// </summary>
internal record Token(TokenType Type, string Value, Location Location)
{
/// <summary>
/// Determines whether the token represents the end of the source.
/// </summary>
public bool IsEndOfSource() => Type is TokenType.EndOfSource;
/// <summary>
/// Creates an empty token representing the end of the source.
/// </summary>
public static Token Empty()
{
return new Token(TokenType.EndOfSource, string.Empty, new Location(Source.Empty(), 0, 0));
}
/// <summary>
/// Creates an indent token.
/// </summary>
/// <param name="location">Location of the indent token.</param>
public static Token Indent(Location location)
{
return new Token(TokenType.Indent, string.Empty, location);
}
/// <summary>
/// Creates a dedent token.
/// </summary>
/// <param name="location">Location of the dedent token.</param>
public static Token Dedent(Location location)
{
return new Token(TokenType.Dedent, string.Empty, location);
}
/// <summary>
/// Returns a string representation of the token.
/// </summary>
public override string ToString()
{
return $"{Type}({Value}) at {Location}";
}
}
}