Search in sources :

Example 1 with LexerGenerator

use of org.apache.asterix.lexergenerator.LexerGenerator in project asterixdb by apache.

the class LexerGeneratorMojo method execute.

public void execute() throws MojoExecutionException {
    LexerGenerator lexer = new LexerGenerator(getLog());
    HashMap<String, String> config = new HashMap<String, String>();
    getLog().info("--- Lexer Generator Maven Plugin - started with grammarFile: " + grammarFile.toString());
    try {
        String input = readFile(grammarFile);
        config.put("OUTPUT_DIR", outputDir.toString());
        boolean tokens = false;
        for (String line : input.split("\r?\n")) {
            line = line.trim();
            if (line.length() == 0 || line.charAt(0) == '#')
                continue;
            if (tokens == false && !line.equals("TOKENS:")) {
                config.put(line.split("\\s*:\\s*")[0], line.split("\\s*:\\s*")[1]);
            } else if (line.equals("TOKENS:")) {
                tokens = true;
            } else {
                lexer.addToken(line);
            }
        }
        lexer.generateLexer(config);
    } catch (Throwable e) {
        throw new MojoExecutionException("Error while generating lexer", e);
    }
    String parsedGrammar = lexer.printParsedGrammar();
    getLog().info("--- Generated grammar:\n" + parsedGrammar);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) LexerGenerator(org.apache.asterix.lexergenerator.LexerGenerator)

Aggregations

HashMap (java.util.HashMap)1 LexerGenerator (org.apache.asterix.lexergenerator.LexerGenerator)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1