本文整理汇总了C#中Antlr.Runtime.RecognitionException类的典型用法代码示例。如果您正苦于以下问题:C# RecognitionException类的具体用法?C# RecognitionException怎么用?C# RecognitionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RecognitionException类属于Antlr.Runtime命名空间,在下文中一共展示了RecognitionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetErrorMessage
public override string GetErrorMessage(RecognitionException e, string[] tokenNames)
{
System.Collections.IList stack = GetRuleInvocationStack(e, typeof(BlaiseParser).FullName);
string msg = string.Empty;
if (e is NoViableAltException)
{
NoViableAltException nvae = (NoViableAltException)e;
msg = "noviablealt;token=" + e.Token.ToString() +
"(decision=" + nvae.decisionNumber +
"state" + nvae.stateNumber + ")" +
"decision=<<" + nvae.grammarDecisionDescription + ">>";
}
else
{
msg = base.GetErrorMessage(e, tokenNames);
}
string stackStr = string.Empty;
foreach (object obj in stack)
{
stackStr += obj.ToString();
}
return stackStr + " " + msg;
}
示例2: DisplayRecognitionError
public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e)
{
var outputWindow = OutputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlIntellisense);
if (outputWindow != null)
{
string header = GetErrorHeader(e);
string message = GetErrorMessage(e, tokenNames);
Span span = new Span();
if (e.Token != null)
span = Span.FromBounds(e.Token.StartIndex, e.Token.StopIndex + 1);
if (message.Length > 100)
message = message.Substring(0, 100) + " ...";
ITextDocument document;
if (TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out document) && document != null)
{
string fileName = document.FilePath;
var line = Snapshot.GetLineFromPosition(span.Start);
message = string.Format("{0}({1},{2}): {3}: {4}", fileName, line.LineNumber + 1, span.Start - line.Start.Position + 1, GetType().Name, message);
}
outputWindow.WriteLine(message);
}
base.DisplayRecognitionError(tokenNames, e);
}
示例3: GetErrorMessage
public override string GetErrorMessage(RecognitionException e, string[] tokenNames)
{
if (e is MismatchedTokenException)
{
MismatchedTokenException exception = (MismatchedTokenException) e;
return ("mismatched character " + this.GetCharErrorDisplay(e.Character) + " expecting " + this.GetCharErrorDisplay(exception.Expecting));
}
if (e is NoViableAltException)
{
NoViableAltException exception1 = (NoViableAltException) e;
return ("no viable alternative at character " + this.GetCharErrorDisplay(e.Character));
}
if (e is EarlyExitException)
{
EarlyExitException exception5 = (EarlyExitException) e;
return ("required (...)+ loop did not match anything at character " + this.GetCharErrorDisplay(e.Character));
}
if (e is MismatchedNotSetException)
{
MismatchedNotSetException exception2 = (MismatchedNotSetException) e;
return string.Concat(new object[] { "mismatched character ", this.GetCharErrorDisplay(e.Character), " expecting set ", exception2.Expecting });
}
if (e is MismatchedSetException)
{
MismatchedSetException exception3 = (MismatchedSetException) e;
return string.Concat(new object[] { "mismatched character ", this.GetCharErrorDisplay(e.Character), " expecting set ", exception3.Expecting });
}
if (e is MismatchedRangeException)
{
MismatchedRangeException exception4 = (MismatchedRangeException) e;
return ("mismatched character " + this.GetCharErrorDisplay(e.Character) + " expecting set " + this.GetCharErrorDisplay(exception4.A) + ".." + this.GetCharErrorDisplay(exception4.B));
}
return base.GetErrorMessage(e, tokenNames);
}
示例4: Convert
public static QuerySyntaxException Convert(RecognitionException e, string hql)
{
string positionInfo = e.Line > 0 && e.CharPositionInLine > 0
? " near line " + e.Line + ", column " + e.CharPositionInLine
: "";
return new QuerySyntaxException(e.Message + positionInfo, hql);
}
示例5: ReportError
public void ReportError(RecognitionException e)
{
ReportError( e.ToString() );
_recognitionExceptions.Add( e );
if ( log.IsDebugEnabled ) {
log.Debug( e.ToString(), e );
}
}
示例6: AutomationErrorNode
public AutomationErrorNode(ITokenStream input, IToken start, IToken stop, RecognitionException ex)
{
var handler = new CommonErrorNode(input, start, stop, ex);
this.isNil = handler.IsNil;
this.type = handler.Type;
this.text = handler.Text;
this.toString = handler.ToString();
}
示例7: DebugRecognitionException
protected virtual void DebugRecognitionException(RecognitionException ex)
{
IDebugEventListener debugListener = this.recognizer.DebugListener;
if (debugListener != null)
{
debugListener.RecognitionException(ex);
}
}
示例8: ReportError
public override void ReportError(RecognitionException e)
{
if ( state.errorRecovery ) {
return;
}
state.syntaxErrors++; // don't count spurious
state.errorRecovery = true;
throw e;
}
示例9: AST2JSOMCommonErrorNode
/**
* Constructor.
*
* @param pInput Will be passed to the constructor of the wrapped object.
* @param pStart Will be passed to the constructor of the wrapped object.
* @param pStop Will be passed to the constructor of the wrapped object.
* @param pException Will be passed to the constructor of the wrapped
* object.
*
* __TEST__
*/
public AST2JSOMCommonErrorNode(
ITokenStream pInput, IToken pStart, IToken pStop,
RecognitionException pException)
: base()
{
//base();
mCommonErrorNode =
new CommonErrorNode(pInput, pStart, pStop, pException);
}
示例10: DisplayRecognitionError
public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e)
{
string headerError = GetErrorHeader(e);
string error = GetErrorMessage(e, tokenNames);
Errors.Add(new ParseException(new LineInfo(e.Line, e.CharPositionInLine), error));
base.DisplayRecognitionError(tokenNames, e);
}
示例11: FormatRecognitionException
private static string FormatRecognitionException(RecognitionException e, string source)
{
var res = "Message: " + e.Message + "\n";
res += "Token: " + e.Token.Text + "\n";
res += "Source: " + source + "\n";
res += "Line: " + e.Line + "\n";
res += "Char position in line: " + e.CharPositionInLine + "\n";
return res;
}
示例12: DisplayRecognitionError
public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e)
{
var handler = Error;
if (handler != null)
{
handler(string.Format("{0} {1}", GetErrorHeader(e), GetErrorMessage(e, tokenNames)));
}
base.DisplayRecognitionError(tokenNames, e);
}
示例13: SyntaxErrorException
public SyntaxErrorException(string input, String antlrMessage, RecognitionException exception)
: base(JSToCSharpExceptionType.SyntaxError, exception)
{
AntlrMessage = antlrMessage;
Input = input;
var span = AntlrException.Token == null ? -1 : AntlrException.Token.Text.Length;
var prettyInput = input.InjectErrorMarker(LineNumber, CharPositionInLine, span).InjectLineNumbers1();
SourceCode = prettyInput;
}
示例14: Report
public static SyntaxErrorException Report(BaseRecognizer source, RecognitionException e)
{
var input = source.Input.ToString();
if (source.Input is ANTLRStringStream)
input = new String((Char[])typeof(ANTLRStringStream).GetField("data",
BindingFlags.NonPublic | BindingFlags.Instance).GetValue(source.Input));
var antlrMessage = source.GetErrorHeader(e) + " " + source.GetErrorMessage(e, source.TokenNames);
throw new SyntaxErrorException(input, antlrMessage, e);
}
示例15: DisplayRecognitionError
/// <summary>
/// Logs the given error to the <see cref="ErrorTracker"/>.
/// </summary>
/// <param name="tokenNames">The names of the tokens in the current language.</param>
/// <param name="e">The error.</param>
public override void DisplayRecognitionError(String[] tokenNames, RecognitionException e)
{
LanguageError lerError = new LanguageError();
lerError.Line = e.Line - 1;
lerError.Column = e.CharPositionInLine;
lerError.Position = e.Token.StartIndex;
lerError.End = e.Token.StopIndex;
lerError.Message = GetErrorMessage(e, tokenNames);
ErrorTracker.ParserErrors.Add(lerError);
}