From: g0dil Date: Wed, 1 Sep 2010 21:03:57 +0000 (+0000) Subject: Utils/Console: Add support for quoted path components X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=e51092f863379f57e46063900168b059d3dc1167;p=senf.git Utils/Console: Add support for quoted path components git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1706 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Utils/Console/Executor.test.cc b/senf/Utils/Console/Executor.test.cc index 24bd307..8e56265 100644 --- a/senf/Utils/Console/Executor.test.cc +++ b/senf/Utils/Console/Executor.test.cc @@ -51,7 +51,7 @@ SENF_AUTO_UNIT_TEST(executor) { namespace fty = senf::console::factory; - senf::console::root().add("dir1",fty::Directory()).add("dir3",fty::Directory()); + senf::console::root().add("dir 1",fty::Directory()).add("dir3",fty::Directory()); senf::console::root().add("dir2",fty::Directory()).doc("Helptext").add("test",fty::Command(&testCommand)); senf::console::Executor executor; @@ -61,11 +61,11 @@ SENF_AUTO_UNIT_TEST(executor) { std::stringstream os; - parser.parse("cd dir1", &setCommand); + parser.parse("cd \"dir 1\"", &setCommand); executor(os, commands.back()); BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinCD ); - BOOST_CHECK( executor.cwd() == senf::console::root()["dir1"] ); - BOOST_CHECK_EQUAL( executor.cwdPath(), "/dir1" ); + BOOST_CHECK( executor.cwd() == senf::console::root()["dir 1"] ); + BOOST_CHECK_EQUAL( executor.cwdPath(), "/dir 1" ); BOOST_CHECK_EQUAL( os.str(), "" ); } @@ -80,7 +80,7 @@ SENF_AUTO_UNIT_TEST(executor) { std::stringstream os; - parser.parse("cd dir1", &setCommand); + parser.parse("cd \"dir 1\"", &setCommand); BOOST_CHECK_THROW( executor(os, commands.back()), senf::console::SyntaxErrorException ); BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinCD ); BOOST_CHECK( &executor.cwd() == &senf::console::root()["dir2"] ); @@ -102,14 +102,14 @@ SENF_AUTO_UNIT_TEST(executor) executor(os, commands.back()); BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLL ); BOOST_CHECK_EQUAL( os.str(), - "dir1/ \n" + "dir 1/ \n" "dir2/ Helptext\n" "sys/ \n" ); } { std::stringstream os; - parser.parse("ll dir1", &setCommand); + parser.parse("ll \"dir 1\"", &setCommand); executor(os, commands.back()); BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLL ); BOOST_CHECK_EQUAL( os.str(), "dir3/ \n" ); @@ -129,7 +129,7 @@ SENF_AUTO_UNIT_TEST(executor) executor(os, commands.back()); BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLR ); BOOST_CHECK_EQUAL( os.str().substr(0,213), - "dir1/ \n" + "dir 1/ \n" " dir3/ \n" "dir2/ Helptext\n" " test \n" @@ -138,10 +138,10 @@ SENF_AUTO_UNIT_TEST(executor) { std::stringstream os; - parser.parse("dir1/dir3 { }", &setCommand); + parser.parse("\"dir 1\"/dir3 { }", &setCommand); executor(os, commands.rbegin()[1]); BOOST_CHECK_EQUAL( commands.rbegin()[1].builtin(), senf::console::ParseCommandInfo::BuiltinPUSHD ); - BOOST_CHECK( &executor.cwd() == &senf::console::root()["dir1"]["dir3"] ); + BOOST_CHECK( &executor.cwd() == &senf::console::root()["dir 1"]["dir3"] ); BOOST_CHECK_EQUAL( os.str(), "" ); } @@ -178,7 +178,7 @@ SENF_AUTO_UNIT_TEST(executor) } commands.clear(); - senf::console::root().remove("dir1"); + senf::console::root().remove("dir 1"); senf::console::root().remove("dir2"); } diff --git a/senf/Utils/Console/Parse.ih b/senf/Utils/Console/Parse.ih index 1fd7d2d..fffaec2 100644 --- a/senf/Utils/Console/Parse.ih +++ b/senf/Utils/Console/Parse.ih @@ -150,10 +150,10 @@ namespace detail { boost_spirit::rule, boost_spirit::rule > { - boost_spirit::rule command, path, argument, word, string, hexstring, token, - punctuation, hexbyte, balanced_tokens, simple_argument, complex_argument, builtin, - skip, statement, relpath, abspath, arguments, group_start, group_close, - statement_end, opt_path; + boost_spirit::rule command, path, argument, word, string, hexstring, + word_or_string, token, punctuation, hexbyte, balanced_tokens, simple_argument, + complex_argument, builtin, skip, statement, relpath, abspath, arguments, + group_start, group_close, statement_end, opt_path; definition(CommandGrammar const & self) { @@ -307,7 +307,7 @@ namespace detail { ; relpath - = ( word [ push_back(path_, token_) ] + = ( word_or_string [ push_back(path_, token_) ] % +ch_p('/') ) >> ( ! (+ch_p('/') ) [ push_back(path_, construct_()) ] ) ; @@ -375,6 +375,11 @@ namespace detail { pos_) ] ; + word_or_string + = word + | string + ; + hexbyte = uint_parser() [ push_back(str_, arg1) ] diff --git a/senf/Utils/Console/Parse.test.cc b/senf/Utils/Console/Parse.test.cc index a214186..3ab948b 100644 --- a/senf/Utils/Console/Parse.test.cc +++ b/senf/Utils/Console/Parse.test.cc @@ -128,10 +128,10 @@ SENF_AUTO_UNIT_TEST(commandGrammar) { ss.str(""); BOOST_CHECK( senf::console::detail::boost_spirit::parse( - "ls //foo/bar;", + "ls //foo/\"bar\";", grammar.use_parser(), grammar.use_parser() ) . full ); - BOOST_CHECK_EQUAL( ss.str(), "builtin_ls( None('')/Word('foo')/Word('bar') )\n" ); + BOOST_CHECK_EQUAL( ss.str(), "builtin_ls( None('')/Word('foo')/BasicString('bar') )\n" ); } { @@ -164,11 +164,11 @@ SENF_AUTO_UNIT_TEST(commandGrammar) { ss.str(""); BOOST_CHECK( senf::console::detail::boost_spirit::parse( - "foo/bar// {", + "foo/\"bar baz\"// {", grammar.use_parser(), grammar.use_parser() ) . full ); BOOST_CHECK_EQUAL( ss.str(), - "beginCommand( Word('foo')/Word('bar')/None('') )\n" + "beginCommand( Word('foo')/BasicString('bar baz')/None('') )\n" "pushDirectory()\n" "endCommand()\n" ); } @@ -355,7 +355,7 @@ SENF_AUTO_UNIT_TEST(parseExceptions) CheckParseEx( "/foo/bar;\n ()", "path expected\nat :2:3" ); CheckParseEx( "cd /foo/bar foo/bar", "end of statement expected\nat :1:13" ); CheckParseEx( "/foo/bar foo /", "end of statement expected\nat :1:14" ); - CheckParseEx( "cd \"foo\"", "path expected\nat :1:4" ); + CheckParseEx( "cd (foo)", "path expected\nat :1:4" ); CheckParseEx( "/foo/bar \"string", "'\"' expected\nat :1:17" ); CheckParseEx( "/foo/bar x\"hi\"", "'\"' expected\nat :1:12" ); CheckParseEx( "/foo/bar (", "')' expected\nat :1:11" );