// Override this method to perform custom error processing public virtual void ReportParseError(ParsingContext context) { string error = null; if (context.CurrentParserInput.Term == this.SyntaxError) { error = context.CurrentParserInput.Token.Value as string; //scanner error } else if (context.CurrentParserInput.Term == this.Indent) { error = Resources.ErrUnexpIndent; } else if (context.CurrentParserInput.Term == this.Eof && context.OpenBraces.Count > 0) { if (context.OpenBraces.Count > 0) { //report unclosed braces/parenthesis var openBrace = context.OpenBraces.Peek(); error = string.Format(Resources.ErrNoClosingBrace, openBrace.Text); } else { error = Resources.ErrUnexpEof; } } else { var expectedTerms = context.GetExpectedTermSet(); error = ConstructParserErrorMessage(context, expectedTerms); } context.AddParserError(error); }//method
public override Token TryMatch(ParsingContext context, ISourceStream source) { string tokenText = string.Empty; while (true) { //Find next position var newPos = source.Text.IndexOfAny(_stopChars, source.PreviewPosition); if(newPos == -1) { if(IsSet(FreeTextOptions.AllowEof)) { source.PreviewPosition = source.Text.Length; return source.CreateToken(this.OutputTerminal); } else return null; } if (newPos == source.PreviewPosition) // DC { context.AddParserError("(DC) in TryMatch, newPos == source.PreviewPosition", new object[] {}); break; // DC } tokenText += source.Text.Substring(source.PreviewPosition, newPos - source.PreviewPosition); source.PreviewPosition = newPos; //if it is escape, add escaped text and continue search if (CheckEscape(source, ref tokenText)) continue; //check terminators if (CheckTerminators(source, ref tokenText)) break; //from while (true) } return source.CreateToken(this.OutputTerminal, tokenText); }
public override void Execute(ParsingContext context) { if (context.TracingEnabled) context.AddTrace(Resources.MsgTraceExecCustomAction); //States with DefaultAction do NOT read input, so we read it here if (context.CurrentParserInput == null) context.Parser.ReadInput(); // Remember old state and input; if they don't change after custom action - it is error, we may fall into an endless loop var oldState = context.CurrentParserState; var oldInput = context.CurrentParserInput; ExecuteRef(context, this); //Prevent from falling into an infinite loop if (context.CurrentParserState == oldState && context.CurrentParserInput == oldInput) { context.AddParserError(Resources.MsgErrorCustomActionDidNotAdvance); context.Parser.RecoverFromError(); } } //method
public override Token TryMatch(ParsingContext context, ISourceStream source) { string tokenText = string.Empty; while (true) { //Find next position var newPos = source.Text.IndexOfAny(_stopChars, source.PreviewPosition); if (newPos == -1) { if (IsSet(FreeTextOptions.AllowEof)) { source.PreviewPosition = source.Text.Length; return(source.CreateToken(this.OutputTerminal)); } else { return(null); } } if (newPos == source.PreviewPosition) // DC { context.AddParserError("(DC) in TryMatch, newPos == source.PreviewPosition", new object[] {}); break; // DC } tokenText += source.Text.Substring(source.PreviewPosition, newPos - source.PreviewPosition); source.PreviewPosition = newPos; //if it is escape, add escaped text and continue search if (CheckEscape(source, ref tokenText)) { continue; } //check terminators if (CheckTerminators(source, ref tokenText)) { break; //from while (true) } } return(source.CreateToken(this.OutputTerminal, tokenText)); }
public override void Execute(ParsingContext context) { var traceEnabled = context.TracingEnabled; if (traceEnabled) { context.AddTrace("Conditional Parser Action."); } for (int i = 0; i < ConditionalEntries.Count; i++) { var ce = ConditionalEntries[i]; if (traceEnabled) { context.AddTrace(" Checking condition: " + ce.Description); } if (ce.Condition(context)) { if (traceEnabled) { context.AddTrace(" Condition is TRUE, executing action: " + ce.Action.ToString()); } ce.Action.Execute(context); return; } } //if no conditions matched, execute default action if (DefaultAction == null) { context.AddParserError("Fatal parser error: no conditions matched in conditional parser action, and default action is null." + " State: {0}", context.CurrentParserState.Name); context.Parser.RecoverFromError(); return; } if (traceEnabled) { context.AddTrace(" All conditions failed, executing default action: " + DefaultAction.ToString()); } DefaultAction.Execute(context); } //method
public override void Execute(ParsingContext context) { if (context.TracingEnabled) { context.AddTrace(Resources.MsgTraceExecCustomAction); } //States with DefaultAction do NOT read input, so we read it here if (context.CurrentParserInput == null) { context.Parser.ReadInput(); } // Remember old state and input; if they don't change after custom action - it is error, we may fall into an endless loop var oldState = context.CurrentParserState; var oldInput = context.CurrentParserInput; ExecuteRef(context, this); //Prevent from falling into an infinite loop if (context.CurrentParserState == oldState && context.CurrentParserInput == oldInput) { context.AddParserError(Resources.MsgErrorCustomActionDidNotAdvance); context.Parser.RecoverFromError(); } }//method
// Override this method to perform custom error processing public virtual void ReportParseError(ParsingContext context) { string error = null; if (context.CurrentParserInput.Term == this.SyntaxError) error = context.CurrentParserInput.Token.Value as string; //scanner error else if (context.CurrentParserInput.Term == this.Indent) error = Resources.ErrUnexpIndent; else if (context.CurrentParserInput.Term == this.Eof && context.OpenBraces.Count > 0) { if (context.OpenBraces.Count > 0) { //report unclosed braces/parenthesis var openBrace = context.OpenBraces.Peek(); error = string.Format(Resources.ErrNoClosingBrace, openBrace.Text); } else error = Resources.ErrUnexpEof; }else { var expectedTerms = context.GetExpectedTermSet(); error = ConstructParserErrorMessage(context, expectedTerms); } context.AddParserError(error); }