Search in sources :

Example 36 with PushbackReader

use of java.io.PushbackReader in project processdash by dtuma.

the class GlobEngine method compile.

private static Start compile(String expression) {
    Start result = (Start) COMPILED_EXPRESSIONS.get(expression);
    if (result == null) {
        try {
            Parser p = new Parser(new Lexer(new PushbackReader(new StringReader(expression), 1024)));
            // Parse the input
            result = p.parse();
        } catch (Exception e) {
            logger.warning("Invalid glob expression: " + expression);
            e.printStackTrace();
        }
    }
    return result;
}
Also used : Lexer(net.sourceforge.processdash.util.glob.lexer.Lexer) Start(net.sourceforge.processdash.util.glob.node.Start) StringReader(java.io.StringReader) Parser(net.sourceforge.processdash.util.glob.parser.Parser) PushbackReader(java.io.PushbackReader)

Example 37 with PushbackReader

use of java.io.PushbackReader 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

PushbackReader (java.io.PushbackReader)37 IOException (java.io.IOException)22 StringReader (java.io.StringReader)12 CompileException (com.googlecode.prolog_cafe.exceptions.CompileException)3 JavaObjectTerm (com.googlecode.prolog_cafe.lang.JavaObjectTerm)3 SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)3 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 StructureTerm (com.googlecode.prolog_cafe.lang.StructureTerm)2 FileNotFoundException (java.io.FileNotFoundException)2 LineNumberReader (java.io.LineNumberReader)2 Lexer (net.sourceforge.processdash.data.compiler.lexer.Lexer)2 Parser (net.sourceforge.processdash.data.compiler.parser.Parser)2 SyntaxException (com.googlecode.prolog_cafe.exceptions.SyntaxException)1 TermException (com.googlecode.prolog_cafe.exceptions.TermException)1 BufferingPrologControl (com.googlecode.prolog_cafe.lang.BufferingPrologControl)1 ListTerm (com.googlecode.prolog_cafe.lang.ListTerm)1 Term (com.googlecode.prolog_cafe.lang.Term)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1