-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathLocation.cs
57 lines (48 loc) · 2.43 KB
/
Location.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
// 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.
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using static System.Net.Mime.MediaTypeNames;
namespace System.CommandLine.Parsing
{
public record Location
{
public const string Implicit = "Implicit";
public const string Internal = "Internal";
public const string User = "User";
public const string Response = "Response";
internal static Location CreateRoot(string exeName, bool isImplicit, int start)
=> new(exeName, isImplicit ? Internal : User, start, null);
internal static Location CreateImplicit(string text, Location outerLocation, int offset = 0)
=> new(text, Implicit, -1, outerLocation, offset);
internal static Location CreateInternal(string text, Location? outerLocation = null, int offset = 0)
=> new(text, Internal, -1, outerLocation, offset);
internal static Location CreateUser(string text, int start, Location outerLocation, int offset = 0)
=> new(text, User, start, outerLocation, offset);
internal static Location CreateResponse(string responseSourceName, int start, Location outerLocation, int offset = 0)
=> new(responseSourceName, $"{Response}:{responseSourceName}", start, outerLocation, offset);
internal static Location FromOuterLocation(string text, int start, Location outerLocation, int offset = 0)
=> new(text, outerLocation.Source, start, outerLocation, offset);
public Location(string text, string source, int start, Location? outerLocation, int offset = 0)
{
Text = text;
Source = source;
Start = start;
Length = text.Length;
Offset = offset;
OuterLocation = outerLocation;
}
public string Text { get; }
public string Source { get; }
public int Start { get; }
public int Offset { get; }
public int Length { get; }
public Location? OuterLocation { get; }
public bool IsImplicit
=> Source == Implicit;
/// <inheritdoc/>
public override string ToString()
=> $"{(OuterLocation is null ? "" : OuterLocation.ToString() + "; ")}{Text} from {Source}[{Start}, {Length}, {Offset}]";
}
}