forked from dotnet/command-line-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.cs
More file actions
63 lines (51 loc) · 2.01 KB
/
Token.cs
File metadata and controls
63 lines (51 loc) · 2.01 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace System.CommandLine.Parsing
{
/// <summary>
/// A unit of significant text on the command line.
/// </summary>
public sealed class Token : IEquatable<Token>
{
internal const int ImplicitPosition = -1;
/// <param name="value">The string value of the token.</param>
/// <param name="type">The type of the token.</param>
/// <param name="symbol">The symbol represented by the token</param>
public Token(string? value, TokenType type, Symbol symbol)
{
Value = value ?? "";
Type = type;
Symbol = symbol;
Position = ImplicitPosition;
}
internal Token(string? value, TokenType type, Symbol? symbol, int position)
{
Value = value ?? "";
Type = type;
Symbol = symbol;
Position = position;
}
internal int Position { get; }
/// <summary>
/// The string value of the token.
/// </summary>
public string Value { get; }
internal bool IsImplicit => Position == ImplicitPosition;
/// <summary>
/// The type of the token.
/// </summary>
public TokenType Type { get; }
/// <summary>
/// The Symbol represented by the token (if any).
/// </summary>
public Symbol? Symbol { get; internal set; }
/// <inheritdoc />
public override bool Equals(object? obj) => Equals(obj as Token);
/// <inheritdoc />
public bool Equals(Token? other) => other is not null && Value == other.Value && Type == other.Type && ReferenceEquals(Symbol, other.Symbol);
/// <inheritdoc />
public override int GetHashCode() => Value.GetHashCode() ^ (int)Type;
/// <inheritdoc />
public override string ToString() => Value;
}
}