本文整理汇总了Java中org.antlr.runtime.Parser类的典型用法代码示例。如果您正苦于以下问题:Java Parser类的具体用法?Java Parser怎么用?Java Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Parser类属于org.antlr.runtime包,在下文中一共展示了Parser类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: syntaxError
import org.antlr.runtime.Parser; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void syntaxError(BaseRecognizer recognizer, String[] tokenNames, RecognitionException e)
{
String hdr = recognizer.getErrorHeader(e);
String msg = recognizer.getErrorMessage(e, tokenNames);
StringBuilder builder = new StringBuilder().append(hdr)
.append(' ')
.append(msg);
if (recognizer instanceof Parser)
appendQuerySnippet((Parser) recognizer, builder);
errorMsgs.add(builder.toString());
}
示例2: createParser
import org.antlr.runtime.Parser; //导入依赖的package包/类
/** Creates a parser for a given term, generating trees of this kind. */
public <P extends Parser> P createParser(Class<P> parserType, I info, String term) {
try {
// find the lexer type
String parserName = parserType.getName();
String lexerName = parserName.substring(0, parserName.indexOf("Parser"))
.concat("Lexer");
@SuppressWarnings("unchecked") Class<? extends Lexer> lexerType =
(Class<? extends Lexer>) Class.forName(lexerName);
Lexer lexer = createLexer(lexerType, info, term);
// instantiate the parser
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
Constructor<P> parserConstructor = parserType.getConstructor(TokenStream.class);
P result = parserConstructor.newInstance(tokenStream);
Method adaptorSetter = parserType.getMethod("setTreeAdaptor", TreeAdaptor.class);
adaptorSetter.invoke(result, new ParseTreeAdaptor<>(this, info, tokenStream));
callInitialise(result, info);
return result;
} catch (Exception e) {
throw toRuntime(e);
}
}
示例3: appendQuerySnippet
import org.antlr.runtime.Parser; //导入依赖的package包/类
/**
* Appends a query snippet to the message to help the user to understand the problem.
*
* @param parser the parser used to parse the query
* @param builder the <code>StringBuilder</code> used to build the error message
*/
private void appendQuerySnippet(Parser parser, StringBuilder builder)
{
TokenStream tokenStream = parser.getTokenStream();
int index = tokenStream.index();
int size = tokenStream.size();
Token from = tokenStream.get(getSnippetFirstTokenIndex(index));
Token to = tokenStream.get(getSnippetLastTokenIndex(index, size));
Token offending = tokenStream.get(getOffendingTokenIndex(index, size));
appendSnippet(builder, from, to, offending);
}
示例4: getParserErrorMessage
import org.antlr.runtime.Parser; //导入依赖的package包/类
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;
}
示例5: buildKeywordEscapeIdentifier
import org.antlr.runtime.Parser; //导入依赖的package包/类
public Object buildKeywordEscapeIdentifier(Parser parser, TreeAdaptor adaptor, Object tree) {
CommonTree ct = (CommonTree)tree;
String txt = ct.getText();
if (txt == null) {
CommonToken leftToken = (CommonToken) parser.getTokenStream().get(ct.getTokenStartIndex());
CommonToken rightToken = (CommonToken) parser.getTokenStream().get(ct.getTokenStopIndex());
txt = leftToken.getInputStream().substring(leftToken.getStartIndex(), rightToken.getStopIndex());
}
return adaptor.create(TokenTypes.Regular_Identifier, ct.getToken(), /*ct.getText()*/txt);
}
示例6: execParser
import org.antlr.runtime.Parser; //导入依赖的package包/类
public Object execParser(
String ruleName,
String input,
int scriptLine)
throws Exception
{
ANTLRStringStream is = new ANTLRStringStream(input);
Class<? extends TokenSource> lexerClass = Class.forName(lexerClassName).asSubclass(TokenSource.class);
Constructor<? extends TokenSource> lexConstructor = lexerClass.getConstructor(CharStream.class);
TokenSource lexer = lexConstructor.newInstance(is);
is.setLine(scriptLine);
CommonTokenStream tokens = new CommonTokenStream(lexer);
Class<? extends Parser> parserClass = Class.forName(parserClassName).asSubclass(Parser.class);
Constructor<? extends Parser> parConstructor = parserClass.getConstructor(TokenStream.class);
Parser parser = parConstructor.newInstance(tokens);
// set up customized tree adaptor if necessary
if ( adaptorClassName!=null ) {
Method m = parserClass.getMethod("setTreeAdaptor", TreeAdaptor.class);
Class<? extends TreeAdaptor> adaptorClass = Class.forName(adaptorClassName).asSubclass(TreeAdaptor.class);
m.invoke(parser, adaptorClass.newInstance());
}
Method ruleMethod = parserClass.getMethod(ruleName);
// INVOKE RULE
return ruleMethod.invoke(parser);
}
示例7: getDelegates
import org.antlr.runtime.Parser; //导入依赖的package包/类
public Parser[] getDelegates() {
return new Parser[] {};
}
示例8: getDelegates
import org.antlr.runtime.Parser; //导入依赖的package包/类
public Parser[] getDelegates() {
return new Parser[] {gParser};
}
示例9: getDelegates
import org.antlr.runtime.Parser; //导入依赖的package包/类
public Parser[] getDelegates() {
return new Parser[] {};
}
示例10: getDelegates
import org.antlr.runtime.Parser; //导入依赖的package包/类
public Parser[] getDelegates()
{
return new Parser[] {};
}
示例11: buildIdentifier
import org.antlr.runtime.Parser; //导入依赖的package包/类
public Object buildIdentifier(Parser parser, TreeAdaptor adaptor, String text) {
return adaptor.create(TokenTypes.Regular_Identifier, text);
}
示例12: extractLine
import org.antlr.runtime.Parser; //导入依赖的package包/类
public String extractLine(Parser parser, RecognitionException e) {
return extractLine(parser.getTokenStream(), e);
}
示例13: CLParserHelper
import org.antlr.runtime.Parser; //导入依赖的package包/类
public CLParserHelper(Parser parser) {
this.parser = parser;
clObject = new CLObject();
}
示例14: getDelegates
import org.antlr.runtime.Parser; //导入依赖的package包/类
public Parser[] getDelegates() {
return new Parser[] {};
}