I have added two new parsers: in String class, a beast called "respectful_split" which can be used like String::split to split a string based on whitespace. However this parser adds capability to ignore spaces in quotes, and provides three quoting methods: single quotes, double quotes and slosh escapes.
Unfortunately the stylised rules weren't enough to handle the arcane parsing rules of bash, so there is also now a Bash::parse. I have also added Shell::parse to the shell abstraction which dispatches to Bash::parse in case of OS = Posix. It remains to write a Cmd::parse for OS=Win32. The PURPOSE of doing all this is to switch flx and probably scoop and pkgtool and other programs over from argument handling based on command strings to considering tool arguments as lists of strings. Using lists of strings means the arguments are pure, and can contain anything viable, such as a white space inside a filename, without quoting concerns. The quoting is deferred to a line rendering subroutine when that is required. This is especially important if the argument is a Perl regexp since they almost always contains weird characters. ==================== Micro test program below. It would be really nice if a few people would test the Bash parser to see if it works right. Incidentally, by my reading and experiment it is IMPOSSIBLE to have an argument containing a single quote in Bash (except perhaps by substitutions into already parsed arguments). ///////////////////////// var x = r" hello 'word ly' good\ ness 'grac\'ious'"; println$ "Input: [" + x + "]"; println$ "----------- Default: keep all ------------------"; var r = respectful_split x; for i in r do println$ i; done println$ "----------- Unquote ------------------"; var action = ( quote=RespectfulParser::drop-quote, dquote=RespectfulParser::drop-dquote, escape=RespectfulParser::drop-escape ); r = respectful_split action x; for i in r do println$ i; done println$ "----------- Windows Command Line ------------------"; var windows = ( quote=RespectfulParser::drop-quote, dquote=RespectfulParser::drop-dquote, escape=RespectfulParser::ignore-escape ); r = respectful_split windows x; for i in r do println$ i; done println$ "----------- Bash Command Line ------------------"; var bash = ( quote=RespectfulParser::drop-quote, dquote=RespectfulParser::drop-dquote, escape=RespectfulParser::keep-escape ); r = respectful_split bash x; for i in r do println$ i; done println$ "----------- Dedicated Bash parser ------------------"; var p = Bash::parse x; for i in p do println$ i; done var x2 = catmap ' ' Bash::quote_arg p; println$ x2; var p2 = Bash::parse x2; for i in p2 do println$ i; done -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the endpoint security space. For insight on selecting the right partner to tackle endpoint security challenges, access the full report. http://p.sf.net/sfu/symantec-dev2dev _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language