lua-users home
lua-l archive

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


Peter Cawley wrote:
I was recently writing some syntax highlighting code for Lua, and
while trying to duplicate the behaviour of the standard Lua parser, I
noticed a curious behaviour. The first two of the following examples
are completely normal. The third is unexpected to me - according the
reference manual on numbers, "A numerical constant can be written with
an optional decimal part and an optional decimal exponent", so I would
expect it to be parsed like the first example, as the parser should
stop trying to match a number at the second decimal point. The fourth
example is included for completeness; it could in theory be parsed
like the second example, or as 1. followed by . and ""

=1. ..""
1
=1 ..""
1
=1...""
stdin:1: malformed number near '1...'
=1..""
stdin:1: malformed number near '1..'

Are there are reasons why the third example is parsed like it currently is?

In the interest of speed, there is no rewind (backtracking) in the llex.c. A number is preferentially parsed, so it cannot reinterpret the thing as something else, and it borks if a user pulls stunts like '1..""'. IMHO, borking on such snippets is good...

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia