Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SourceLocation.cs
Go to the documentation of this file.
1 #region License
2 /* **********************************************************************************
3  * Copyright (c) Roman Ivantsov
4  * This source code is subject to terms and conditions of the MIT License
5  * for Irony. A copy of the license can be found in the License.txt file
6  * at the root of this distribution.
7  * By using this source code in any fashion, you are agreeing to be bound by the terms of the
8  * MIT License.
9  * You must not remove this notice from this software.
10  * **********************************************************************************/
11 #endregion
12 
13 using System;
14 using System.Collections.Generic;
15 using System.Linq;
16 using System.Text;
17 
18 namespace Irony.Parsing {
19 
20  public struct SourceLocation
21  {
22  public string SourceFilename;
23  public int Position;
24  public int Line;
25  public int Column;
26  public SourceLocation(int position, int line, int column, string sourceFilename = null)
27  {
28  SourceFilename = sourceFilename;
29  Position = position;
30  Line = line;
31  Column = column;
32  }
33  //Line/col are zero-based internally
34  public override string ToString()
35  {
36  return string.Format(Resources.FmtRowCol, SourceFilename == null ? "" : SourceFilename + " ", Line, Column);
37  }
38  //Line and Column displayed to user should be 1-based
39  public string ToUiString()
40  {
41  return string.Format(Resources.FmtRowCol, SourceFilename == null ? "" : SourceFilename + " ", Line + 1, Column + 1);
42  }
43  public static int Compare(SourceLocation x, SourceLocation y)
44  {
45  if (x.Position < y.Position) return -1;
46  if (x.Position == y.Position) return 0;
47  return 1;
48  }
49  public static SourceLocation Empty
50  {
51  get { return _empty; }
52  } static SourceLocation _empty = new SourceLocation();
53 
54  public static SourceLocation operator +(SourceLocation x, SourceLocation y)
55  {
56  return new SourceLocation(x.Position + y.Position, x.Line + y.Line, x.Column + y.Column);
57  }
58  public static SourceLocation operator +(SourceLocation x, int offset)
59  {
60  return new SourceLocation(x.Position + offset, x.Line, x.Column + offset);
61  }
62  }//SourceLocation
63 
64  public struct SourceSpan {
65  public readonly SourceLocation Location;
66  public readonly int Length;
67  public SourceSpan(SourceLocation location, int length) {
68  Location = location;
69  Length = length;
70  }
71  public int EndPosition {
72  get { return Location.Position + Length; }
73  }
74  }
75 
76 
77 }//namespace
override string ToString()
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
SourceSpan(SourceLocation location, int length)
static int Compare(SourceLocation x, SourceLocation y)
static string FmtRowCol
Looks up a localized string similar to {0}({1}:{2}).
readonly SourceLocation Location
SourceLocation(int position, int line, int column, string sourceFilename=null)