Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
LanguageDataBuilder.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 using System.Diagnostics;
18 
19 namespace Irony.Parsing.Construction {
20  internal class LanguageDataBuilder {
21 
22  internal LanguageData Language;
23  Grammar _grammar;
24 
25  public LanguageDataBuilder(LanguageData language) {
26  Language = language;
27  _grammar = Language.Grammar;
28  }
29 
30  public bool Build() {
31  var sw = new Stopwatch();
32  try {
33  if (_grammar.Root == null)
34  Language.Errors.AddAndThrow(GrammarErrorLevel.Error, null, Resources.ErrRootNotSet);
35  sw.Start();
36  var gbld = new GrammarDataBuilder(Language);
37  gbld.Build();
38  //Just in case grammar author wants to customize something...
39  _grammar.OnGrammarDataConstructed(Language);
40  var pbld = new ParserDataBuilder(Language);
41  pbld.Build();
42  Validate();
43  //call grammar method, a chance to tweak the automaton
44  _grammar.OnLanguageDataConstructed(Language);
45  return true;
46  } catch (GrammarErrorException) {
47  return false; //grammar error should be already added to Language.Errors collection
48  } finally {
49  Language.ErrorLevel = Language.Errors.GetMaxLevel();
50  sw.Stop();
51  Language.ConstructionTime = sw.ElapsedMilliseconds;
52  }
53 
54  }
55 
56  #region Language Data Validation
57  private void Validate() {
58 
59  }//method
60  #endregion
61 
62 
63  }//class
64 }
static string ErrRootNotSet
Looks up a localized string similar to Root property of the grammar is not set..