14 using System.Collections.Generic;
16 using System.Runtime.InteropServices;
17 using System.Diagnostics;
18 using System.Globalization;
54 public int MaxErrors = 20;
57 #region properties and fields
64 public ParseTree CurrentParseTree {
get;
internal set; }
85 public readonly Dictionary<string, object> Values =
new Dictionary<string, object>();
89 get {
return _tabWidth; }
102 this.Parser = parser;
103 Language = Parser.Language;
104 Culture = Language.Grammar.DefaultCulture;
107 Resources.Culture = Culture;
110 Options |= ParseOptions.GrammarDebugging;
117 #region Events: TokenCreated
120 internal void OnTokenCreated() {
121 if (TokenCreated != null)
122 TokenCreated(
this, SharedParsingEventArgs);
126 #region Options helper methods
128 return (Options & option) != 0;
138 #region Error handling and tracing
140 var location = CurrentParserInput == null? Parser.Scanner.Location : CurrentParserInput.Span.Location;
145 if (CurrentParseTree == null)
return;
146 if (CurrentParseTree.ParserMessages.Count >= MaxErrors)
return;
147 if (args != null && args.Length > 0)
148 message = string.Format(message, args);
149 CurrentParseTree.ParserMessages.Add(
new ParserMessage(level, location, message, CurrentParserState));
154 public void AddTrace(
string message, params
object[] args) {
156 if (args != null && args.Length > 0)
157 message = string.Format(message, args);
163 internal void Reset() {
164 CurrentParserState = Parser.InitialState;
165 CurrentParserInput = null;
169 ParserInputStack.Clear();
170 CurrentParseTree = null;
173 CurrentTerminals.Clear();
175 PreviousToken = null;
178 foreach (var filter
in TokenFilters)
183 foreach (var filter
in TokenFilters)
184 filter.OnSetSourceLocation(location);
185 Parser.Scanner.Location = location;
188 #region Expected term set computations
190 if (CurrentParserState == null)
193 if (CurrentParserState.ReportedExpectedSet == null)
194 CurrentParserState.ReportedExpectedSet = CoreParser.ComputeGroupedExpectedSetForState(Language.Grammar, CurrentParserState);
199 var expectedSet = FilterBracesInExpectedSet(CurrentParserState.ReportedExpectedSet);
205 result.UnionWith(stateExpectedSet);
207 var nextClosingBrace = string.Empty;
208 if (OpenBraces.Count > 0) {
209 var lastOpenBraceTerm = OpenBraces.Peek().
KeyTerm;
210 var nextClosingBraceTerm = lastOpenBraceTerm.IsPairFor as
KeyTerm;
211 if (nextClosingBraceTerm != null)
212 nextClosingBrace = nextClosingBraceTerm.Text;
215 foreach(var closingBrace
in Language.GrammarData.ClosingBraces) {
216 if (result.Contains(closingBrace) && closingBrace != nextClosingBrace)
217 result.Remove(closingBrace);
233 [StructLayout(LayoutKind.Explicit)]
readonly ParserStack ParserStack
StringSet GetExpectedTermSet()
SourceLocation PreviousLineStart
Flags
Enumeration of the new Assimp's flags.
bool OptionIsSet(ParseOptions option)
void SetOption(ParseOptions option, bool value)
void AddParserMessage(ParserErrorLevel level, SourceLocation location, string message, params object[] args)
void SetSourceLocation(SourceLocation location)
ParsingContext(Parser parser)
VsScannerStateMap VsLineScanState
EventHandler< ParsingEventArgs > TokenCreated
Tokens are produced by scanner and fed to parser, optionally passing through Token filters in between...
void AddParserError(string message, params object[] args)
readonly LanguageData Language
void AddTrace(string message, params object[] args)