本文整理汇总了C#中Irony.Parsing.ParsingContext.AddParserError方法的典型用法代码示例。如果您正苦于以下问题:C# ParsingContext.AddParserError方法的具体用法?C# ParsingContext.AddParserError怎么用?C# ParsingContext.AddParserError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Irony.Parsing.ParsingContext
的用法示例。
在下文中一共展示了ParsingContext.AddParserError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryMatch
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);
}
示例2: Execute
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
示例3: ReportParseError
// 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);
}