{
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;
{
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(), "" );
}
{
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"] );
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" );
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"
{
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(), "" );
}
}
commands.clear();
- senf::console::root().remove("dir1");
+ senf::console::root().remove("dir 1");
senf::console::root().remove("dir2");
}
boost_spirit::rule<Scanner>,
boost_spirit::rule<Scanner> >
{
- boost_spirit::rule<Scanner> 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<Scanner> 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)
{
;
relpath
- = ( word [ push_back(path_, token_) ]
+ = ( word_or_string [ push_back(path_, token_) ]
% +ch_p('/') )
>> ( ! (+ch_p('/') ) [ push_back(path_, construct_<Token>()) ] )
;
pos_) ]
;
+ word_or_string
+ = word
+ | string
+ ;
+
hexbyte
= uint_parser<char, 16, 2, 2>()
[ push_back(str_, arg1) ]
{
ss.str("");
BOOST_CHECK( senf::console::detail::boost_spirit::parse(
- "ls //foo/bar;",
+ "ls //foo/\"bar\";",
grammar.use_parser<Grammar::CommandParser>(),
grammar.use_parser<Grammar::SkipParser>() ) . 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" );
}
{
{
ss.str("");
BOOST_CHECK( senf::console::detail::boost_spirit::parse(
- "foo/bar// {",
+ "foo/\"bar baz\"// {",
grammar.use_parser<Grammar::CommandParser>(),
grammar.use_parser<Grammar::SkipParser>() ) . 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" );
}
CheckParseEx( "/foo/bar;\n ()", "path expected\nat <unknown>:2:3" );
CheckParseEx( "cd /foo/bar foo/bar", "end of statement expected\nat <unknown>:1:13" );
CheckParseEx( "/foo/bar foo /", "end of statement expected\nat <unknown>:1:14" );
- CheckParseEx( "cd \"foo\"", "path expected\nat <unknown>:1:4" );
+ CheckParseEx( "cd (foo)", "path expected\nat <unknown>:1:4" );
CheckParseEx( "/foo/bar \"string", "'\"' expected\nat <unknown>:1:17" );
CheckParseEx( "/foo/bar x\"hi\"", "'\"' expected\nat <unknown>:1:12" );
CheckParseEx( "/foo/bar (", "')' expected\nat <unknown>:1:11" );