Search in sources :

Example 1 with ReaderLineInput

use of com.teradata.jaqy.lineinput.ReaderLineInput in project jaqy by Teradata.

the class JaqyInterpreter method executeCommand.

private void executeCommand(ParseCommand cmd, boolean interactive) {
    if (!cmd.silent) {
        incCommandCount();
    }
    if (cmd.alias != null) {
        if (cmd.args == null) {
            error("error parsing argument.");
        }
        String alias = AliasManager.replaceArgs(cmd.alias, cmd.args);
        try {
            push(new ReaderLineInput(new StringReader(alias), getDirectory(), false));
        // interpret (false);
        } catch (Throwable t) {
            m_display.error(this, t);
        }
    } else {
        JaqyCommand call = cmd.call;
        if (call == null) {
            ++m_errorCount;
            m_display.error(this, "unknown command: " + cmd.cmd);
            return;
        }
        try {
            call.execute(cmd.args, cmd.silent, this);
        } catch (Throwable t) {
            ++m_errorCount;
            m_display.error(this, t);
        }
    }
}
Also used : StringReader(java.io.StringReader) ReaderLineInput(com.teradata.jaqy.lineinput.ReaderLineInput)

Example 2 with ReaderLineInput

use of com.teradata.jaqy.lineinput.ReaderLineInput in project jaqy by Teradata.

the class IfCommand method parse.

@Override
public void parse(String action, Object value, boolean silent, Globals globals, JaqyInterpreter interpreter) throws IOException {
    globals.log(Level.INFO, "if condition = " + value);
    Display display = interpreter.getDisplay();
    if (value != null && (Boolean) value) {
        globals.log(Level.INFO, "running if statement");
        globals.log(Level.INFO, action);
        globals.log(Level.INFO, "end if statement");
        interpreter.interpret(new ReaderLineInput(new StringReader(action), interpreter.getDirectory(), false), false);
        if (!silent) {
            display.echo(interpreter, ".end " + getName(), false);
        }
    } else {
        if (!silent) {
            String[] lines = action.split("\n");
            for (String line : lines) {
                display.echo(interpreter, "-- skip: " + line, false);
            }
            display.echo(interpreter, ".end " + getName(), false);
        }
    }
}
Also used : StringReader(java.io.StringReader) ReaderLineInput(com.teradata.jaqy.lineinput.ReaderLineInput) Display(com.teradata.jaqy.interfaces.Display)

Example 3 with ReaderLineInput

use of com.teradata.jaqy.lineinput.ReaderLineInput in project jaqy by Teradata.

the class Main method loadInit.

private static void loadInit(Globals globals, JaqyInterpreter interpreter, Display display, Path initFile) {
    LineInput lineInput;
    try {
        Reader reader = new InputStreamReader(Main.class.getResourceAsStream(INTERNAL_INIT_RC), "UTF-8");
        Path startDir = new FilePath(new File(System.getProperty("user.dir")));
        lineInput = new ReaderLineInput(reader, startDir, false);
        interpreter.push(lineInput);
        interpreter.interpret(false);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    if (initFile != null && initFile.exists()) {
        // check if ~/.jqrc exists
        try {
            lineInput = LineInputFactory.getLineInput(initFile, null, false);
            interpreter.push(lineInput);
            interpreter.interpret(false);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : FilePath(com.teradata.jaqy.path.FilePath) Path(com.teradata.jaqy.interfaces.Path) FilePath(com.teradata.jaqy.path.FilePath) ReaderLineInput(com.teradata.jaqy.lineinput.ReaderLineInput) JLineConsoleLineInput(com.teradata.jaqy.lineinput.JLineConsoleLineInput) LineInput(com.teradata.jaqy.interfaces.LineInput) CommandLineInput(com.teradata.jaqy.lineinput.CommandLineInput) ReaderLineInput(com.teradata.jaqy.lineinput.ReaderLineInput)

Aggregations

ReaderLineInput (com.teradata.jaqy.lineinput.ReaderLineInput)3 StringReader (java.io.StringReader)2 Display (com.teradata.jaqy.interfaces.Display)1 LineInput (com.teradata.jaqy.interfaces.LineInput)1 Path (com.teradata.jaqy.interfaces.Path)1 CommandLineInput (com.teradata.jaqy.lineinput.CommandLineInput)1 JLineConsoleLineInput (com.teradata.jaqy.lineinput.JLineConsoleLineInput)1 FilePath (com.teradata.jaqy.path.FilePath)1