1 (* Copyright (C) 2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 exception Parse_error of Token.flocation * string
30 let grammar = Grammar.gcreate CicNotationLexer.level1_lexer
32 let level1 = Grammar.Entry.create grammar "level1"
34 let return_term loc term = ()
36 (*let fail floc msg =*)
37 (* let (x, y) = CicAst.loc_of_floc floc in*)
38 (* failwith (sprintf "Error at characters %d - %d: %s" x y msg)*)
42 Pervasives.int_of_string s
44 failwith (sprintf "Lexer failure: string_of_int \"%s\" failed" s)
49 level1: [ [ p = pattern -> () ] ];
51 pattern: [ [ p = LIST1 simple_pattern -> () ] ];
59 sep: [ [ SYMBOL "\\SEP"; sep = literal -> () ] ];
60 row_sep: [ [ SYMBOL "\\ROWSEP"; sep = literal -> () ] ];
61 field_sep: [ [ SYMBOL "\\FIELDSEP"; sep = literal -> () ] ];
64 [ SYMBOL "\\HBOX"; p = simple_pattern -> ()
65 | SYMBOL "\\VBOX"; p = simple_pattern -> ()
66 | SYMBOL "\\BREAK" -> ()
71 [ SYMBOL "\\ARRAY"; p = simple_pattern; fsep = OPT field_sep;
74 | SYMBOL "\\FRAC"; p1 = simple_pattern; p2 = simple_pattern -> ()
75 | SYMBOL "\\SQRT"; p = simple_pattern -> ()
76 | SYMBOL "\\ROOT"; p1 = simple_pattern; SYMBOL "\\OF";
77 p2 = simple_pattern ->
79 (* TODO XXX many issues here:
80 * - "^^" is lexed as two "^" symbols
81 * - "a_b" is lexed as IDENT "a_b" *)
82 | p1 = simple_pattern; SYMBOL "^"; p2 = simple_pattern -> ()
83 | p1 = simple_pattern; SYMBOL "^"; SYMBOL "^"; p2 = simple_pattern -> ()
84 | p1 = simple_pattern; SYMBOL "_"; p2 = simple_pattern -> ()
85 | p1 = simple_pattern; SYMBOL "_"; SYMBOL "_"; p2 = simple_pattern -> ()
90 [ SYMBOL "\\LIST0"; p = simple_pattern; sep = OPT sep -> ()
91 | SYMBOL "\\LIST1"; p = simple_pattern; sep = OPT sep -> ()
94 | SYMBOL "\\NUM"; id = IDENT -> ()
95 | SYMBOL "\\IDENT"; id = IDENT -> ()
96 | SYMBOL "\\OPT"; p = simple_pattern -> ()
97 | l = layout_schemata -> ()
98 | SYMBOL "["; p = pattern; SYMBOL "]" -> ()
103 let exc_located_wrapper f =
107 | Stdpp.Exc_located (floc, Stream.Error msg) ->
108 raise (Parse_error (floc, msg))
109 | Stdpp.Exc_located (floc, exn) ->
110 raise (Parse_error (floc, (Printexc.to_string exn)))
112 let parse_level1_pattern stream =
113 exc_located_wrapper (fun () -> (Grammar.Entry.parse level1 stream))
115 (* vim:set encoding=utf8: *)