Moonscript: support for modules using with statement; optionally ignore colon as part of an identifier

This commit is contained in:
Steve Donovan 2013-08-07 09:53:39 +02:00
parent 94dc198f4b
commit b87180996d
2 changed files with 10 additions and 6 deletions

View File

@ -274,11 +274,13 @@ function Moon:_init()
end
function Moon:item_follows (t,v,tok)
if t == '.' then -- enclosed in with statement
t,v = tnext(tok)
end
if t == 'iden' then
local name,t,v = v, tnext(tok) --tools.get_fun_name(tok,v)
local name,t,v = tools.get_fun_name(tok,v,'')
if name == 'class' then
name = v
--name,t,v = tools.get_fun_name(tok,v)
name,t,v = tools.get_fun_name(tok,v,'')
-- class!
return function(tags,tok)
tags:add('class','type')

View File

@ -352,10 +352,12 @@ function M.get_parameters (tok,endtoken,delim)
return args
end
-- parse a Lua identifier - contains names separated by . and :.
function M.get_fun_name (tok,first)
-- parse a Lua identifier - contains names separated by . and (optionally) :.
-- Set `colon` to be the secondary separator, '' for none.
function M.get_fun_name (tok,first,colon)
local res = {}
local t,name,sep
colon = colon or ':'
if not first then
t,name = tnext(tok)
else
@ -363,7 +365,7 @@ function M.get_fun_name (tok,first)
end
if t ~= 'iden' then return nil end
t,sep = tnext(tok)
while sep == '.' or sep == ':' do
while sep == '.' or sep == colon do
append(res,name)
append(res,sep)
t,name = tnext(tok)