lua-users home
lua-l archive

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

>> local i --[[:integer]] = 0
>> Ravi could parse the --[[: prelude and treat it as a type annotation,
>> while Lua will simply ignore it. This is what some typed Javascript
>> tools do.
>> /s/ Adam
> This seems great to me. Ravi (or others) can parse the clean way and
> the commented way.
> A filter could convert code in both directions, if needed.
> If inline comments were a common way to do something like this,
> perhaps a more terse inline comment (perhaps with special
> restrictions, such as no nesting or it ends when when an = sign is
> present, as you're suggesting) would make some sense.

I took the same approach with integrating typedlua syntax into
ZeroBrane Studio analyzer (in a separate branch:

One can write:

--[[interface Shape
  const new:(self, number, number) -> (self)
local Shape = require "shape"
--[[const]] function Shape:new(x --[[:number]], y --[[:number]])
print(self, x, y) return self end
local shape --[[:Shape]] = Shape:new(10, 10)

to get it properly parsed by (extended) typedlua analyzer. The
"standard" typedlua syntax is also supported, but this approach allows
to skip the compilation step and still get the type information into
consideration during static analysis.