svnno****@sourc*****
svnno****@sourc*****
2010年 1月 21日 (木) 19:42:52 JST
Revision: 93 http://sourceforge.jp/projects/ngms/svn/view?view=rev&revision=93 Author: osiire Date: 2010-01-21 19:42:52 +0900 (Thu, 21 Jan 2010) Log Message: ----------- [NMShell] skipWhitespace bug. [NMShell] use :quit instead of :exit Modified Paths: -------------- trunk/source/NMShell/src/info/ngms/nmshell/NMShellCommandParser.scala trunk/source/NMShell/test/CommandParserTest.scala Modified: trunk/source/NMShell/src/info/ngms/nmshell/NMShellCommandParser.scala =================================================================== --- trunk/source/NMShell/src/info/ngms/nmshell/NMShellCommandParser.scala 2010-01-15 08:21:58 UTC (rev 92) +++ trunk/source/NMShell/src/info/ngms/nmshell/NMShellCommandParser.scala 2010-01-21 10:42:52 UTC (rev 93) @@ -38,9 +38,11 @@ } object NMShellCommandParser extends RegexParsers { + override def skipWhitespace = false + def line = statements | exit - def exit = ":exit" <~ optional_spaces ^^ { case _ => Exit } + def exit = ":quit" <~ optional_spaces ^^ { case _ => Exit } def statements = rep1sep(statement, statement_sep) <~ optional_spaces ^^ { case sts => Statements(sts) @@ -91,9 +93,9 @@ } def out_case2 : Parser[OutCase] = optional_spaces ~> path ^^ { case path => OutPath(path) } - def out_redirect_symbol = (">" | ">>") ^^ { + def out_redirect_symbol = (">>" | ">") ^^ { + case ">>" => AppendRedirect case ">" => NormalRedirect - case ">>" => AppendRedirect } def file_descriptor = (number | "-") ^^ { @@ -102,20 +104,21 @@ } def number = "[1-9]+[0-9]*".r - def command = command_name ~ repsep(cmd_string, spaces) ^^ { + def command = ((command_name <~ spaces) ~ repsep(cmd_string, spaces)) ^^ { case name ~ args => new Command(name, args) } + def command_name = "[^ :<>|&`\"]+".r - def cmd_string = ("\"" ~> double_quote_escaped_string) <~ "\"" | space_escaped_string + def cmd_string = (("\"" ~> double_quote_escaped_string) <~ "\"") | space_escaped_string def double_quote_escaped_string = rep(double_quote_escaped_char) ^^ { case l => l.foldLeft ("") { (a,b) => a + b } } def double_quote_escaped_char = non_double_quote_char | double_double_quote - def non_double_quote_char = "[^\"<>|&`]".r - def double_double_quote = "\"\"" ^^ { case _ => "\"" } + def non_double_quote_char = "[^ <>|&`\"]".r + def double_double_quote = "\"\"" ^^ { _ => "\"" } def space_escaped_string = rep(space_escaped_char) ^^ { case l => l.foldLeft ("") { (a,b) => a + b } @@ -123,10 +126,10 @@ def space_escaped_char = non_space_char | escape_space_char def non_space_char = "[^ <>|&`]".r - def escape_space_char = """\ """ + def escape_space_char = "\\ " ^^ { _ => " " } def expand_command = "`" ~> command <~ "`" def spaces = " +".r def optional_spaces = opt(spaces) -} +} \ No newline at end of file Modified: trunk/source/NMShell/test/CommandParserTest.scala =================================================================== --- trunk/source/NMShell/test/CommandParserTest.scala 2010-01-15 08:21:58 UTC (rev 92) +++ trunk/source/NMShell/test/CommandParserTest.scala 2010-01-21 10:42:52 UTC (rev 93) @@ -20,6 +20,21 @@ } } + test("args") { + val input = "mkdir -v dir1 dir2" + val line = NMShellCommandParser.parse(NMShellCommandParser.line, input).get + line match { + case Exit => assert(false) + case Statements(sts) => { + assert(sts.length == 1) + assert(sts.head.cmds.head.name === "mkdir") + assert(sts.head.cmds.head.args.apply(0) === "-v") + assert(sts.head.cmds.head.args.apply(1) === "dir1") + assert(sts.head.cmds.head.args.apply(2) === "dir2") + } + } + } + test("pipe") { val input = " foo -la | bar -args " val line = NMShellCommandParser.parse(NMShellCommandParser.line, input).get @@ -40,7 +55,7 @@ } test("exit") { - val input = ":exit" + val input = ":quit" val line = NMShellCommandParser.parse(NMShellCommandParser.line, input).get line match { case Exit => ()