richardhundt / shine

A Shiny Lua Dialect
Other
231 stars 18 forks source link

Import macro with shorthand 'import macro ...' syntax #64

Closed leonidborisenko closed 9 years ago

leonidborisenko commented 9 years ago

Add import macro ... syntax and document it.

Example (based on example from README.md):

-- file: macros.shn
function hello(ctx, expr)
   util = require("shine.lang.util")
   mesg = util::unquote(ctx.get(expr))
   return ctx.op{'!call', 'print', ctx.op"Hello %{mesg}"}
end

export hello
-- file: hello.shn
import macro hello from "macros"

hello("World!")

PR also contains fix for following bug:

 -- file:macros.shn
function fn(ctx, expr) return ctx.op"hello" end
--- file:error.shn
import my_macro = fn from "macros"
macro my_macro = my_macro
$ shine error.shn
Error: [string "shine.lang.translator"]:0: imported macro body for 'my_macro' cannot be resolved
stack traceback:
  <...>
richardhundt commented 9 years ago

Looks good. Thanks!