Tweaks and adjustments.
This commit is contained in:
parent
861d5accc0
commit
d3a5fc73bc
35
nomsu.lua
35
nomsu.lua
@ -30,13 +30,8 @@ local parsetree_mt = {
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
local ParseTree
|
local ParseTree
|
||||||
ParseTree = function(type, src, value, errors)
|
ParseTree = function(x)
|
||||||
return setmetatable({
|
return setmetatable(x, parsetree_mt)
|
||||||
type = type,
|
|
||||||
src = src,
|
|
||||||
value = value,
|
|
||||||
errors = errors
|
|
||||||
}, parsetree_mt)
|
|
||||||
end
|
end
|
||||||
local functiondef_mt = {
|
local functiondef_mt = {
|
||||||
__tostring = function(self)
|
__tostring = function(self)
|
||||||
@ -184,12 +179,20 @@ local defs = {
|
|||||||
}
|
}
|
||||||
setmetatable(defs, {
|
setmetatable(defs, {
|
||||||
__index = function(t, key)
|
__index = function(t, key)
|
||||||
local fn
|
do
|
||||||
fn = function(src, value, errors)
|
local _with_0
|
||||||
return ParseTree(key, src, value, errors)
|
_with_0 = function(src, value, errors)
|
||||||
|
return {
|
||||||
|
type = key,
|
||||||
|
src = src,
|
||||||
|
value = value,
|
||||||
|
errors = errors
|
||||||
|
}
|
||||||
|
end
|
||||||
|
t[key] = _with_0
|
||||||
|
local _ = nil
|
||||||
|
return _with_0
|
||||||
end
|
end
|
||||||
t[key] = fn
|
|
||||||
return fn
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
nomsu = re.compile(nomsu, defs)
|
nomsu = re.compile(nomsu, defs)
|
||||||
@ -209,7 +212,7 @@ do
|
|||||||
aliases = self:get_aliases(aliases)
|
aliases = self:get_aliases(aliases)
|
||||||
end
|
end
|
||||||
if self.debug then
|
if self.debug then
|
||||||
self:writeln("Defining rule: " .. tostring(aliases))
|
self:writeln("Defining rule: " .. tostring(repr(aliases)))
|
||||||
end
|
end
|
||||||
local fn_def = FunctionDef(fn, { }, src, is_macro)
|
local fn_def = FunctionDef(fn, { }, src, is_macro)
|
||||||
return self:add_aliases(aliases, fn_def)
|
return self:add_aliases(aliases, fn_def)
|
||||||
@ -287,7 +290,7 @@ do
|
|||||||
args = _tbl_0
|
args = _tbl_0
|
||||||
end
|
end
|
||||||
if self.debug then
|
if self.debug then
|
||||||
self:writeln("Calling " .. tostring(alias) .. " with args: " .. tostring(repr(args)))
|
self:writeln("Calling " .. tostring(repr(alias)) .. " with args: " .. tostring(repr(args)))
|
||||||
end
|
end
|
||||||
insert(self.callstack, alias)
|
insert(self.callstack, alias)
|
||||||
local rets = {
|
local rets = {
|
||||||
@ -560,10 +563,6 @@ do
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
get_aliases = function(self, x)
|
get_aliases = function(self, x)
|
||||||
if self.value then
|
|
||||||
print(self)
|
|
||||||
error("WTF")
|
|
||||||
end
|
|
||||||
if not x then
|
if not x then
|
||||||
self:error("Nothing to get aliases from")
|
self:error("Nothing to get aliases from")
|
||||||
end
|
end
|
||||||
|
16
nomsu.moon
16
nomsu.moon
@ -23,8 +23,7 @@ STRING_ESCAPES = n:"\n", t:"\t", b:"\b", a:"\a", v:"\v", f:"\f", r:"\r"
|
|||||||
|
|
||||||
-- Helper "classes"
|
-- Helper "classes"
|
||||||
parsetree_mt = {__tostring:=> "#{@type}(#{repr(@value)})"}
|
parsetree_mt = {__tostring:=> "#{@type}(#{repr(@value)})"}
|
||||||
ParseTree = (type, src, value, errors)->
|
ParseTree = (x)-> setmetatable(x, parsetree_mt)
|
||||||
setmetatable({:type, :src, :value, :errors}, parsetree_mt)
|
|
||||||
|
|
||||||
functiondef_mt = {__tostring:=> "FunctionDef(#{repr(@aliases)}"}
|
functiondef_mt = {__tostring:=> "FunctionDef(#{repr(@aliases)}"}
|
||||||
FunctionDef = (fn, aliases, src, is_macro)->
|
FunctionDef = (fn, aliases, src, is_macro)->
|
||||||
@ -151,9 +150,9 @@ defs =
|
|||||||
|
|
||||||
setmetatable(defs, {
|
setmetatable(defs, {
|
||||||
__index: (t,key)->
|
__index: (t,key)->
|
||||||
fn = (src, value, errors)-> ParseTree(key, src, value, errors)
|
-- Disabled for performance
|
||||||
t[key] = fn
|
--with t[key] = (src, value, errors)-> ParseTree({type: key, :src, :value, :errors}) do nil
|
||||||
return fn
|
with t[key] = (src, value, errors)-> {type: key, :src, :value, :errors} do nil
|
||||||
})
|
})
|
||||||
nomsu = re.compile(nomsu, defs)
|
nomsu = re.compile(nomsu, defs)
|
||||||
|
|
||||||
@ -176,7 +175,7 @@ class NomsuCompiler
|
|||||||
if type(aliases) == 'string'
|
if type(aliases) == 'string'
|
||||||
aliases = @get_aliases aliases
|
aliases = @get_aliases aliases
|
||||||
if @debug
|
if @debug
|
||||||
@writeln "Defining rule: #{aliases}"
|
@writeln "Defining rule: #{repr aliases}"
|
||||||
fn_def = FunctionDef(fn, {}, src, is_macro)
|
fn_def = FunctionDef(fn, {}, src, is_macro)
|
||||||
@add_aliases aliases, fn_def
|
@add_aliases aliases, fn_def
|
||||||
|
|
||||||
@ -221,7 +220,7 @@ class NomsuCompiler
|
|||||||
{:fn, :aliases} = fn_def
|
{:fn, :aliases} = fn_def
|
||||||
args = {name, select(i,...) for i,name in ipairs(aliases[alias])}
|
args = {name, select(i,...) for i,name in ipairs(aliases[alias])}
|
||||||
if @debug
|
if @debug
|
||||||
@writeln "Calling #{alias} with args: #{repr(args)}"
|
@writeln "Calling #{repr alias} with args: #{repr(args)}"
|
||||||
insert @callstack, alias
|
insert @callstack, alias
|
||||||
-- TODO: optimize, but still allow multiple return values?
|
-- TODO: optimize, but still allow multiple return values?
|
||||||
rets = {fn(self,args)}
|
rets = {fn(self,args)}
|
||||||
@ -430,9 +429,6 @@ class NomsuCompiler
|
|||||||
return concat(alias," "), args
|
return concat(alias," "), args
|
||||||
|
|
||||||
get_aliases:(x)=>
|
get_aliases:(x)=>
|
||||||
if self.value
|
|
||||||
print self
|
|
||||||
error "WTF"
|
|
||||||
if not x then @error "Nothing to get aliases from"
|
if not x then @error "Nothing to get aliases from"
|
||||||
if type(x) == 'string'
|
if type(x) == 'string'
|
||||||
alias, args = @get_alias(x)
|
alias, args = @get_alias(x)
|
||||||
|
Loading…
Reference in New Issue
Block a user