Search in sources :

Example 16 with TokenRewriteStream

use of org.antlr.runtime.TokenRewriteStream in project hive by apache.

the class ParseDriver method parseTriggerActionExpression.

public ASTNode parseTriggerActionExpression(String command) throws ParseException {
    GenericHiveLexer lexer = GenericHiveLexer.of(command, null);
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    HiveParser parser = new HiveParser(tokens);
    parser.setTreeAdaptor(adaptor);
    ParserRuleReturnScope r;
    try {
        r = parser.triggerActionExpressionStandalone();
    } catch (RecognitionException e) {
        throw new ParseException(parser.errors);
    }
    if (lexer.getErrors().size() != 0) {
        throw new ParseException(lexer.getErrors());
    } else if (parser.errors.size() != 0) {
        throw new ParseException(parser.errors);
    }
    return (ASTNode) r.getTree();
}
Also used : TokenRewriteStream(org.antlr.runtime.TokenRewriteStream) ParserRuleReturnScope(org.antlr.runtime.ParserRuleReturnScope) RecognitionException(org.antlr.runtime.RecognitionException)

Example 17 with TokenRewriteStream

use of org.antlr.runtime.TokenRewriteStream in project flink by apache.

the class HiveASTParseDriver method parse.

/**
 * Parses a command, optionally assigning the parser's token stream to the given context.
 *
 * @param command command to parse
 * @param ctx context with which to associate this parser's token stream, or null if either no
 *     context is available or the context already has an existing stream
 * @return parsed AST
 */
public HiveParserASTNode parse(String command, HiveParserContext ctx, String viewFullyQualifiedName) throws HiveASTParseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Parsing command: " + command);
    }
    HiveLexerX lexer = new HiveLexerX(new ANTLRNoCaseStringStream(command));
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    if (ctx != null) {
        if (viewFullyQualifiedName == null) {
            // Top level query
            ctx.setTokenRewriteStream(tokens);
        } else {
            // It is a view
            ctx.addViewTokenRewriteStream(viewFullyQualifiedName, tokens);
        }
        lexer.setHiveConf(ctx.getConf());
    }
    HiveASTParser parser = new HiveASTParser(tokens);
    if (ctx != null) {
        parser.setHiveConf(ctx.getConf());
    }
    parser.setTreeAdaptor(ADAPTOR);
    HiveASTParser.statement_return r = null;
    try {
        r = parser.statement();
    } catch (RecognitionException e) {
        throw new HiveASTParseException(parser.errors);
    }
    if (lexer.getErrors().size() == 0 && parser.errors.size() == 0) {
        LOG.debug("Parse Completed");
    } else if (lexer.getErrors().size() != 0) {
        throw new HiveASTParseException(lexer.getErrors());
    } else {
        throw new HiveASTParseException(parser.errors);
    }
    HiveParserASTNode tree = r.getTree();
    tree.setUnknownTokenBoundaries();
    return tree;
}
Also used : TokenRewriteStream(org.antlr.runtime.TokenRewriteStream) HiveASTParser(org.apache.flink.table.planner.delegation.hive.parse.HiveASTParser) RecognitionException(org.antlr.runtime.RecognitionException)

Example 18 with TokenRewriteStream

use of org.antlr.runtime.TokenRewriteStream in project flink by apache.

the class HiveASTParseDriver method parseHint.

/*
     * Parse a string as a query hint.
     */
public HiveParserASTNode parseHint(String command) throws HiveASTParseException {
    LOG.info("Parsing hint: " + command);
    HiveLexerX lexer = new HiveLexerX(new ANTLRNoCaseStringStream(command));
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    HiveASTHintParser parser = new HiveASTHintParser(tokens);
    parser.setTreeAdaptor(ADAPTOR);
    HiveASTHintParser.hint_return r = null;
    try {
        r = parser.hint();
    } catch (RecognitionException e) {
        throw new HiveASTParseException(parser.errors);
    }
    if (lexer.getErrors().size() == 0 && parser.errors.size() == 0) {
        LOG.info("Parse Completed");
    } else if (lexer.getErrors().size() != 0) {
        throw new HiveASTParseException(lexer.getErrors());
    } else {
        throw new HiveASTParseException(parser.errors);
    }
    return r.getTree();
}
Also used : TokenRewriteStream(org.antlr.runtime.TokenRewriteStream) HiveASTHintParser(org.apache.flink.table.planner.delegation.hive.parse.HiveASTHintParser) RecognitionException(org.antlr.runtime.RecognitionException)

Example 19 with TokenRewriteStream

use of org.antlr.runtime.TokenRewriteStream in project ceylon-compiler by ceylon.

the class CeylonVersionTool method updateModuleVersion.

private boolean updateModuleVersion(Module module, Map<String, String> updatedModuleVersions) throws IOException, RecognitionException {
    String moduleDescriptorPath = module.getUnit().getFullPath();
    CeylonLexer lexer = new CeylonLexer(new ANTLRFileStream(moduleDescriptorPath, encoding));
    TokenRewriteStream tokenStream = new TokenRewriteStream(lexer);
    CeylonParser parser = new CeylonParser(tokenStream);
    Tree.CompilationUnit cu = parser.compilationUnit();
    String v = this.confirm == Confirm.dependencies ? this.newVersion : confirm("update.module.version", module.getNameAsString(), module.getVersion(), this.newVersion);
    if (v == null) {
        return false;
    } else if (!v.isEmpty()) {
        // record the new version for this module
        updatedModuleVersions.put(module.getNameAsString(), v);
        updateModuleVersion(moduleDescriptorPath, tokenStream, cu, v);
    }
    return true;
}
Also used : ANTLRFileStream(org.antlr.runtime.ANTLRFileStream) TokenRewriteStream(org.antlr.runtime.TokenRewriteStream) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) CeylonLexer(com.redhat.ceylon.compiler.typechecker.parser.CeylonLexer) CeylonParser(com.redhat.ceylon.compiler.typechecker.parser.CeylonParser)

Aggregations

TokenRewriteStream (org.antlr.runtime.TokenRewriteStream)19 RecognitionException (org.antlr.runtime.RecognitionException)11 ParserRuleReturnScope (org.antlr.runtime.ParserRuleReturnScope)5 ANTLRFileStream (org.antlr.runtime.ANTLRFileStream)4 CeylonLexer (com.redhat.ceylon.compiler.typechecker.parser.CeylonLexer)2 CeylonParser (com.redhat.ceylon.compiler.typechecker.parser.CeylonParser)2 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)2 OutputStream (java.io.OutputStream)2 PrintStream (java.io.PrintStream)2 Path (org.apache.hadoop.fs.Path)2 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)2 QB (org.apache.hadoop.hive.ql.parse.QB)2 CeylonLexer (org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer)2 CeylonParser (org.eclipse.ceylon.compiler.typechecker.parser.CeylonParser)2 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)2 ImportModule (com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportModule)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 AccessControlException (java.security.AccessControlException)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1