本文整理了Java中org.antlr.runtime.Parser
类的一些代码示例,展示了Parser
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser
类的具体详情如下:
包路径:org.antlr.runtime.Parser
类名称:Parser
[英]A parser for TokenStreams. "parser grammars" result in a subclass of this.
[中]令牌流的解析器。“语法分析器”产生了这个类的一个子类。
代码示例来源:origin: JesusFreke/smali
public String getErrorMessage(RecognitionException e,
String[] tokenNames) {
if (verboseErrors) {
List stack = getRuleInvocationStack(e, this.getClass().getName());
String msg = null;
if (e instanceof NoViableAltException) {
NoViableAltException nvae = (NoViableAltException)e;
msg = " no viable alt; token="+getTokenErrorDisplay(e.token)+
" (decision="+nvae.decisionNumber+
" state "+nvae.stateNumber+")"+
" decision=<<"+nvae.grammarDecisionDescription+">>";
} else {
msg = super.getErrorMessage(e, tokenNames);
}
return stack + " " + msg;
} else {
return super.getErrorMessage(e, tokenNames);
}
}
代码示例来源:origin: protostuff/protostuff
/**
* Creates the error/warning message that we need to show users/IDEs when ANTLR has found a parsing error, has
* recovered from it and is now telling us that a parsing exception occurred.
*
* @param tokenNames
* token names as known by ANTLR (which we ignore)
* @param e
* The exception that was thrown
*/
@Override
public void displayRecognitionError(String[] tokenNames, RecognitionException e)
{
// This is just a place holder that shows how to override this method
//
super.displayRecognitionError(tokenNames, e);
}
代码示例来源:origin: org.antlr/antlr4
public String getParserErrorMessage(Parser parser, RecognitionException e) {
String msg;
if ( e instanceof NoViableAltException) {
String name = parser.getTokenErrorDisplay(e.token);
msg = name+" came as a complete surprise to me";
}
else if ( e instanceof v4ParserException) {
msg = ((v4ParserException)e).msg;
}
else {
msg = parser.getErrorMessage(e, parser.getTokenNames());
}
return msg;
}
代码示例来源:origin: antlr/stringtemplate4
protected void reportMessageAndThrowSTException(TokenStream tokens, Token templateToken,
Parser parser, RecognitionException re)
{
if ( re.token.getType() == STLexer.EOF_TYPE ) {
String msg = "premature EOF";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else if ( re instanceof NoViableAltException) {
String msg = "'"+re.token.getText()+"' came as a complete surprise to me";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else if ( tokens.index() == 0 ) { // couldn't parse anything
String msg = "this doesn't look like a template: \""+tokens+"\"";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else if ( tokens.LA(1) == STLexer.LDELIM ) { // couldn't parse expr
String msg = "doesn't look like an expression";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else {
String msg = parser.getErrorMessage(re, parser.getTokenNames());
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
throw new STException(); // we have reported the error, so just blast out
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelimpl
public void reportError(RecognitionException re) {
super.reportError(re);
hasErrorOccurred = true;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics
protected Object getMissingSymbol(IntStream input,
RecognitionException e,
int expectedTokenType,
BitSet follow)
{
String tokenText = null;
if ( expectedTokenType==Token.EOF ) tokenText = "<missing EOF>";
else tokenText = "<missing "+getTokenNames()[expectedTokenType]+">";
CommonToken t = new CommonToken(expectedTokenType, tokenText);
Token current = ((TokenStream)input).LT(1);
if ( current.getType() == Token.EOF ) {
current = ((TokenStream)input).LT(-1);
}
t.line = current.getLine();
t.charPositionInLine = current.getCharPositionInLine();
t.channel = DEFAULT_TOKEN_CHANNEL;
return t;
}
代码示例来源:origin: org.daisy.libs/jstyleparser
/**
* Recovers and logs error, using custom follow set,
* prepares tree part replacement
*/
public Object invalidFallbackGreedy(int ttype, String ttext, BitSet follow, RecognitionException re) {
parser.reportError(re);
if ( state.lastErrorIndex==input.index() ) {
// uh oh, another error at same token index; must be a case
// where LT(1) is in the recovery token set so nothing is
// consumed; consume a single token so at least to prevent
// an infinite loop; this is a failsafe.
input.consume();
}
state.lastErrorIndex = input.index();
parser.beginResync();
consumeUntilGreedy(input, follow);
parser.endResync();
return invalidReplacement(ttype, ttext);
}
代码示例来源:origin: org.daisy.libs/jstyleparser
/**
* Recovers and logs error, prepares tree part replacement
*/
public Object invalidFallback(int ttype, String ttext, RecognitionException re) {
parser.reportError(re);
parser.recover(input, re);
return invalidReplacement(ttype, ttext);
}
代码示例来源:origin: antlr/antlr3
/** Set the token stream and reset the parser */
public void setTokenStream(TokenStream input) {
this.input = null;
reset();
this.input = input;
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr-runtime
public Parser(TokenStream input) {
super(); // highlight that we go to super to set state object
setTokenStream(input);
}
代码示例来源:origin: uk.co.nichesolutions/antlr4
public String getParserErrorMessage(Parser parser, RecognitionException e) {
String msg;
if ( e instanceof NoViableAltException) {
String name = parser.getTokenErrorDisplay(e.token);
msg = name+" came as a complete surprise to me";
}
else if ( e instanceof v4ParserException) {
msg = ((v4ParserException)e).msg;
}
else {
msg = parser.getErrorMessage(e, parser.getTokenNames());
}
return msg;
}
代码示例来源:origin: org.antlr/ST4
protected void reportMessageAndThrowSTException(TokenStream tokens, Token templateToken,
Parser parser, RecognitionException re)
{
if ( re.token.getType() == STLexer.EOF_TYPE ) {
String msg = "premature EOF";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else if ( re instanceof NoViableAltException) {
String msg = "'"+re.token.getText()+"' came as a complete surprise to me";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else if ( tokens.index() == 0 ) { // couldn't parse anything
String msg = "this doesn't look like a template: \""+tokens+"\"";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else if ( tokens.LA(1) == STLexer.LDELIM ) { // couldn't parse expr
String msg = "doesn't look like an expression";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else {
String msg = parser.getErrorMessage(re, parser.getTokenNames());
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
throw new STException(); // we have reported the error, so just blast out
}
代码示例来源:origin: net.rapture/CodeGenLib
@Override
public void reportError(RecognitionException e) {
super.reportError(e);
throw new IllegalArgumentException("Failed");
}
}
代码示例来源:origin: antlr/antlr3
@Override
protected Object getMissingSymbol(IntStream input,
RecognitionException e,
int expectedTokenType,
BitSet follow)
{
String tokenText;
if ( expectedTokenType==Token.EOF ) tokenText = "<missing EOF>";
else tokenText = "<missing "+getTokenNames()[expectedTokenType]+">";
CommonToken t = new CommonToken(expectedTokenType, tokenText);
Token current = ((TokenStream)input).LT(1);
if ( current.getType() == Token.EOF ) {
current = ((TokenStream)input).LT(-1);
}
t.line = current.getLine();
t.charPositionInLine = current.getCharPositionInLine();
t.channel = DEFAULT_TOKEN_CHANNEL;
t.input = current.getInputStream();
return t;
}
代码示例来源:origin: org.daisy.libs/jstyleparser
/**
* Recovers and logs error inside a function, using custom follow set,
* prepares tree part replacement
*/
public Object invalidFallback(int ttype, String ttext, BitSet follow, CSSLexerState.RecoveryMode mode, CSSLexerState ls, RecognitionException re) {
parser.reportError(re);
if ( state.lastErrorIndex==input.index() ) {
// uh oh, another error at same token index; must be a case
// where LT(1) is in the recovery token set so nothing is
// consumed; consume a single token so at least to prevent
// an infinite loop; this is a failsafe.
input.consume();
}
state.lastErrorIndex = input.index();
parser.beginResync();
consumeUntil(input, follow, mode, ls);
parser.endResync();
return invalidReplacement(ttype, ttext);
}
代码示例来源:origin: antlr/antlr3
/** Set the token stream and reset the parser */
public void setTokenStream(TokenStream input) {
this.input = null;
reset();
this.input = input;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
public Parser(TokenStream input) {
super(); // highlight that we go to super to set state object
setTokenStream(input);
}
代码示例来源:origin: apache/phoenix
@Override
public String getErrorMessage(RecognitionException e, String[] tokenNames) {
if (e instanceof MismatchedTokenException) {
MismatchedTokenException mte = (MismatchedTokenException)e;
String txt = mte.token.getText();
String p = mte.token.getType() == -1 ? "EOF" : PARAPHRASE[mte.token.getType()];
String expecting = (mte.expecting < PARAPHRASE.length && mte.expecting >= 0) ? PARAPHRASE[mte.expecting] : null;
if (expecting == null) {
return "unexpected token (" + line(mte.token) + "," + column(mte.token) + "): " + (txt != null ? txt : p);
} else {
return "expecting " + expecting +
", found '" + (txt != null ? txt : p) + "'";
}
} else if (e instanceof NoViableAltException) {
//NoViableAltException nvae = (NoViableAltException)e;
return "unexpected token: (" + line(e.token) + "," + column(e.token) + ")" + getTokenErrorDisplay(e.token);
}
return super.getErrorMessage(e, tokenNames);
}
代码示例来源:origin: com.tunnelvisionlabs/antlr4
public String getParserErrorMessage(Parser parser, RecognitionException e) {
String msg;
if ( e instanceof NoViableAltException) {
String name = parser.getTokenErrorDisplay(e.token);
msg = name+" came as a complete surprise to me";
}
else if ( e instanceof v4ParserException) {
msg = ((v4ParserException)e).msg;
}
else {
msg = parser.getErrorMessage(e, parser.getTokenNames());
}
return msg;
}
代码示例来源:origin: org.antlr/stringtemplate
protected void reportMessageAndThrowSTException(TokenStream tokens, Token templateToken,
Parser parser, RecognitionException re)
{
if ( re.token.getType() == STLexer.EOF_TYPE ) {
String msg = "premature EOF";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else if ( re instanceof NoViableAltException) {
String msg = "'"+re.token.getText()+"' came as a complete surprise to me";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else if ( tokens.index() == 0 ) { // couldn't parse anything
String msg = "this doesn't look like a template: \""+tokens+"\"";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else if ( tokens.LA(1) == STLexer.LDELIM ) { // couldn't parse expr
String msg = "doesn't look like an expression";
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
else {
String msg = parser.getErrorMessage(re, parser.getTokenNames());
group.errMgr.compileTimeError(ErrorType.SYNTAX_ERROR, templateToken, re.token, msg);
}
throw new STException(); // we have reported the error, so just blast out
}
内容来源于网络,如有侵权,请联系作者删除!