6 Jane Street Holding, LLC
8 email: mmottl@janestcapital.com
9 WWW: http://www.janestcapital.com/ocaml
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 (** Parser: Grammar Specification for Parsing S-expressions *)
30 let parse_failure what =
31 let pos = symbol_start_pos () in
33 Printf.sprintf "Sexplib.Parser: failed to parse line %d char %d: %s"
34 pos.pos_lnum (pos.pos_cnum - pos.pos_bol) what in
38 %token <string> STRING
39 %token LPAREN RPAREN EOF
45 %type <Type.t option> sexp_opt
48 %type <Type.t list> sexps
51 %type <Type.t list> rev_sexps
56 : STRING { Type.Atom $1 }
57 | LPAREN RPAREN { Type.List [] }
58 | LPAREN rev_sexps_aux RPAREN { Type.List (List.rev $2) }
59 | error { parse_failure "sexp" }
67 | rev_sexps_aux sexp { $2 :: $1 }
70 : rev_sexps_aux { $1 }
74 : rev_sexps_aux { List.rev $1 }