From: Massimiliano Mirra Date: 2002-02-05T03:14:58+09:00 Subject: Re: bash-like command splitting (for regexp wizards) On Mon, Feb 04, 2002 at 11:57:23AM +0900, Jeff 'japhy' Pinyan wrote: > >dividers = ['\|\|', '&&', ';'] > >divs = dividers.collect {|div| "(#{div})"}.join('|') ^ ^ > That regex does not do what you think it does... > > /([^jeff]+)|jeff/ > > does not mean "one or more non-jeff's in a row, OR jeff", but rather "one > or more non-j's, non-e's, and non-f's in a row, OR jeff". But that regex is (note parentheses above): /([^(\|\|)|(&&)|(;)]+|(\|\|)|(&&)|(;)/ > >'ls || cd dir; grep "word; sentence" && beep' > This is a job for a more explicit parser -- one that recognizes quotes and > escapes and all. Now that I've seen what the solution looks like, I agree. Before heading for regexps to solve this, I tried to get the hang of yacc/bison and still keep my sanity, but I have little background in C and none at all in parsers. I am trying out rockit, which feels much better to me than yacc/bison-like, however it is still in alpha stage. Can someone point out some easy, task-oriented yacc documentation (if any such thing exists)? All I've found is very feature-oriented, I'd prefer (shall I say need?) something in the ``to get this, do this'' style. > I come from a Perl background, so I apologize if my Ruby isn't quite as > idiomatic as many might be used to. > SPLIT_RE = %r{ > \|\| > | > ; [...] Wow. Do you all come to Perl with a degree in Egyptology or do you get one honoris causa afterwards? :-) Thanks a lot! Massimiliano