[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: expression parser change
- From: Kevin Vermeer <reemrevnivek@...>
- Date: Tue, 21 Dec 2010 13:47:09 -0500
On Mon, Dec 20, 2010 at 7:16 AM, Roberto Ierusalimschy <email@example.com>
> So how about more constrained version I suggested before, i.e. leaveIt has exactly the same problem:
> prefixexp in but extend it so that it can contain also literal
> - prefixexp ::= var | functioncall | ‘(’ exp ‘)’
> + prefixexp ::= var | functioncall | ‘(’ exp ‘)’ | String
a = "hellooo"
(print or io.write)(a)Moreover, it is too ad-hoc. We justify parentheses as the only
exception because everything else fits inside them. But to allow
parentheses plus strings, because that is what happens to be useful
right now, is not a good argument.
A real-life example of code that would break in a different fashion, that I (and others, I'm sure) have used many times is code like the following line:
-- Get stdout stream by running "cmd", convert to string, and trim it.
local cmd = io.popen "cmd":read "*a":gsub("^%s*(.-)%s*$", "%1")
The current policy allows the ':' operator to work as a pipe between these functions. The proposed change would, unfortunately, try to call 'read' on the string "cmd" and gsub on the string "*a". This would require changing such pipes to either break to multiple lines and separate assignments, or add a bunch of parentheses to get the original meaning:
local f = io.popen "cmd"
local str = f:read "*a"
local cmd = str:gsub("^%s*(.-)%s*$", "%1")
local cmd = ((io.popen "cmd"):read "*a"):gsub("^%s*(.-)%s*$", "%1")