lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, May 24, 2020 at 7:55 PM Francisco Olarte wrote:
> And how do you parse "{a=1,b=2}", as ["a"]=1,["b"]=2 or as ["a=1,b"]=2
> or, if you allow the same extension in values, ["a"]="1,b=2" ?

I think the"Proposal" was to make valid

a = { "f" = "val1", 1 = "val2" }

not

a = { f = "val1", 1 = "val2" }

> You could come up with elaborate rules for all of that, but it is
> normally better to limit to simple specs, like unbracketed keys can
> only be identifiers and always parsed as strings.

Well, they are not so elaborate. If it is a valid lua literal, its
value can be used as key without [], stop (maybe there is some corner
case I can not think of right now). However I agree that this syntax
does not worth the increase of the parser complexity: you still have
to allow the [] enclosing to support complex expressions and variables
in keys, so the []-free version just for literals is redundant.

> No, it is not. In your example above, how do you differentiate betwee
> "1".."0" and 5+5 ( both written as 10 )

List:       lua-l
Subject:    Re: Question on get/setmetatable()
From:       pocomane <pocomane_7a () pocomane ! com>
Date:       2020-05-24 18:00:28
Message-ID: CAFceo-Teq9RDLQLi2qUyJajihRxx+QDGyCVLk-1FbReMmMg+NQ ()
mail ! gmail ! com
[Download RAW message or body]

On Sun, May 24, 2020 at 3:34 PM Philippe Verdy wrote:
> Oops, you're right.
> I rarely use long brackets, and absolutely never after an identifier for an \
> implicit function call without parentheses, or after any other expression. Long \
> brackets litterals (with [[...]] or [=[...]=] or with longer matching sequences of \
> "=") are very rarely used (unlike long comments where "[[...]]" or "[=[...]=]" or \
> al. immediately follows "--")

Actually I use long strings as the only argument of a function quite
often when quoting shell command line, e.g.


These expressions can not be used as keys, if you allow just the
literals to be []-free