Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 76 lines (57 sloc) 1.668 kb
fccc685 Initial open-source release
MLstate authored
1 /*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 */
18 %{
19
20 module J = JsonTypes
21
22 %}
23
24 %token EOF
25 %token LCURLY RCURLY COLON
26
27 %token LBRACKET RBRACKET COMMA
28 %token TRUE FALSE NIL
29 %token <string> STRING IDENT
30 %token <int> INT
31 %token <float> FLOAT
32
33 %start json
34
35 %type <JsonTypes.json> json
36
37 %%
38
39 json:
40 | value { $1 }
41 | error {
42 let p = symbol_start_pos () in
43 let msg = Printf.sprintf "line %d, char %d (%d) parse error\n"
44 p.Lexing.pos_lnum p.Lexing.pos_bol p.Lexing.pos_cnum in
45 failwith msg }
46
47 value:
48 | STRING { J.String $1 }
49 | INT { J.Int $1 }
50 | FLOAT { J.Float $1 }
51 | obj { $1 }
52 | array { J.Array $1 }
53 | TRUE { J.Bool true }
54 | FALSE { J.Bool false }
55 | NIL { J.Void }
56
57 obj:
58 | LCURLY members RCURLY { J.Record (List.rev $2) }
59 | LCURLY RCURLY { J.Void }
60
61 members:
62 | pair { [$1] }
63 | members COMMA pair { $3 :: $1 }
64
65 pair:
66 | STRING COLON value { $1, $3 }
67 | IDENT COLON value { $1, $3 }
68
69 array:
70 | LBRACKET RBRACKET { [] }
71 | LBRACKET elements RBRACKET { List.rev $2 }
72
73 elements:
74 | elements COMMA value { $3 :: $1 }
75 | value { [$1] }
Something went wrong with that request. Please try again.