From: <cr...@us...> - 2008-11-04 11:04:56
|
Revision: 4666 http://jnode.svn.sourceforge.net/jnode/?rev=4666&view=rev Author: crawley Date: 2008-11-04 11:04:49 +0000 (Tue, 04 Nov 2008) Log Message: ----------- Change shell's command line tokenizer to throw a more appropriate exception when it sees an incomplete '\' escape sequence. Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java trunk/shell/src/shell/org/jnode/shell/CommandShell.java trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java trunk/shell/src/test/org/jnode/test/shell/syntax/DefaultTokenizerTest.java Modified: trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java 2008-11-03 14:22:31 UTC (rev 4665) +++ trunk/shell/src/shell/org/jnode/shell/CommandInterpreter.java 2008-11-04 11:04:49 UTC (rev 4666) @@ -53,10 +53,9 @@ * @param partial a input to the interpreter. * @return the CommandLine represent the fragment of the supplied command * input to be completed. - * @throws ShellException + * @throws ShellException */ - Completable parsePartial(CommandShell shell, String partial) - throws ShellSyntaxException; + Completable parsePartial(CommandShell shell, String partial) throws ShellException; /** * Get the interpreter's name Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2008-11-03 14:22:31 UTC (rev 4665) +++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java 2008-11-04 11:04:49 UTC (rev 4666) @@ -649,7 +649,7 @@ } public Completable parseCommandLine(String cmdLineStr) - throws ShellSyntaxException { + throws ShellException { return interpreter.parsePartial(this, cmdLineStr); } @@ -678,7 +678,7 @@ if (cl != null) { cl.complete(completion, this); } - } catch (ShellSyntaxException ex) { + } catch (ShellException ex) { outPW.println(); // next line errPW.println("Cannot parse: " + ex.getMessage()); stackTrace(ex); Modified: trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java 2008-11-03 14:22:31 UTC (rev 4665) +++ trunk/shell/src/shell/org/jnode/shell/DefaultInterpreter.java 2008-11-04 11:04:49 UTC (rev 4666) @@ -110,8 +110,7 @@ } } - public Completable parsePartial(CommandShell shell, String line) - throws ShellSyntaxException { + public Completable parsePartial(CommandShell shell, String line) throws ShellException { Tokenizer tokenizer = new Tokenizer(line); if (!tokenizer.hasNext()) { return new CommandLine("", null); @@ -211,12 +210,13 @@ * * @param line the input String. * @param flags flags controlling the tokenization. + * @throws ShellException */ - public Tokenizer(String line, int flags) { + public Tokenizer(String line, int flags) throws ShellSyntaxException { tokenize(line, flags); } - public Tokenizer(String line) { + public Tokenizer(String line) throws ShellSyntaxException { this(line, 0); } @@ -242,7 +242,7 @@ return tokens.get(pos++); } - private void tokenize(String s, int flags) throws IllegalArgumentException { + private void tokenize(String s, int flags) throws ShellSyntaxException { int pos = 0; while (true) { @@ -271,7 +271,7 @@ switch (currentChar) { case ESCAPE_CHAR: if (pos >= s.length()) { - throw new IllegalArgumentException( + throw new ShellSyntaxException( "escape char ('\\') not followed by a character"); } char ch; Modified: trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java 2008-11-03 14:22:31 UTC (rev 4665) +++ trunk/shell/src/shell/org/jnode/shell/RedirectingInterpreter.java 2008-11-04 11:04:49 UTC (rev 4666) @@ -78,7 +78,7 @@ } public Completable parsePartial(CommandShell shell, String line) - throws ShellSyntaxException { + throws ShellException { Tokenizer tokenizer = new Tokenizer(line, REDIRECTS_FLAG); List<CommandDescriptor> commands = new LinkedList<CommandDescriptor>(); return parse(tokenizer, commands, true); Modified: trunk/shell/src/test/org/jnode/test/shell/syntax/DefaultTokenizerTest.java =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/syntax/DefaultTokenizerTest.java 2008-11-03 14:22:31 UTC (rev 4665) +++ trunk/shell/src/test/org/jnode/test/shell/syntax/DefaultTokenizerTest.java 2008-11-04 11:04:49 UTC (rev 4666) @@ -25,34 +25,35 @@ import junit.framework.TestCase; import org.jnode.shell.CommandLine; import org.jnode.shell.DefaultInterpreter; +import org.jnode.shell.ShellException; import org.jnode.shell.SymbolSource; public class DefaultTokenizerTest extends TestCase { // Expose methods for testing. private class MyDefaultInterpreter extends DefaultInterpreter { - DefaultInterpreter.Tokenizer makeTokenizer(String line) { + DefaultInterpreter.Tokenizer makeTokenizer(String line) throws ShellException { return new DefaultInterpreter.Tokenizer(line); } - DefaultInterpreter.Tokenizer makeTokenizer(String line, int flags) { + DefaultInterpreter.Tokenizer makeTokenizer(String line, int flags) throws ShellException { return new DefaultInterpreter.Tokenizer(line, flags); } } - public void testTokenizerEmpty() { + public void testTokenizerEmpty() throws ShellException { SymbolSource<CommandLine.Token> t = new MyDefaultInterpreter().makeTokenizer(""); assertEquals(false, t.hasNext()); assertEquals(false, t.whitespaceAfterLast()); } - public void testTokenizerSpaces() { + public void testTokenizerSpaces() throws ShellException { SymbolSource<CommandLine.Token> t = new MyDefaultInterpreter().makeTokenizer(" "); assertEquals(false, t.hasNext()); assertEquals(true, t.whitespaceAfterLast()); } - public void testTokenizerSimple() { + public void testTokenizerSimple() throws ShellException{ SymbolSource<CommandLine.Token> t = new MyDefaultInterpreter().makeTokenizer("a b c"); assertEquals(true, t.hasNext()); assertEquals(false, t.whitespaceAfterLast()); @@ -97,7 +98,7 @@ } } - public void testTokenizerQuotes() { + public void testTokenizerQuotes() throws ShellException { SymbolSource<CommandLine.Token> t = new MyDefaultInterpreter().makeTokenizer("'a' \"b c\""); assertEquals(true, t.hasNext()); assertEquals(false, t.whitespaceAfterLast()); @@ -112,7 +113,7 @@ assertEquals(false, t.hasNext()); } - public void testTokenizerBackslashes() { + public void testTokenizerBackslashes() throws ShellException { SymbolSource<CommandLine.Token> t = new MyDefaultInterpreter().makeTokenizer("\\'a b\\ c\\\""); assertEquals(true, t.hasNext()); assertEquals(false, t.whitespaceAfterLast()); @@ -127,7 +128,7 @@ assertEquals(false, t.hasNext()); } - public void testTokenizerBackslashes2() { + public void testTokenizerBackslashes2() throws ShellException { SymbolSource<CommandLine.Token> t = new MyDefaultInterpreter().makeTokenizer("\\\\\\n\\r\\t\\b "); assertEquals(true, t.hasNext()); assertEquals(true, t.whitespaceAfterLast()); @@ -138,7 +139,7 @@ assertEquals(false, t.hasNext()); } - public void testTokenizerRedirects() { + public void testTokenizerRedirects() throws ShellException { SymbolSource<CommandLine.Token> t = new MyDefaultInterpreter().makeTokenizer("a< >b c|d \"<\" \\< '<'", MyDefaultInterpreter.REDIRECTS_FLAG); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |