Last active
December 15, 2015 18:59
-
-
Save smosher/5308176 to your computer and use it in GitHub Desktop.
DSL for Map literals using Map { ... } as a Map-scoped constructor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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