lua-users home
lua-l archive

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


On Wed, Nov 30, 2011 at 9:59 PM, Xavier Wang <weasley.wx@gmail.com> wrote:
> the metalua use two :gsub to turn string escapes to correct byte, but
> a "\92" escape will confuse the lexer, the patch is below:
> --- a/src/compiler/lexer.lua
> +++ b/src/compiler/lexer.lua
> @@ -92,8 +92,8 @@ local function unescape_string (s)
>    end
>
>    return s
> -      :gsub ("(\\+)([0-9][0-9]?[0-9]?)", unesc_digits)
>       :gsub ("\\(%D)",unesc_letter)
> +      :gsub ("(\\+)([0-9][0-9]?[0-9]?)", unesc_digits)
>  end

Careful: assert(unescape_string [[\\116]] == [[\116]]) would fail due
to %D matching a backslash.

An attempt was already recently made to correct this bug in the
'spaceinfo' branch [1].  (Most of the active Metalua development in
recent weeks has been done in the spaceinfo branch.)

Test cases will need to be added though since chained gsub's like this
can be difficult to reason about.  Moreover, the subsequent patches in
spaceinfo [2] to add Lua 5.2 lexing support (hex escapes) add
additional gsubs to the chain.

(BTW, there's also a dedicated Metalua mailing list [3] .)

[1] https://github.com/fab13n/metalua/commit/a8d75dc81127b91fc9fa9dcaf70a697357dc44f1
[2] https://github.com/fab13n/metalua/blob/spaceinfo/src/compiler/lexer.lua
[3] http://groups.google.com/group/metalua