Search in sources :

Example 1 with CppFilterReader

use of net.sourceforge.processdash.util.CppFilterReader in project processdash by dtuma.

the class DataRepository method loadDatafile.

private String loadDatafile(String filename, Reader datafile, Map dest, boolean followIncludes, boolean close) throws FileNotFoundException, IOException, InvalidDatafileFormat {
    //debug("loadDatafile("+filename+")");
    // Initialize data, file, and read buffer.
    BufferedReader in = new BufferedReader(datafile);
    FileLoader loader = new FileLoader(dest, followIncludes);
    String defineDecls = null;
    if (filename != null)
        defineDecls = (String) defineDeclarations.get(filename);
    defineDecls = prependGlobalDefineDeclarations(defineDecls);
    try {
        CppFilterReader readIn = new CppFilterReader(in, defineDecls);
        Parser p = new Parser(new Lexer(new PushbackReader(readIn, 1024)));
        // Parse the file.
        Start tree = p.parse();
        // Apply the file loader.
        tree.apply(loader);
    } catch (ParserException pe) {
        String message = "Could not parse " + filename + "; " + pe.getMessage();
        TemplateLoader.logTemplateError(message);
        throw new InvalidDatafileFormat(message);
    } catch (LexerException le) {
        String message = "Could not parse " + filename + "; " + le.getMessage();
        TemplateLoader.logTemplateError(message);
        throw new InvalidDatafileFormat(message);
    } catch (LoadingException load) {
        Exception root = load.getRoot();
        if (root instanceof FileNotFoundException)
            throw (FileNotFoundException) root;
        if (root instanceof IOException)
            throw (IOException) root;
        if (root instanceof InvalidDatafileFormat)
            throw (InvalidDatafileFormat) root;
        System.err.println("Unusual exception when loading file: " + root);
        root.printStackTrace();
        throw new IOException(root.getMessage());
    } finally {
        if (close)
            in.close();
    }
    return loader.getInheritedDatafile();
}
Also used : ParserException(net.sourceforge.processdash.data.compiler.parser.ParserException) Start(net.sourceforge.processdash.data.compiler.node.Start) FileNotFoundException(java.io.FileNotFoundException) EscapeString(net.sourceforge.processdash.util.EscapeString) IOException(java.io.IOException) MalformedValueException(net.sourceforge.processdash.data.MalformedValueException) PatternSyntaxException(java.util.regex.PatternSyntaxException) FileNotFoundException(java.io.FileNotFoundException) ConcurrentModificationException(java.util.ConcurrentModificationException) LexerException(net.sourceforge.processdash.data.compiler.lexer.LexerException) IOException(java.io.IOException) CompilationException(net.sourceforge.processdash.data.compiler.CompilationException) ParserException(net.sourceforge.processdash.data.compiler.parser.ParserException) ExecutionException(net.sourceforge.processdash.data.compiler.ExecutionException) Parser(net.sourceforge.processdash.data.compiler.parser.Parser) PushbackReader(java.io.PushbackReader) Lexer(net.sourceforge.processdash.data.compiler.lexer.Lexer) CppFilterReader(net.sourceforge.processdash.util.CppFilterReader) BufferedReader(java.io.BufferedReader) LexerException(net.sourceforge.processdash.data.compiler.lexer.LexerException)

Aggregations

BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PushbackReader (java.io.PushbackReader)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 MalformedValueException (net.sourceforge.processdash.data.MalformedValueException)1 CompilationException (net.sourceforge.processdash.data.compiler.CompilationException)1 ExecutionException (net.sourceforge.processdash.data.compiler.ExecutionException)1 Lexer (net.sourceforge.processdash.data.compiler.lexer.Lexer)1 LexerException (net.sourceforge.processdash.data.compiler.lexer.LexerException)1 Start (net.sourceforge.processdash.data.compiler.node.Start)1 Parser (net.sourceforge.processdash.data.compiler.parser.Parser)1 ParserException (net.sourceforge.processdash.data.compiler.parser.ParserException)1 CppFilterReader (net.sourceforge.processdash.util.CppFilterReader)1 EscapeString (net.sourceforge.processdash.util.EscapeString)1