NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Analyzer.Config.Syntax.SyntaxNode< T > Class Template Referenceabstract
Inheritance diagram for Ntp.Analyzer.Config.Syntax.SyntaxNode< T >:
Collaboration diagram for Ntp.Analyzer.Config.Syntax.SyntaxNode< T >:

Public Member Functions

void Add (ISyntaxNode node)
 
void Assemble (ISyntaxNode node)
 
Compile ()
 
void CompileNode ()
 
IEnumerator< ISyntaxNodeGetEnumerator ()
 
void Resolve (SymbolTable table)
 
void Validate (SymbolTable table)
 

Public Attributes

ConfigurationNode CompiledNode => compiledNode
 
IEnumerable< string > Errors => errors
 
bool HasErrors => errors.Count != 0
 

Protected Member Functions

 SyntaxNode (Symbol symbol, string name, int line, bool requirePath=false)
 
void AddError (string message)
 
void AddReferenceNameError (ISyntaxNode node, string keyword, string name)
 
void AddReferenceTypeError (ISyntaxNode node, string keyword, string section, string name)
 
void CheckAllIsPresent (IEnumerable< Symbol > list)
 
void CheckIsUnique (IEnumerable< Symbol > list)
 
Uri CheckLink (string link, string keyword)
 
void CheckOneIsPresent (IEnumerable< Symbol > list)
 
void CheckOnlyOneIsPresent (IEnumerable< Symbol > list)
 
void CheckTypeIs< TU > (Symbol symbol)
 
void CheckTypeIs< TU, TV > (Symbol symbol)
 
abstract T InternalCompile ()
 
virtual void InternalResolve (SymbolTable table)
 Override to resolve references to other syntax nodes from this syntax node. More...
 
virtual void ValidateMandatories ()
 Override to validates the mandatory types in this syntax node. More...
 
virtual void ValidateReferences (SymbolTable table)
 Override to validates the references in this syntax node. More...
 
virtual void ValidateTypes ()
 Override to validates the types in this syntax node. More...
 

Properties

int Line [get]
 
string Name [get]
 
List< ISyntaxNodeNodes [get]
 
bool RequirePath [get]
 
Symbol Symbol [get]
 
- Properties inherited from Ntp.Analyzer.Config.Syntax.ISyntaxNode
ConfigurationNode CompiledNode [get]
 
IEnumerable< string > Errors [get]
 
bool HasErrors [get]
 
int Line [get]
 
bool RequirePath [get]
 
Symbol Symbol [get]
 

Private Member Functions

IEnumerator IEnumerable. GetEnumerator ()
 

Private Attributes

compiledNode
 
readonly List< string > errors
 

Detailed Description

Type Constraints
T :ConfigurationNode 

Definition at line 33 of file SyntaxNode.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.SyntaxNode ( Symbol  symbol,
string  name,
int  line,
bool  requirePath = false 
)
inlineprotected

Definition at line 36 of file SyntaxNode.cs.

37  {
38  Symbol = symbol;
39  Name = name;
40  Line = line;
41  RequirePath = requirePath;
42  compiledNode = null;
43  Nodes = new List<ISyntaxNode>();
44  errors = new List<string>();
45  }
readonly List< string > errors
Definition: SyntaxNode.cs:47

Member Function Documentation

void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.Add ( ISyntaxNode< T >  node)
inline

Implements Ntp.Analyzer.Config.Syntax.ISyntaxNode.

Definition at line 66 of file SyntaxNode.cs.

Referenced by Ntp.Analyzer.Config.Syntax.GraphSetSyntaxNode.InternalCompile(), and Ntp.Analyzer.Config.Compiler.ConfigParser.ParseOption< T >().

67  {
68  Nodes.Add(node);
69  }

Here is the caller graph for this function:

void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.AddError ( string  message)
inlineprotected

Definition at line 454 of file SyntaxNode.cs.

455  {
456  errors.Add(message);
457  }
readonly List< string > errors
Definition: SyntaxNode.cs:47
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.AddReferenceNameError ( ISyntaxNode< T >  node,
string  keyword,
string  name 
)
inlineprotected

Definition at line 428 of file SyntaxNode.cs.

429  {
430  var b = new StringBuilder();
431  if (Line != 0)
432  {
433  b.Append("Error in line ");
434  b.Append(node.Line);
435  b.Append(": ");
436  }
437  b.Append($"{keyword} {name} refers to a nonexistent section.");
438  AddError(b.ToString());
439  }
var b
Definition: bootstrap.min.js:6
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.AddReferenceTypeError ( ISyntaxNode< T >  node,
string  keyword,
string  section,
string  name 
)
inlineprotected

Definition at line 441 of file SyntaxNode.cs.

442  {
443  var b = new StringBuilder();
444  if (node.Line != 0)
445  {
446  b.Append("Error in line ");
447  b.Append(node.Line);
448  b.Append(": ");
449  }
450  b.Append($"{keyword} {name} does not refer to a {section} section.");
451  AddError(b.ToString());
452  }
var b
Definition: bootstrap.min.js:6
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.Assemble ( ISyntaxNode< T >  node)
inline

Implements Ntp.Analyzer.Config.Syntax.ISyntaxNode.

Definition at line 98 of file SyntaxNode.cs.

99  {
100  if (compiledNode == null)
101  return;
102 
103  compiledNode.Parent = node.CompiledNode;
104  node.CompiledNode.Assemble();
105  }
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.CheckAllIsPresent ( IEnumerable< Symbol list)
inlineprotected

Definition at line 205 of file SyntaxNode.cs.

206  {
207  var missing = list.
208  Where(item => Nodes.Count(n => n.Symbol == item) == 0).
209  ToList();
210 
211  if (missing.Count == 0)
212  return;
213 
214  // Build error message
215  int i = 0;
216  int count = missing.Count;
217  var b = new StringBuilder();
218 
219  if (Line != 0)
220  {
221  b.Append("Error in line ");
222  b.Append(Line);
223  b.Append(": ");
224  }
225  b.Append(Keyword.Find(Symbol).Name);
226  b.Append(" section is missing the setting");
227  b.Append(missing.Count > 1 ? "s: " : ": ");
228 
229  foreach (var item in missing)
230  {
231  i++;
232  b.Append(Keyword.Find(item).Name);
233  if (i == count - 1 && count > 1)
234  {
235  b.Append(" and ");
236  }
237  else if (i != count)
238  {
239  b.Append(", ");
240  }
241  else
242  {
243  b.Append(".");
244  }
245  }
246 
247  errors.Add(b.ToString());
248  }
static Keyword Find(Symbol symbol)
Definition: Keyword.cs:216
var b
Definition: bootstrap.min.js:6
readonly List< string > errors
Definition: SyntaxNode.cs:47
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.CheckIsUnique ( IEnumerable< Symbol list)
inlineprotected

Definition at line 340 of file SyntaxNode.cs.

341  {
342  var nonUniques = (
343  from symbol in list
344  let c = Nodes.Count(n => n.Symbol == symbol)
345  where c > 1
346  select symbol
347  ).ToList();
348 
349  if (nonUniques.Count == 0)
350  return;
351 
352  // Build error message
353  int i = 0;
354  int count = nonUniques.Count;
355  var b = new StringBuilder();
356 
357  if (Line != 0)
358  {
359  b.Append("Error in line ");
360  b.Append(Line);
361  b.Append(": ");
362  }
363  b.Append(Keyword.Find(Symbol).Name);
364  b.Append(" section has multiple occurrences of the setting");
365  b.Append(count > 1 ? "s: " : ": ");
366 
367  foreach (var item in nonUniques)
368  {
369  i++;
370  b.Append(Keyword.Find(item).Name);
371  if (i == count - 1)
372  {
373  b.Append(" and ");
374  }
375  else if (i != count)
376  {
377  b.Append(", ");
378  }
379  else
380  {
381  b.Append(".");
382  }
383  }
384 
385  errors.Add(b.ToString());
386  }
static Keyword Find(Symbol symbol)
Definition: Keyword.cs:216
var c
Definition: bootstrap.min.js:6
var b
Definition: bootstrap.min.js:6
readonly List< string > errors
Definition: SyntaxNode.cs:47
Uri Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.CheckLink ( string  link,
string  keyword 
)
inlineprotected

Definition at line 388 of file SyntaxNode.cs.

389  {
390  if (link == null)
391  return null;
392 
393  Uri uri;
394  string text = link.TrimStart();
395 
396  if ((text.StartsWith("http://") ||
397  text.StartsWith("https://") ||
398  text.StartsWith("ftp://") ||
399  text.StartsWith("mailto:") ||
400  text.StartsWith("javascript:")) &&
401  Uri.TryCreate(link, UriKind.Absolute, out uri))
402  return uri;
403 
404  if (Uri.TryCreate("/" + link.TrimStart('/'), UriKind.Relative, out uri))
405  return uri;
406 
407  if (Uri.TryCreate(link, UriKind.Absolute, out uri))
408  return uri;
409 
410  var name = Keyword.Find(Symbol).Name;
411  var b = new StringBuilder();
412  if (Line != 0)
413  {
414  b.Append("Error in line ");
415  b.Append(Line);
416  b.Append(": ");
417  }
418  b.Append($"{keyword} {name} is not a wellformed link.");
419  AddError(b.ToString());
420 
421  return null;
422  }
static Keyword Find(Symbol symbol)
Definition: Keyword.cs:216
var b
Definition: bootstrap.min.js:6
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.CheckOneIsPresent ( IEnumerable< Symbol list)
inlineprotected

Definition at line 250 of file SyntaxNode.cs.

251  {
252  var symbols = list as IList<Symbol> ?? list.ToList();
253  var set = new HashSet<Symbol>(symbols);
254 
255  if (Nodes.Any(node => set.Contains(node.Symbol)))
256  return;
257 
258  // Build error message
259  int i = 0;
260  int count = symbols.Count;
261  var b = new StringBuilder();
262 
263  if (Line != 0)
264  {
265  b.Append("Error in line ");
266  b.Append(Line);
267  b.Append(": ");
268  }
269  b.Append(Keyword.Find(Symbol).Name);
270  b.Append(" section must contain at least one of the setting");
271  b.Append(count > 1 ? "s: " : ": ");
272 
273  foreach (var item in symbols)
274  {
275  i++;
276  b.Append(Keyword.Find(item).Name);
277  if (i == count - 1)
278  {
279  b.Append(" or ");
280  }
281  else if (i != count)
282  {
283  b.Append(", ");
284  }
285  else
286  {
287  b.Append(".");
288  }
289  }
290 
291  errors.Add(b.ToString());
292  }
static Keyword Find(Symbol symbol)
Definition: Keyword.cs:216
var b
Definition: bootstrap.min.js:6
readonly List< string > errors
Definition: SyntaxNode.cs:47
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.CheckOnlyOneIsPresent ( IEnumerable< Symbol list)
inlineprotected

Definition at line 294 of file SyntaxNode.cs.

295  {
296  var symbols = list.ToList();
297  var set = new HashSet<Symbol>(symbols);
298 
299  int a = Nodes.Count(node => set.Contains(node.Symbol));
300 
301  if (a < 2)
302  return;
303 
304  // Build error message
305  int i = 0;
306  int count = symbols.Count;
307  var b = new StringBuilder();
308 
309  if (Line != 0)
310  {
311  b.Append("Error in line ");
312  b.Append(Line);
313  b.Append(": ");
314  }
315  b.Append(Keyword.Find(Symbol).Name);
316  b.Append(" section can only contain one of the setting");
317  b.Append(count > 1 ? "s: " : ": ");
318 
319  foreach (var item in symbols)
320  {
321  i++;
322  b.Append(Keyword.Find(item).Name);
323  if (i == count - 1)
324  {
325  b.Append(" or ");
326  }
327  else if (i != count)
328  {
329  b.Append(", ");
330  }
331  else
332  {
333  b.Append(".");
334  }
335  }
336 
337  errors.Add(b.ToString());
338  }
function a
Definition: bootstrap.min.js:6
static Keyword Find(Symbol symbol)
Definition: Keyword.cs:216
var b
Definition: bootstrap.min.js:6
readonly List< string > errors
Definition: SyntaxNode.cs:47
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.CheckTypeIs< TU > ( Symbol  symbol)
inlineprotected
Type Constraints
TU :SettingNode 
TU :new() 

Definition at line 154 of file SyntaxNode.cs.

155  : SettingNode, new()
156  {
157  foreach (var node in Nodes.Where(n => n.Symbol == symbol))
158  {
159  if (node is TU)
160  continue;
161 
162  // Build error message
163  var b = new StringBuilder();
164  if (Line != 0)
165  {
166  b.Append("Error in line ");
167  b.Append(Line);
168  b.Append(": ");
169  }
170  b.Append("Value of setting ");
171  b.Append(Keyword.Find(symbol).Name);
172  b.Append(" must be ");
173  b.Append(new TU().SettingValue);
174  errors.Add(b.ToString());
175  }
176  }
static Keyword Find(Symbol symbol)
Definition: Keyword.cs:216
var b
Definition: bootstrap.min.js:6
readonly List< string > errors
Definition: SyntaxNode.cs:47
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.CheckTypeIs< TU, TV > ( Symbol  symbol)
inlineprotected
Type Constraints
TU :SettingNode 
TU :new() 
TV :SettingNode 
TV :new() 

Definition at line 178 of file SyntaxNode.cs.

179  : SettingNode, new()
180  where TV : SettingNode, new()
181  {
182  foreach (var node in Nodes.Where(n => n.Symbol == symbol))
183  {
184  if (node is TU || node is TV)
185  continue;
186 
187  // Build error message
188  var b = new StringBuilder();
189  if (Line != 0)
190  {
191  b.Append("Error in line ");
192  b.Append(Line);
193  b.Append(": ");
194  }
195  b.Append("Value of setting ");
196  b.Append(Keyword.Find(symbol).Name);
197  b.Append(" must be ");
198  b.Append(new TU().SettingValue);
199  b.Append(" or ");
200  b.Append(new TV().SettingValue);
201  errors.Add(b.ToString());
202  }
203  }
static Keyword Find(Symbol symbol)
Definition: Keyword.cs:216
var b
Definition: bootstrap.min.js:6
readonly List< string > errors
Definition: SyntaxNode.cs:47
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.CompileNode ( )
inline

Implements Ntp.Analyzer.Config.Syntax.ISyntaxNode.

Definition at line 81 of file SyntaxNode.cs.

82  {
83  Compile();
84  }
IEnumerator<ISyntaxNode> Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.GetEnumerator ( )
inline

Definition at line 71 of file SyntaxNode.cs.

72  {
73  return Nodes.GetEnumerator();
74  }
IEnumerator IEnumerable. Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.GetEnumerator ( )
inlineprivate

Definition at line 76 of file SyntaxNode.cs.

77  {
78  return GetEnumerator();
79  }
IEnumerator< ISyntaxNode > GetEnumerator()
Definition: SyntaxNode.cs:71
virtual void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.InternalResolve ( SymbolTable  table)
inlineprotectedvirtual

Override to resolve references to other syntax nodes from this syntax node.

When overriding this method do not call the base method.

Parameters
tableTable.

Definition at line 146 of file SyntaxNode.cs.

147  {
148  }
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.Resolve ( SymbolTable  table)
inline

Implements Ntp.Analyzer.Config.Syntax.ISyntaxNode.

Definition at line 86 of file SyntaxNode.cs.

87  {
88  InternalResolve(table);
89  }
virtual void InternalResolve(SymbolTable table)
Override to resolve references to other syntax nodes from this syntax node.
Definition: SyntaxNode.cs:146
void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.Validate ( SymbolTable  table)
inline

Implements Ntp.Analyzer.Config.Syntax.ISyntaxNode.

Definition at line 91 of file SyntaxNode.cs.

92  {
93  ValidateTypes();
95  ValidateReferences(table);
96  }
virtual void ValidateReferences(SymbolTable table)
Override to validates the references in this syntax node.
Definition: SyntaxNode.cs:137
virtual void ValidateMandatories()
Override to validates the mandatory types in this syntax node.
Definition: SyntaxNode.cs:128
virtual void ValidateTypes()
Override to validates the types in this syntax node.
Definition: SyntaxNode.cs:120
virtual void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.ValidateMandatories ( )
inlineprotectedvirtual
virtual void Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.ValidateReferences ( SymbolTable  table)
inlineprotectedvirtual

Override to validates the references in this syntax node.

When overriding this method do not call the base method.

Parameters
tableTable.

Definition at line 137 of file SyntaxNode.cs.

138  {
139  }

Member Data Documentation

T Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.compiledNode
private

Definition at line 48 of file SyntaxNode.cs.

Definition at line 64 of file SyntaxNode.cs.

readonly List<string> Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.errors
private

Definition at line 47 of file SyntaxNode.cs.

IEnumerable<string> Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.Errors => errors

Definition at line 62 of file SyntaxNode.cs.

bool Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.HasErrors => errors.Count != 0

Definition at line 60 of file SyntaxNode.cs.

Property Documentation

Definition at line 58 of file SyntaxNode.cs.

string Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.Name
getprotected

Definition at line 52 of file SyntaxNode.cs.

List<ISyntaxNode> Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.Nodes
getprotected

Definition at line 50 of file SyntaxNode.cs.

bool Ntp.Analyzer.Config.Syntax.SyntaxNode< T >.RequirePath
get

Definition at line 56 of file SyntaxNode.cs.


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