Subject: | Shell::Parser bug and suggestion |
Date: | Tue, 19 Apr 2011 18:11:34 -0400 (EDT) |
To: | bug-shell-parser [...] rt.cpan.org |
From: | Eli the Bearded <eli [...] panix.com> |
Hello,
From the "Copyright 2004", maybe you are long past caring, but
I was looking at Shell::Parser and noticed some issues with it.
In your own example of parsing:
#!/bin/sh
if [ "$text" != "" ]; then grep "$text" file.txt; fi
The trace output contains:
text: <"$text">
text: < >
assign: <!=>
text: < >
text: <"">
But there is no assignment going on there, that should be text.
Unlike perl, shells are really strict about whitespace around =,
so "varname = value" is not acceptable. The "$text", !=, and ""
strings are parameters to the <[> command, which is a synonym
for <test>.
I'd also consider it a bug that you do not group together the $IFS
whitespace into a single token. Nor do you distinguish types of
quoted string.
$parser->parse(q*echo "The $cow \"jumps\" over "'the $moon' && $again*);
gives output:
text: <echo>
text: < >
text: <"The $cow \"jumps\" over "'the $moon'>
text: < >
text: < >
metachar: <&>
metachar: <&>
text: < >
variable: <$again>
When I'd expect:
text: <echo>
ifs: < >
dquoted: <"The $cow \"jumps\" over ">
squoted: <'the $moon'>
ifs: < >
metachar: <&>
metachar: <&>
ifs: < >
variable: <$again>
One more thing is that your set of shell syntax definitions is lacking.
My ksh has an <enum> builtin, but that's not in your syntax. Rather
than try to correct the reasonable defaults, I'd suggest way to
define a custom syntax. See attached patch.
Elijah
Message body is not shown because sender requested not to inline it.