當前位置: 首頁>>代碼示例>>Java>>正文


Java RecognitionException類代碼示例

本文整理匯總了Java中org.antlr.v4.runtime.RecognitionException的典型用法代碼示例。如果您正苦於以下問題:Java RecognitionException類的具體用法?Java RecognitionException怎麽用?Java RecognitionException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RecognitionException類屬於org.antlr.v4.runtime包,在下文中一共展示了RecognitionException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseString

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
@Override
public SortedMap<Integer, String> parseString(String fieldString) {
    CharStream is = CharStreams.fromString(fieldString);
    DrawGrammarLexer lex = new DrawGrammarLexer(is);
    CommonTokenStream tokens = new CommonTokenStream(lex);
    DrawGrammarParser parser = new DrawGrammarParser(tokens);
    palette = Palette.makeDefaultPalette("DarkSpectrum");
    final SortedMap<Integer, String> resultMap;
    try {
        resultMap = parser.root().map;
    } catch (RecognitionException | NullPointerException | StringIndexOutOfBoundsException | RasterFormatException re) {
        //Something wrong with the parsing do not update.
        return null;
    }
    return resultMap;
}
 
開發者ID:fusiled,項目名稱:bitbox,代碼行數:17,代碼來源:PainterLogic.java

示例2: syntaxError

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
@Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
            int line, int charPositionInLine,
            String msg, RecognitionException e) {
        if (!reportSyntaxErrors) {
            return;
        }

//        String sourceName = recognizer.getInputStream().getSourceName();
//        if (!sourceName.isEmpty()) {
//            sourceName = String.format("%s:%d:%d: ", sourceName, line, charPositionInLine);
//        }

        System.err.println("CUSTOM:  "  + "line " + line + ":" + charPositionInLine + " " + msg);
        syntaxErrors = msg;
    }
 
開發者ID:CIRDLES,項目名稱:Squid,代碼行數:17,代碼來源:DescriptiveErrorListener.java

示例3: setupPicky

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
private void setupPicky(PainlessParser parser) {
    // Diagnostic listener invokes syntaxError on other listeners for ambiguity issues,
    parser.addErrorListener(new DiagnosticErrorListener(true));
    // a second listener to fail the test when the above happens.
    parser.addErrorListener(new BaseErrorListener() {
        @Override
        public void syntaxError(final Recognizer<?,?> recognizer, final Object offendingSymbol, final int line,
                                final int charPositionInLine, final String msg, final RecognitionException e) {
            throw new AssertionError("line: " + line + ", offset: " + charPositionInLine +
                ", symbol:" + offendingSymbol + " " + msg);
        }
    });

    // Enable exact ambiguity detection (costly). we enable exact since its the default for
    // DiagnosticErrorListener, life is too short to think about what 'inexact ambiguity' might mean.
    parser.getInterpreter().setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:Walker.java

示例4: recover

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
@Override
public void recover(final Parser recognizer, final RecognitionException re) {
    final Token token = re.getOffendingToken();
    String message;

    if (token == null) {
        message = "no parse token found.";
    } else if (re instanceof InputMismatchException) {
        message = "unexpected token [" + getTokenErrorDisplay(token) + "]" +
                " was expecting one of [" + re.getExpectedTokens().toString(recognizer.getVocabulary()) + "].";
    } else if (re instanceof NoViableAltException) {
        if (token.getType() == PainlessParser.EOF) {
            message = "unexpected end of script.";
        } else {
            message = "invalid sequence of tokens near [" + getTokenErrorDisplay(token) + "].";
        }
    } else {
        message =  "unexpected token near [" + getTokenErrorDisplay(token) + "].";
    }

    Location location = new Location(sourceName, token == null ? -1 : token.getStartIndex());
    throw location.createError(new IllegalArgumentException(message, re));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:ParserErrorStrategy.java

示例5: syntaxError

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
                    int line, int charPositionInLine,
                    String msg, RecognitionException e)
{
    if (!REPORT_SYNTAX_ERRORS) {
        return;
    }

    String sourceName = recognizer.getInputStream().getSourceName();
    if (!sourceName.isEmpty()) {
        sourceName = String.format("%d:%d: ", line, charPositionInLine);
    }

    error_msg.add(sourceName+"line "+line+":"+charPositionInLine+" "+msg);
}
 
開發者ID:ESS-OVGU,項目名稱:SelectScriptC,代碼行數:17,代碼來源:SelectScriptErrorListener.java

示例6: recoverInline

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
/**
 * Make sure we don't attempt to recover inline; if the parser successfully
 * recovers, it won't throw an exception.
 */
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
    InputMismatchException e = new InputMismatchException(recognizer);

    String policies = recognizer.getInputStream().getText();
    StringTokenizer tk = new StringTokenizer(policies, ";");
    String policy = "";
    int idx = 0;
    while (tk.hasMoreElements()) {
        policy = (String) tk.nextElement();
        idx += policy.length();
        if (idx >= e.getOffendingToken().getStartIndex()) {
            break;
        }
    }

    String message = Messages.get(Messages.DEFAULT_LOCALE,
            "error_invalid_firewallconfig", new Object[] {
                    e.getOffendingToken().getText(), policy });
    throw new RuntimeException(message);
}
 
開發者ID:servicecatalog,項目名稱:oscm-app,代碼行數:26,代碼來源:FWPolicyErrorStrategy.java

示例7: source_zone

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
public final Source_zoneContext source_zone(FWPolicy p)
        throws RecognitionException {
    Source_zoneContext _localctx = new Source_zoneContext(_ctx, getState(),
            p);
    enterRule(_localctx, 4, RULE_source_zone);
    try {
        enterOuterAlt(_localctx, 1);
        {
            {
                setState(51);
                ((Source_zoneContext) _localctx).ZONE = match(ZONE);
            }

            _localctx.p.setSrcZone(((Source_zoneContext) _localctx).ZONE
                    .getText());

        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
 
開發者ID:servicecatalog,項目名稱:oscm-app,代碼行數:27,代碼來源:FWPolicyParser.java

示例8: dest_zone

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
public final Dest_zoneContext dest_zone(FWPolicy p)
        throws RecognitionException {
    Dest_zoneContext _localctx = new Dest_zoneContext(_ctx, getState(), p);
    enterRule(_localctx, 10, RULE_dest_zone);
    try {
        enterOuterAlt(_localctx, 1);
        {
            {
                setState(60);
                ((Dest_zoneContext) _localctx).ZONE = match(ZONE);
            }

            _localctx.p.setDstZone(((Dest_zoneContext) _localctx).ZONE
                    .getText());

        }
    } catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    } finally {
        exitRule();
    }
    return _localctx;
}
 
開發者ID:servicecatalog,項目名稱:oscm-app,代碼行數:26,代碼來源:FWPolicyParser.java

示例9: parseInputStream

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
private void parseInputStream(CharStream inputStream, OboParseResultListener listener) {
  final OboLexer l = new OboLexer(inputStream);
  final Antlr4OboParser p = new Antlr4OboParser(new CommonTokenStream(l));

  p.addErrorListener(new BaseErrorListener() {
    @Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
        int charPositionInLine, String msg, RecognitionException e) {
      throw new IllegalStateException("Failed to parse at line " + line + " due to " + msg, e);
    }
  });

  if (debug) {
    p.addErrorListener(new DiagnosticErrorListener());
  }

  p.addParseListener(new OboParserListener(listener));

  p.oboFile();
}
 
開發者ID:Phenomics,項目名稱:ontolib,代碼行數:21,代碼來源:OboParser.java

示例10: assignment

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
public final AssignmentContext assignment() throws RecognitionException {
	AssignmentContext _localctx = new AssignmentContext(_ctx, getState());
	enterRule(_localctx, 4, RULE_assignment);
	try {
		enterOuterAlt(_localctx, 1);
		{
		setState(62);
		match(NAME);
		setState(63);
		match(EQ);
		setState(64);
		expr(0);
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
開發者ID:kylepls,項目名稱:Expr3,代碼行數:25,代碼來源:ExprParser.java

示例11: t0z_path_delay_expression

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
public final T0z_path_delay_expressionContext t0z_path_delay_expression() throws RecognitionException {
	T0z_path_delay_expressionContext _localctx = new T0z_path_delay_expressionContext(_ctx, getState());
	enterRule(_localctx, 380, RULE_t0z_path_delay_expression);
	try {
		enterOuterAlt(_localctx, 1);
		{
		setState(3159);
		path_delay_expression();
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
開發者ID:xprova,項目名稱:netlist-graph,代碼行數:21,代碼來源:Verilog2001Parser.java

示例12: syntaxError

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
                        int line, int charPositionInLine,
                        String msg, RecognitionException e)
{
    
   
   List<String> stack = ((Parser)recognizer).getRuleInvocationStack(); Collections.reverse(stack);
    System.err.println("rule stack: "+stack);
    System.err.println("linea "+line+":"+charPositionInLine+" at "+
    offendingSymbol+": "+msg);
    String rule = "rule stack: "+stack;
    String mensaje = "linea "+line+":"+charPositionInLine+" at "+
    offendingSymbol+": "+msg + "\n\r";
   
   
   agregarLog("Un error inesperado ha ocurrido " +"\n" + mensaje, line, charPositionInLine,true);
    
    
}
 
開發者ID:fcpauldiaz,項目名稱:Compilador,代碼行數:21,代碼來源:DescriptiveErrorListener.java

示例13: trise_path_delay_expression

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
public final Trise_path_delay_expressionContext trise_path_delay_expression() throws RecognitionException {
	Trise_path_delay_expressionContext _localctx = new Trise_path_delay_expressionContext(_ctx, getState());
	enterRule(_localctx, 370, RULE_trise_path_delay_expression);
	try {
		enterOuterAlt(_localctx, 1);
		{
		setState(3149);
		path_delay_expression();
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
開發者ID:xprova,項目名稱:netlist-graph,代碼行數:21,代碼來源:Verilog2001Parser.java

示例14: t01_path_delay_expression

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
public final T01_path_delay_expressionContext t01_path_delay_expression() throws RecognitionException {
	T01_path_delay_expressionContext _localctx = new T01_path_delay_expressionContext(_ctx, getState());
	enterRule(_localctx, 376, RULE_t01_path_delay_expression);
	try {
		enterOuterAlt(_localctx, 1);
		{
		setState(3155);
		path_delay_expression();
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
開發者ID:xprova,項目名稱:netlist-graph,代碼行數:21,代碼來源:Verilog2001Parser.java

示例15: testObjectArray

import org.antlr.v4.runtime.RecognitionException; //導入依賴的package包/類
@Test
public void testObjectArray() throws RecognitionException, JssdParserException, IOException {
  final Iterable<JObject> objects = getObjects("[{\"text\": <String> \"one\"},{\"value\": <int> 2}]");
  final Iterator<JObject> iterator = objects.iterator();
  assertObject(iterator.next(),//
      new String[]{},//
      new String[]{ "text" },//
      new String[]{ "String" },//
      new Object[]{ "one" });
  assertObject(iterator.next(),//
      new String[]{},//
      new String[]{ "value" },//
      new String[]{ "int" },
      new Object[]{ 2L }//
  );
}
 
開發者ID:AndreasWBartels,項目名稱:libraries,代碼行數:17,代碼來源:JSONSchemaDefinitionTreeParserTest.java


注:本文中的org.antlr.v4.runtime.RecognitionException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。