Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

88 lines (64 sloc) 1.9 kB
use("core")
use("define")
use("control-flow")
use("comparison")
-- patterns defined by dsl use 'with', so make sure it's exported
export(use("patterns"))
define-class(nil, e: Atomy AST Constant) = `(~e = class:)
define-class(root, e: Atomy AST Constant) = `(~e = ~root class:)
define-class(root, `(~n { ~*cs })) =
define-class(root, `((~n)() { ~*cs }))
define-class(root, x: `((~name)(~*as))) =
define-class(root, `(~x {}))
define-class(root, `((~name)(~*as): ~*cs)) = do:
attrs = []
as each [a]:
a through-quotes [x]:
x match:
`@~_ -> attrs << x
x
tmps = names(attrs size) collect [t]:
Atomy AST Unquote new(0, t)
pat = name
attrs zip(tmps) [a, t]:
pat =! `(~pat with(~a, ~t))
cons = `((~name)(~*tmps))
pat-def =
`(pattern(~(Atomy AST QuasiQuote new(0, cons))):
pattern(~(Atomy AST QuasiQuote new(0, pat))))
parent = root or 'Object
names [copy]:
`(do:
~name = ~parent class:
attr-accessor(
~*(attrs collect [a]:
`.~(a receiver)))
initialize(~*as) := nil
copy := do:
~copy = super
~*(attrs collect [a]:
`(~copy ~(a receiver) = ~a copy))
~copy
inspect :=
~(name name to-s) + "(" +
[~*attrs] collect .inspect join(", ") +
")"
~pat-def
~*(cs collect [c]: define-class(name, c)))
macro(data ~(children: Block)):
`(Object data: ~children)
macro(data(~x)):
`(Object data(~x) {})
macro(~root data(~x)):
`(~root data(~x) {})
macro(data(~parent): ~*children):
`(Object data(~parent): ~*children)
macro(~root data: ~*children):
`(do:
~*(children collect [c]:
define-class(root, c))
nil)
macro(~root data(~parent): ~*children):
`(do:
~(define-class(root, `(~(parent): ~*children)))
nil)
Jump to Line
Something went wrong with that request. Please try again.