NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Analyzer.Config.Compiler.Tokenizer Class Reference
Inheritance diagram for Ntp.Analyzer.Config.Compiler.Tokenizer:
Collaboration diagram for Ntp.Analyzer.Config.Compiler.Tokenizer:

Public Member Functions

 Tokenizer (string file)
 
void Consume ()
 Consume white spaces, line breaks and comments. More...
 
void ConsumeWhiteSpaces ()
 Consume white spaces and comments. More...
 
void Dispose ()
 
Token GetNext ()
 
Token PeekNext ()
 

Public Attributes

int ColumnNumber => reader.Position
 
int LineNumber => reader.Line
 

Properties

Token Token [get, private set]
 

Private Member Functions

 ~Tokenizer ()
 
void ConsumeComment ()
 
void Dispose (bool disposing)
 
Token GetNextToken ()
 
Token ParseLiteral ()
 
Token ParseQuotedIdent ()
 

Static Private Member Functions

static Token ParseBoolean (string text)
 
static Token ParseDigitValue (string text)
 

Private Attributes

bool disposedValue
 
readonly ConfigFileReader reader
 

Detailed Description

Definition at line 29 of file Tokenizer.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Config.Compiler.Tokenizer.Tokenizer ( string  file)
inline

Definition at line 31 of file Tokenizer.cs.

References Ntp.Analyzer.Config.Table.Token.Undefined.

32  {
33  reader = new ConfigFileReader(file);
35  }
readonly ConfigFileReader reader
Definition: Tokenizer.cs:37
Ntp.Analyzer.Config.Compiler.Tokenizer.~Tokenizer ( )
inlineprivate

Definition at line 300 of file Tokenizer.cs.

301  {
302  Dispose(false);
303  }

Member Function Documentation

void Ntp.Analyzer.Config.Compiler.Tokenizer.Consume ( )
inline

Consume white spaces, line breaks and comments.

Definition at line 48 of file Tokenizer.cs.

References c, Ntp.Analyzer.Config.Table.Token.NewLine, and Ntp.Analyzer.Config.Table.Token.Whitespace.

49  {
50  bool pass = true;
51  do
52  {
53  char c = reader.Peek();
54  switch (c)
55  {
56  case ' ':
57  case '\t':
58  reader.Read();
60  break;
61  case '#':
63  break;
64  case '\n':
65  reader.Read();
66  reader.NextLine();
68  break;
69  case '\r':
70  reader.Read();
71  if (reader.Peek() == '\n')
72  reader.Read();
73 
74  reader.NextLine();
76  break;
77  default:
78  pass = false;
79  break;
80  }
81  } while (pass);
82  }
readonly ConfigFileReader reader
Definition: Tokenizer.cs:37
char Read()
Consumes one character from file.
var c
Definition: bootstrap.min.js:6
void Ntp.Analyzer.Config.Compiler.Tokenizer.ConsumeComment ( )
inlineprivate

Definition at line 123 of file Tokenizer.cs.

References Ntp.Analyzer.Config.Table.Token.NewLine.

124  {
125  if (reader.Peek() != '#')
126  return;
127 
128  reader.Read();
129  while (reader.Peek() != '\r' && reader.Peek() != '\n' && reader.Peek() != '\0')
130  reader.Read();
131 
132  switch (reader.Peek())
133  {
134  case '\n':
135  reader.Read();
136  reader.NextLine();
137  Token = Token.NewLine;
138  return;
139  case '\r':
140  reader.Read();
141  if (reader.Peek() == '\n')
142  reader.Read();
143 
144  reader.NextLine();
145  Token = Token.NewLine;
146  break;
147  }
148  }
readonly ConfigFileReader reader
Definition: Tokenizer.cs:37
char Read()
Consumes one character from file.
void Ntp.Analyzer.Config.Compiler.Tokenizer.ConsumeWhiteSpaces ( )
inline

Consume white spaces and comments.

Definition at line 87 of file Tokenizer.cs.

References Ntp.Analyzer.Config.Table.Token.Whitespace.

88  {
89  while (reader.Peek() == ' ' || reader.Peek() == '\t')
90  {
92  if (reader.Peek() == '#')
94  else
95  reader.Read();
96  }
97  }
readonly ConfigFileReader reader
Definition: Tokenizer.cs:37
char Read()
Consumes one character from file.
void Ntp.Analyzer.Config.Compiler.Tokenizer.Dispose ( bool  disposing)
inlineprivate

Definition at line 287 of file Tokenizer.cs.

288  {
289  if (disposedValue)
290  return;
291 
292  if (disposing)
293  {
294  reader.Dispose();
295  }
296 
297  disposedValue = true;
298  }
readonly ConfigFileReader reader
Definition: Tokenizer.cs:37
void Ntp.Analyzer.Config.Compiler.Tokenizer.Dispose ( )
inline

Definition at line 305 of file Tokenizer.cs.

306  {
307  Dispose(true);
308  GC.SuppressFinalize(this);
309  }
Token Ntp.Analyzer.Config.Compiler.Tokenizer.GetNext ( )
inline

Definition at line 99 of file Tokenizer.cs.

Token Ntp.Analyzer.Config.Compiler.Tokenizer.GetNextToken ( )
inlineprivate

Definition at line 150 of file Tokenizer.cs.

References c, Ntp.Analyzer.Config.Table.Token.NewLine, and Ntp.Analyzer.Config.Table.Token.Whitespace.

151  {
152  while (reader.Peek() != '\0')
153  {
154  switch (reader.Peek())
155  {
156  case '\n':
157  reader.Read();
158  reader.NextLine();
159  return Token.NewLine;
160  case '\r':
161  reader.Read();
162  if (reader.Peek() == '\n')
163  reader.Read();
164 
165  reader.NextLine();
166  return Token.NewLine;
167  }
168 
169  while (char.IsWhiteSpace(reader.Peek()))
170  {
171  reader.Read();
172  return Token.Whitespace;
173  }
174 
175  if (reader.Peek() == '\0')
176  {
177  return new SymbolToken(Symbol.EndOfFile);
178  }
179 
180  var c = reader.Peek();
181  switch (c)
182  {
183  case '{':
184  reader.Read();
185  return new SymbolToken(Symbol.OpeningBrace);
186  case '}':
187  reader.Read();
188  return new SymbolToken(Symbol.ClosingBrace);
189  }
190 
191  var token = ParseQuotedIdent() ?? ParseLiteral();
192  return token;
193  }
194 
195  return new SymbolToken(Symbol.EndOfFile);
196  }
readonly ConfigFileReader reader
Definition: Tokenizer.cs:37
char Read()
Consumes one character from file.
var c
Definition: bootstrap.min.js:6
static Token Ntp.Analyzer.Config.Compiler.Tokenizer.ParseBoolean ( string  text)
inlinestaticprivate

Definition at line 198 of file Tokenizer.cs.

199  {
200  switch (text.ToLower())
201  {
202  case "0":
203  return new SymbolToken(Symbol.Zero);
204  case "1":
205  return new SymbolToken(Symbol.One);
206  case "no":
207  case "off":
208  case "false":
209  return new SymbolToken(Symbol.BooleanFalse);
210  case "on":
211  case "yes":
212  case "true":
213  return new SymbolToken(Symbol.BooleanTrue);
214  default:
215  return null;
216  }
217  }
static Token Ntp.Analyzer.Config.Compiler.Tokenizer.ParseDigitValue ( string  text)
inlinestaticprivate

Definition at line 219 of file Tokenizer.cs.

References c.

220  {
221  int value;
222  if (int.TryParse(text, out value))
223  {
224  switch (value)
225  {
226  case 0:
227  return new SymbolToken(Symbol.Zero);
228  case 1:
229  return new SymbolToken(Symbol.One);
230  default:
231  return new IntegerToken(value);
232  }
233  }
234 
235  if (text.ToCharArray().Count(c => "0123456789.".Contains(c)) != text.Length)
236  return null;
237 
238  if (text.ToCharArray().Count(c => c == '.') > 1)
239  return null;
240 
241  double dvalue;
242  return double.TryParse(text, out dvalue) ? new NumericToken(dvalue) : null;
243  }
var c
Definition: bootstrap.min.js:6
Token Ntp.Analyzer.Config.Compiler.Tokenizer.ParseLiteral ( )
inlineprivate

Definition at line 245 of file Tokenizer.cs.

References Ntp.Analyzer.Config.Table.Keyword.Keywords.

246  {
247  var text = new StringBuilder();
248  while (!char.IsWhiteSpace(reader.Peek()) && reader.Peek() != '\r' && reader.Peek() != '\n' &&
249  reader.Peek() != '\0')
250  text.Append(reader.Read());
251 
252  string tokenText = text.ToString();
253 
254  var token = ParseBoolean(tokenText) ?? ParseDigitValue(tokenText);
255  if (token != null)
256  return token;
257 
258  string search = tokenText.ToLower();
259  var keyword = Keyword.Keywords.FirstOrDefault(k => k.LowerText == search);
260 
261  return keyword != null
262  ? new KeywordToken(keyword, tokenText)
263  : (Token) new LiteralToken(tokenText);
264  }
static Token ParseDigitValue(string text)
Definition: Tokenizer.cs:219
readonly ConfigFileReader reader
Definition: Tokenizer.cs:37
char Read()
Consumes one character from file.
static IEnumerable< Keyword > Keywords
Definition: Keyword.cs:47
static Token ParseBoolean(string text)
Definition: Tokenizer.cs:198
Token Ntp.Analyzer.Config.Compiler.Tokenizer.ParseQuotedIdent ( )
inlineprivate

Definition at line 266 of file Tokenizer.cs.

267  {
268  if (reader.Peek() != '"')
269  return null;
270 
271  reader.Read();
272 
273  var text = new StringBuilder();
274  while (reader.Peek() != '\0' && reader.Peek() != '"')
275  text.Append(reader.Read());
276 
277  if (reader.Peek() == '"')
278  reader.Read();
279 
280  return new QuotedIdentToken(text.ToString());
281  }
readonly ConfigFileReader reader
Definition: Tokenizer.cs:37
char Read()
Consumes one character from file.
Token Ntp.Analyzer.Config.Compiler.Tokenizer.PeekNext ( )
inline

Definition at line 105 of file Tokenizer.cs.

References Ntp.Analyzer.Config.Table.Token.EndOfFile, Ntp.Analyzer.Config.Table.Token.NewLine, Ntp.Analyzer.Config.Table.Token.Undefined, and Ntp.Analyzer.Config.Table.Token.Whitespace.

106  {
107  if (reader.Peek() == '\0')
108  return Token.EndOfFile;
109 
110  switch (reader.Peek())
111  {
112  case '\r':
113  case '\n':
114  return Token.NewLine;
115  case ' ':
116  case '\t':
117  return Token.Whitespace;
118  default:
119  return Token.Undefined;
120  }
121  }
readonly ConfigFileReader reader
Definition: Tokenizer.cs:37

Member Data Documentation

int Ntp.Analyzer.Config.Compiler.Tokenizer.ColumnNumber => reader.Position

Definition at line 43 of file Tokenizer.cs.

bool Ntp.Analyzer.Config.Compiler.Tokenizer.disposedValue
private

Definition at line 285 of file Tokenizer.cs.

int Ntp.Analyzer.Config.Compiler.Tokenizer.LineNumber => reader.Line

Definition at line 41 of file Tokenizer.cs.

readonly ConfigFileReader Ntp.Analyzer.Config.Compiler.Tokenizer.reader
private

Definition at line 37 of file Tokenizer.cs.

Property Documentation

Token Ntp.Analyzer.Config.Compiler.Tokenizer.Token
getprivate set

Definition at line 39 of file Tokenizer.cs.


The documentation for this class was generated from the following file: