gdritter repos virgil / 85b1043
Added colon to dictionary syntax Getty Ritter 8 years ago
4 changed file(s) with 22 addition(s) and 13 deletion(s). Collapse all Expand all
3636 @sign @int { lex (TkInt . read . T.unpack) }
3737 @str { lex strLiteral }
3838
39 with { lex' (TkKw KwWith) }
3940 true { lex' (TkKw KwTrue) }
4041 false { lex' (TkKw KwFalse) }
4142 null { lex' (TkKw KwNull) }
4647 \] { lex' TkRBrac }
4748 \( { lex' TkLParn }
4849 \) { lex' TkRParn }
50 \: { lex' TkColon }
51 \; { lex' TkSemi }
4952
5053 {
5154 data Token = Token AlexPosn TkType deriving (Eq, Show)
5457 = KwTrue
5558 | KwFalse
5659 | KwNull
60 | KwWith
5761 deriving (Eq, Show)
5862
5963 data TkType
6165 | TkFloat Scientific
6266 | TkStr Text
6367 | TkKw KwType
68 | TkColon
69 | TkSemi
6470 | TkLCurl
6571 | TkRCurl
6672 | TkLBrac
1919 '}' { Token _ TkRCurl }
2020 '[' { Token _ TkLBrac }
2121 ']' { Token _ TkRBrac }
22 ':' { Token _ TkColon }
23 ';' { Token _ TkSemi }
2224
25 with { Token _ (TkKw KwWith) }
2326 true { Token _ (TkKw KwTrue) }
2427 false { Token _ (TkKw KwFalse) }
2528 null { Token _ (TkKw KwNull) }
4851 | expr list { $1 : $2 }
4952
5053 dict
51 : '}' { [] }
52 | str expr dict { ($1, $2) : $3 }
54 : '}' { [] }
55 | str ':' expr dict { ($1, $3) : $4 }
5356
5457 {
5558
44 # objects are created with key-value pairs, but don't use
55 # commas or colons
66
7 "one" 1 # integers
7 "one": 1 # integers
88
9 "two" 2.0 # floats
9 "two": 2.0 # floats
1010
11 "three" [ # lists use square brackets
11 "three": [ # lists use square brackets
1212 "s" # the string syntax is identical to JSON's
1313 "s" # again, no commas are necessary
1414 "0"
1515 ]
1616
17 "four" # stitched expressions are fully contained in parens
17 "four": # stitched expressions are fully contained in parens
1818 ( 2 + 2 )
1919
2020 # the with keyword introduces a binding, of the form
2121 # with ( [ident] [arg1 arg2 ... argn] = [expr] )
2222 # these can occur anywhere and are ignored, but are scoped
2323 # to the data structure in which they occur
24 with (
25 incr x = x + 1
26 )
27 "five" (incr 4)
24 with
25 incr x = x + 1;
26
27 "five": (incr 4)
2828
2929 # this entire file denotes the JSON document
3030 # { "one": 1,
44 # objects are created with key-value pairs, but don't use
55 # commas or colons
66
7 "one" 1 # integers
7 "one": 1 # integers
88
9 "two" 2.0 # floats
9 "two": 2.0 # floats
1010
1111 # lists use square brackets
12 "three"
12 "three":
1313 [
1414 "s" # the string syntax is identical to JSON's
1515 "s" # again, no commas are necessary