Skip to content

Instantly share code, notes, and snippets.

@smosher
Last active December 15, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smosher/5308176 to your computer and use it in GitHub Desktop.
Save smosher/5308176 to your computer and use it in GitHub Desktop.
DSL for Map literals using Map { ... } as a Map-scoped constructor
// mostly a guess:
OperatorTable addOperator(":", 13.5)
// : is a key-value pair (list) constructor on sequences:
Sequence : := method(a, return list(self, a) )
Message : := method(a, return list(self, a) )
Map curlyBrackets := method(
env := call sender clone
x := Map clone
call message arguments foreach(arg,
ls := self doMessage(arg)
k := ls at(0)
v := ls at(1)
// perl fatarrow-style LHS:
(k type == Message) ifTrue( k = k name )
// interpolate RHS:
// factor this out so non-interpolating versions can be composed DRYly
(v type == Message) ifTrue(
v = env doMessage(v)
)
x atPut(k, v)
)
)
// Todo:
// interpolation isn't tested
// List squareBrackets := method(...)
// Might switch to a KeyValuePair type from a simple list, with the scope captured too
// Map { key1: val1, k2: val2, ... }
// LHS doesn't need quoting, RHS interpolates via sender
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment