Proto: meaning etc.
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
-- Prototype for nel
|
||||
require("interpreter")
|
||||
require("nellie.parser")
|
||||
|
||||
function Bind(scope,abstract,callback)
|
||||
scope:insert(
|
||||
Binding(
|
||||
Parse(abstract),
|
||||
for _,expression in pairs(Parse(abstract)) do
|
||||
assert_meta(Expression)(expression)
|
||||
scope:insert(Binding(
|
||||
expression,
|
||||
callback
|
||||
)
|
||||
)
|
||||
))
|
||||
end
|
||||
end
|
||||
function Run(scope,expression,chain,name)
|
||||
name = name or "?"
|
||||
@@ -17,6 +18,13 @@ function Run(scope,expression,chain,name)
|
||||
local chain = Chain(expression:link(name)):from(chain)
|
||||
return scope:run(expression,chain)
|
||||
end
|
||||
function Do(scope,expression,chain,name)
|
||||
local latest
|
||||
for index,item in pairs(expression.items) do
|
||||
latest = Run(scope,item,chain,"do: "+tostring(index))
|
||||
end
|
||||
return latest
|
||||
end
|
||||
|
||||
NelliScope = Scope()
|
||||
local ns = NelliScope
|
||||
@@ -270,13 +278,37 @@ end)
|
||||
Bind(ns,"let (binding) in (scope)",function(s,e,c)
|
||||
|
||||
end)
|
||||
Bind(ns,"text (literal)",function(s,e,c) return e.literal:text() end)
|
||||
Bind(ns,"let ((named (name)) be (value))",function(s,e,c) end)
|
||||
Bind(ns,"new table",function(s,e,c) return {} end)
|
||||
]]
|
||||
|
||||
Bind(ns,"print (text)",function(s,e,c)
|
||||
log(Run(s,e.text,c,"print: text"))
|
||||
Bind(ns,"(closed)",function(s,e,c) return Run(s,e.closed,c,"(...)") end)
|
||||
Bind(ns,"log (text)",function(s,e,c) log(Run(s,e.text,c,"print: text")) end)
|
||||
Bind(ns,"this scope",function(s,e,c) return s end)
|
||||
Bind(ns,"new scope",function(s,e,c) return Scope() end) -- TODO: chains?!!?
|
||||
Bind(ns,"index (table) with (key)",function(s,e,c) return Run(s,e,c,"") end)
|
||||
Bind(ns,[[
|
||||
(input) means do (output);
|
||||
(input) in (input_scope) means do (output);
|
||||
(input) means do (output) in (output_scope);
|
||||
(input) in (input_scope) means do (output) in (output_scope)
|
||||
]],function(s,e,c1) -- A substitution
|
||||
local input_scope = s
|
||||
if e.input_scope then input_scope = Run(s,e.input_scope,c1,"means: input scope") end
|
||||
local output_scope = s
|
||||
if e.output_scope then output_scope = Run(s,e.output_scope,c2,"means: output scope") end
|
||||
Bind(e.input_scope,e.input,function(s,e,c2)
|
||||
return Do(e.output_scope,e.output,c2) -- TODO: chains?!
|
||||
end)
|
||||
end)
|
||||
Bind(ns,"do (stuff) in (scope); do (stuff)",function(s,e,c)
|
||||
s = s or Scope()
|
||||
return Do(s,e.stuff,c)
|
||||
end)
|
||||
Bind(ns,"new table",function(s,e,c) return {} end)
|
||||
|
||||
local Hpath = "nel/helper.nel"
|
||||
local Hpath = "nellie/helper.nel"
|
||||
local Hchain = Chain("in internal: "..Hpath)
|
||||
local success,result = Hchain:call(function(chain)
|
||||
Run(NelliScope,Parse(read(Hpath),Hpath,chain),chain)
|
||||
@@ -284,8 +316,6 @@ end)
|
||||
|
||||
--[[ Documentation:
|
||||
(log (text)) -> Log text to the output stream (print?)
|
||||
|
||||
|
||||
(a new scope) -> Becomes a created new scope
|
||||
(this scope) -> Becomes the current scope
|
||||
(macro) expands to (expansion) -> Becomes a binding which makes
|
||||
|
||||
Reference in New Issue
Block a user