Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
GrammarError.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  public enum GrammarErrorLevel {
20  NoError, //used only for max error level when there are no errors
21  Info,
22  Warning,
23  Conflict, //shift-reduce or reduce-reduce conflict
24  Error, //severe grammar error, parser construction cannot continue
25  InternalError, //internal Irony error
26  }
27 
28  public class GrammarError {
29  public readonly GrammarErrorLevel Level;
30  public readonly string Message;
31  public readonly ParserState State; //can be null!
32  public GrammarError(GrammarErrorLevel level, ParserState state, string message) {
33  Level = level;
34  State = state;
35  Message = message;
36  }
37  }//class
38 
39  public class GrammarErrorList : List<GrammarError> {
40  public void Add(GrammarErrorLevel level, ParserState state, string message, params object[] args) {
41  if (args != null && args.Length > 0)
42  message = String.Format(message, args);
43  base.Add(new GrammarError(level, state, message));
44  }
45  public void AddAndThrow(GrammarErrorLevel level, ParserState state, string message, params object[] args) {
46  Add(level, state, message, args);
47  var error = this[this.Count - 1];
48  var exc = new GrammarErrorException(error.Message, error);
49  throw exc;
50  }
52  var max = GrammarErrorLevel.NoError;
53  foreach (var err in this)
54  if (max < err.Level)
55  max = err.Level;
56  return max;
57  }
58  }
59 
60  //Used to cancel parser construction when fatal error is found
62  public readonly GrammarError Error;
63  public GrammarErrorException(string message, GrammarError error) : base(message) {
64  Error = error;
65  }
66 
67  }//class
68 
69 
70 }
readonly string Message
Definition: GrammarError.cs:30
GrammarError(GrammarErrorLevel level, ParserState state, string message)
Definition: GrammarError.cs:32
GrammarErrorException(string message, GrammarError error)
Definition: GrammarError.cs:63
readonly ParserState State
Definition: GrammarError.cs:31
GrammarErrorLevel GetMaxLevel()
Definition: GrammarError.cs:51
void Add(GrammarErrorLevel level, ParserState state, string message, params object[] args)
Definition: GrammarError.cs:40
void AddAndThrow(GrammarErrorLevel level, ParserState state, string message, params object[] args)
Definition: GrammarError.cs:45
readonly GrammarErrorLevel Level
Definition: GrammarError.cs:29