Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: $(...) and <<



On Jul 31,  5:42pm, Peter Stephenson wrote:
} Subject: Re: $(...) and <<
}
} > } $ zsh -c 'echo $(cat << EOF
} > } blah)
} > } EOF
} > } ); echo test'
} > } zsh:4: parse error near `)'
} 
} - Check if it looks like $( ... ) or $(( ... ) ... ) but not $(( ... ))
} as before, in other words we have to guess if it's $( ... ) by looking
} for a stray ")" that might actually not be the end of the command
} substitution but probably implies it's not a $(( ... )) substitution.
} A bit icky but we've done worse.
} 
} - Re-enter the parser at this point within the lexer and keep going

I tried this a couple of different ways but always ended up with one or
more of the "make check" tests failing because I wasn't backtracking
properly after discovering that the first ")" wasn't a "))".  It's also
fairly ugly to discover that the first ")" in "$( ... ) ... )" is NOT
closing the expression unless you are already in the parser.

What it seems realy needs to happen is to always attempt to parse math
at "$((" and if that fails, back up to the second "(" and attempt to
parse shell code.  But that can require arbitrary lookahead ... which
is no worse than attempting to consume everything up to ")" as a string
and then parse it, but (as you mentioned) a bit harder to extract the
result because it's passing through the parser rather than lexer.



Messages sorted by: Reverse Date, Date, Thread, Author