Mercury library 1.0 Translation of CFG grammars into an object model (Bachelor's thesis).

- Main Page
- Packages
- Classes
- Files

- File List

All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
Token.cs
Go to the documentation of this file.
1 using System;
2
3 namespace Mercury.Scanning
4 {
5
6 //==<< TokenType >>==========================================================
7
12 public enum TokenType
13 {
15 String,
17 Symbol,
19 Keyword,
21 Number
22 }
23
24 //=============================================================================
25 // Token
26 //=============================================================================
27
29 public class Token : IEquatable<Token>
30 {
31 //--[ Constructors ]-------------------------------------------------
32
38 public Token(string value, TokenType type, int position, bool quoted = false)
39 {
40 if (value == null) throw new ArgumentNullException("value");
41
42 Value = value;
43 Type = type;
44 Position = position;
45 Quoted = quoted;
46 }
47
48 //--[ Properties ]---------------------------------------------------
49
51 public string Value { get; private set; }
52
54 public TokenType Type { get; private set; }
55
57 public int Position { get; private set; }
58
60 public bool Quoted { get; private set; }
61
62 //--[ Overriden methods ]--------------------------------------------
63
64 #region [ Object ]
65
66 public override bool Equals(object obj)
67 {
68 Token other = obj as Token;
69 return other == null ? false : Equals(other);
70 }
71
72 public override int GetHashCode()
73 { return Value.GetHashCode(); }
74
75 public override string ToString()
76 { return string.Format(Quoted ? "{0}\t <{1}>\t [\"{2}\"]" : "{0}\t <{1}>\t [{2}]", Position, Type, Value); }
77
78 #endregion
79
80 //--[ Interface implementation ]-------------------------------------
81
82 #region [ IEquatable ]
83
84 public bool Equals(Token other)
85 {
86 return (other != null ) && (Type == other.Type )
87 && (Position == other.Position) && (Value == other.Value);
88 }
89
90 #endregion
91
92 }
93 }
Mercury.Scanning.Token.Position
int Position
Position in the input text.
Definition: Token.cs:57
Mercury.Scanning.Token.ToString
override string ToString()
Definition: Token.cs:75
Mercury.Scanning.Token
Token, a part of an input text recognized by tokenizer
Definition: Token.cs:29
Mercury.Scanning.Token.GetHashCode
override int GetHashCode()
Definition: Token.cs:72
Mercury.Scanning.Keyword
summary>Number.
Mercury.Scanning.Token.Token
Token(string value, TokenType type, int position, bool quoted=false)
Creates a new Token.
Definition: Token.cs:38
Mercury.Scanning.Number
Mercury.Scanning.Token.Equals
override bool Equals(object obj)
Definition: Token.cs:66
Mercury.Scanning.TokenType
TokenType
Defines token types. The actual conditions depend on the Mercury.Scanning.ITokenizer implementation...
Definition: Token.cs:12
Mercury.Scanning.Token.Equals
bool Equals(Token other)
Definition: Token.cs:84