[Mulgara-svn] r802 - trunk/src/jar/itql/java/org/mulgara/itql
pag at mulgara.org
pag at mulgara.org
Mon Apr 21 22:12:42 UTC 2008
Author: pag
Date: 2008-04-21 15:12:40 -0700 (Mon, 21 Apr 2008)
New Revision: 802
Modified:
trunk/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java
trunk/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java
trunk/src/jar/itql/java/org/mulgara/itql/TqlSession.java
trunk/src/jar/itql/java/org/mulgara/itql/TqlSessionUI.java
Log:
Fixes #93
Incomplete commands are now detected and individual lines are accumulated until a complete command is available.
TODO: partial commands which share a single line
Modified: trunk/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java
===================================================================
--- trunk/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java 2008-04-21 08:05:47 UTC (rev 801)
+++ trunk/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java 2008-04-21 22:12:40 UTC (rev 802)
@@ -104,7 +104,7 @@
return true;
}
if (cmd == null) {
- lastMessage = "";
+ lastMessage = null;
return true;
}
@@ -120,6 +120,8 @@
lastMessage = "Error: " + e.getMessage();
}
+ assert lastMessage != null;
+
// test if the command wants the user to quit - return false if it does
return !(cmd.isLocalOperation() && ((LocalCommand)cmd).isQuitCommand());
}
Modified: trunk/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java
===================================================================
--- trunk/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java 2008-04-21 08:05:47 UTC (rev 801)
+++ trunk/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java 2008-04-21 22:12:40 UTC (rev 802)
@@ -191,6 +191,7 @@
// Reset the variable incrementer in the query.
variableFactory.reset();
+ resetInterpreter();
// log the iTQL command - system property itql.command.log must be set
@@ -215,7 +216,6 @@
commandTree = parser.parse();
// Build the command. This populates lastCommand
- resetInterpreter();
commandTree.apply(this);
if (logger.isDebugEnabled()) logger.debug("Successfully parsed command " + command);
Modified: trunk/src/jar/itql/java/org/mulgara/itql/TqlSession.java
===================================================================
--- trunk/src/jar/itql/java/org/mulgara/itql/TqlSession.java 2008-04-21 08:05:47 UTC (rev 801)
+++ trunk/src/jar/itql/java/org/mulgara/itql/TqlSession.java 2008-04-21 22:12:40 UTC (rev 802)
@@ -59,7 +59,7 @@
public final static String PS1 = "TQL> ";
/** The secondary prompt, indicating an incomplete command. */
- public final static String PS2 = " ";
+ public final static String PS2 = "---> ";
/** The log4j configuration file path (within the JAR file) */
private final static String LOG4J_CONFIG_PATH = "log4j-tql.xml";
@@ -104,8 +104,10 @@
/** A functor for splitting commands apart. */
private CommandSplitter commandSplitter = null;
+
+ /** A flag to indicate that an executed command was complete */
+ private boolean incomplete = false;
-
/**
* Start an interactive TQL session from the command prompt.
* @param args command line parameters
@@ -197,6 +199,16 @@
/**
+ * Indicates if the last issued command was complete. If not, then a semicolon was not found
+ * to terminate the command.
+ * @return <code>false</code> only if the last command was complete. <code>true</code> if it completed.
+ */
+ boolean isCommandIncomplete() {
+ return incomplete;
+ }
+
+
+ /**
* Executes a series of commands the given command. Accumulates all the
* results of these commands into the answers and messages lists.
* @param command The command to execute
@@ -206,7 +218,11 @@
answers.clear();
messages.clear();
+ // presume complete commands
+ incomplete = false;
for (String query: commandSplitter.split(command)) {
+ // clear out empty commands
+ if (incomplete) incomplete = false;
if (log.isDebugEnabled()) log.debug("Starting execution of command \"" + command + "\"");
@@ -215,6 +231,13 @@
close();
return;
}
+
+ String msg = autoTql.getLastMessage();
+ if (msg == null) {
+ if (log.isDebugEnabled()) log.debug("Need to follow on for an incomplete command.");
+ incomplete = true;
+ continue;
+ }
if (log.isDebugEnabled()) log.debug("Completed execution of commmand \"" + command + "\"");
@@ -222,7 +245,7 @@
if (e != null) log.warn("Couldn't execute command", e);
// Add the message and answer
- messages.add(autoTql.getLastMessage());
+ messages.add(msg);
Answer answer = autoTql.getLastAnswer();
if (answer != null) answers.add(answer);
Modified: trunk/src/jar/itql/java/org/mulgara/itql/TqlSessionUI.java
===================================================================
--- trunk/src/jar/itql/java/org/mulgara/itql/TqlSessionUI.java 2008-04-21 08:05:47 UTC (rev 801)
+++ trunk/src/jar/itql/java/org/mulgara/itql/TqlSessionUI.java 2008-04-21 22:12:40 UTC (rev 802)
@@ -99,6 +99,9 @@
/** Whether we are running a command still. */
private volatile boolean runningCommand = false;
+
+ /** The last command that was run. */
+ private String lastCommand = "";
/**
* Create a new UI representation.
@@ -303,7 +306,7 @@
}
// Handle back space - don't let it go too far back.
- if (e.paramString().indexOf("Backspace") != -1) {
+ if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE || e.paramString().indexOf("Backspace") != -1) {
if (text.getCaretPosition() <= cursorPosition) {
@@ -406,6 +409,11 @@
if (command.length() != 0) {
// Put the command at the end of the array.
history.add(command);
+
+ // check if we need to follow on
+ if (tqlSession.isCommandIncomplete()) command = lastCommand + command;
+ lastCommand = command + " ";
+
command = command + NEWLINE;
// If the array gets too large remove the last entry.
@@ -427,7 +435,7 @@
* Prints out the prompt.
*/
public void printPrompt() {
- print(NEWLINE + TqlSession.PROMPT);
+ print(NEWLINE + (tqlSession.isCommandIncomplete() ? TqlSession.PS2 : TqlSession.PROMPT));
historyIndex = 0;
text.repaint();
}
More information about the Mulgara-svn
mailing list