in reply to Re^2: Break string into array
in thread Break string into array

Not only does your solution allow

my $s = q[dogs OR cats AND "flying fish" OR (shrimp AND squid)];
it parses to the same as
my $s = q[dogs OR cats OR "flying fish" OR (shrimp AND squid)];

And it also allows

my $s = q[OR dogs OR cats OR "flying fish" OR (shrimp AND squid)];

Finally, quoted strings are left quoted. A parser shouldn't return literals. If you want to differentiate between quoted and unquoted terms, you'll need to add to the parse tree.

$VAR1 = [ "OR", [ term => "dogs" ], [ term => "cats" ], [ phrase => "flying fish" ], [ "AND", [ term => "shrimp" ], [ term => "squid" ], ] ];

Replies are listed 'Best First'.
Re^4: Break string into array
by Anonymous Monk on Sep 18, 2009 at 15:23 UTC
    That is all true, but it does satisfy the OPs requirement/example :)
      No. Allowing AND and OR at the same level is explicitly disallowed by his requirements. It's clearly wrong to use AND when the string contains OR and vice-versa, even if it wasn't explicitly stated. I suppose there's no harm is allowing a leading OR or AND. Finally, the parser also didn't do it's job wrt quoted strings. A parser that doesn't parse is buggy.