Added colon to dictionary syntax
Getty Ritter
8 years ago
36 | 36 |
@sign @int { lex (TkInt . read . T.unpack) }
|
37 | 37 |
@str { lex strLiteral }
|
38 | 38 |
|
| 39 |
with { lex' (TkKw KwWith) }
|
39 | 40 |
true { lex' (TkKw KwTrue) }
|
40 | 41 |
false { lex' (TkKw KwFalse) }
|
41 | 42 |
null { lex' (TkKw KwNull) }
|
|
46 | 47 |
\] { lex' TkRBrac }
|
47 | 48 |
\( { lex' TkLParn }
|
48 | 49 |
\) { lex' TkRParn }
|
| 50 |
\: { lex' TkColon }
|
| 51 |
\; { lex' TkSemi }
|
49 | 52 |
|
50 | 53 |
{
|
51 | 54 |
data Token = Token AlexPosn TkType deriving (Eq, Show)
|
|
54 | 57 |
= KwTrue
|
55 | 58 |
| KwFalse
|
56 | 59 |
| KwNull
|
| 60 |
| KwWith
|
57 | 61 |
deriving (Eq, Show)
|
58 | 62 |
|
59 | 63 |
data TkType
|
|
61 | 65 |
| TkFloat Scientific
|
62 | 66 |
| TkStr Text
|
63 | 67 |
| TkKw KwType
|
| 68 |
| TkColon
|
| 69 |
| TkSemi
|
64 | 70 |
| TkLCurl
|
65 | 71 |
| TkRCurl
|
66 | 72 |
| TkLBrac
|
19 | 19 |
'}' { Token _ TkRCurl }
|
20 | 20 |
'[' { Token _ TkLBrac }
|
21 | 21 |
']' { Token _ TkRBrac }
|
| 22 |
':' { Token _ TkColon }
|
| 23 |
';' { Token _ TkSemi }
|
22 | 24 |
|
| 25 |
with { Token _ (TkKw KwWith) }
|
23 | 26 |
true { Token _ (TkKw KwTrue) }
|
24 | 27 |
false { Token _ (TkKw KwFalse) }
|
25 | 28 |
null { Token _ (TkKw KwNull) }
|
|
48 | 51 |
| expr list { $1 : $2 }
|
49 | 52 |
|
50 | 53 |
dict
|
51 | |
: '}' { [] }
|
52 | |
| str expr dict { ($1, $2) : $3 }
|
| 54 |
: '}' { [] }
|
| 55 |
| str ':' expr dict { ($1, $3) : $4 }
|
53 | 56 |
|
54 | 57 |
{
|
55 | 58 |
|
4 | 4 |
# objects are created with key-value pairs, but don't use
|
5 | 5 |
# commas or colons
|
6 | 6 |
|
7 | |
"one" 1 # integers
|
| 7 |
"one": 1 # integers
|
8 | 8 |
|
9 | |
"two" 2.0 # floats
|
| 9 |
"two": 2.0 # floats
|
10 | 10 |
|
11 | |
"three" [ # lists use square brackets
|
| 11 |
"three": [ # lists use square brackets
|
12 | 12 |
"s" # the string syntax is identical to JSON's
|
13 | 13 |
"s" # again, no commas are necessary
|
14 | 14 |
"0"
|
15 | 15 |
]
|
16 | 16 |
|
17 | |
"four" # stitched expressions are fully contained in parens
|
| 17 |
"four": # stitched expressions are fully contained in parens
|
18 | 18 |
( 2 + 2 )
|
19 | 19 |
|
20 | 20 |
# the with keyword introduces a binding, of the form
|
21 | 21 |
# with ( [ident] [arg1 arg2 ... argn] = [expr] )
|
22 | 22 |
# these can occur anywhere and are ignored, but are scoped
|
23 | 23 |
# 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)
|
28 | 28 |
|
29 | 29 |
# this entire file denotes the JSON document
|
30 | 30 |
# { "one": 1,
|
4 | 4 |
# objects are created with key-value pairs, but don't use
|
5 | 5 |
# commas or colons
|
6 | 6 |
|
7 | |
"one" 1 # integers
|
| 7 |
"one": 1 # integers
|
8 | 8 |
|
9 | |
"two" 2.0 # floats
|
| 9 |
"two": 2.0 # floats
|
10 | 10 |
|
11 | 11 |
# lists use square brackets
|
12 | |
"three"
|
| 12 |
"three":
|
13 | 13 |
[
|
14 | 14 |
"s" # the string syntax is identical to JSON's
|
15 | 15 |
"s" # again, no commas are necessary
|