lua-users home
lua-l archive

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


> * There is no definition of the formal syntax of a String in the EBNF,
> though there is in the prose of section 3.1. I suppose that this regex
> should match, though I've not tested extensively. Any refinements are
> welcome:
> /(?:"(?:[^\\"]|\\[abfnrtvz\\"']|\\\n|\\\d{1,3}|\\x[\da-fA-F]{2})*")|(?:'(?:[^\\']|\\[abfnrtvz\\"']|\\\n|\\\d{1,3}|\\x[\da-fA-F]{2})*')|(?:--\[(=*)\[\.+?\]\1\])/m

I am afraid I cannot read this very well. But I think the '[^\\"]'
in the beginning should be at least '[^\\"\n\r]' (or classes, by default,
excludes these characters?).

Also, the last part should not include '--' in the beginning.


> * There is no definition of the formal syntax of a Number. Based on experimentation, it looks like this might be a valid regex for matching a Lua number:
> /-?\d*\.?\d+(e[-+]?\d+)?/i
> Anyone see anything wrong with that?

- A '-' is not part of a number (for the lexer). Otherwise, x-3 would
be read as 'x' followed by '-3'.

- The definition of a numeral in Lua follows C (which, in retrospect,
may not have been a very good idea). So, things like "3." are correct,
too.

- Lua accepts hexadecimal numerals. (In 5.2, that includes floating-point
hexas too.)

-- Roberto