(* Copyright (C) 2005, HELM Team. * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science * Department, University of Bologna, Italy. * * HELM is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * HELM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HELM; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, * http://helm.cs.unibo.it/ *) open Printf exception Parse_error of Token.flocation * string let grammar = Grammar.gcreate CicNotationLexer.level1_lexer let level1 = Grammar.Entry.create grammar "level1" let return_term loc term = () (*let fail floc msg =*) (* let (x, y) = CicAst.loc_of_floc floc in*) (* failwith (sprintf "Error at characters %d - %d: %s" x y msg)*) let int_of_string s = try Pervasives.int_of_string s with Failure _ -> failwith (sprintf "Lexer failure: string_of_int \"%s\" failed" s) EXTEND GLOBAL: level1; level1: [ [ p = pattern -> () ] ]; pattern: [ [ p = LIST1 simple_pattern -> () ] ]; literal: [ [ s = SYMBOL -> () | k = KEYWORD -> () ] ]; sep: [ [ SYMBOL "\\SEP"; sep = literal -> () ] ]; row_sep: [ [ SYMBOL "\\ROWSEP"; sep = literal -> () ] ]; field_sep: [ [ SYMBOL "\\FIELDSEP"; sep = literal -> () ] ]; box_token: [ [ SYMBOL "\\HBOX"; p = simple_pattern -> () | SYMBOL "\\VBOX"; p = simple_pattern -> () | SYMBOL "\\BREAK" -> () ] ]; layout_schemata: [ [ SYMBOL "\\ARRAY"; p = simple_pattern; fsep = OPT field_sep; rsep = OPT row_sep -> () | SYMBOL "\\FRAC"; p1 = simple_pattern; p2 = simple_pattern -> () | SYMBOL "\\SQRT"; p = simple_pattern -> () | SYMBOL "\\ROOT"; p1 = simple_pattern; SYMBOL "\\OF"; p2 = simple_pattern -> () (* TODO XXX many issues here: * - "^^" is lexed as two "^" symbols * - "a_b" is lexed as IDENT "a_b" *) | p1 = simple_pattern; SYMBOL "^"; p2 = simple_pattern -> () | p1 = simple_pattern; SYMBOL "^"; SYMBOL "^"; p2 = simple_pattern -> () | p1 = simple_pattern; SYMBOL "_"; p2 = simple_pattern -> () | p1 = simple_pattern; SYMBOL "_"; SYMBOL "_"; p2 = simple_pattern -> () ] ]; simple_pattern: [ [ SYMBOL "\\LIST0"; p = simple_pattern; sep = OPT sep -> () | SYMBOL "\\LIST1"; p = simple_pattern; sep = OPT sep -> () | b = box_token -> () | id = IDENT -> () | SYMBOL "\\NUM"; id = IDENT -> () | SYMBOL "\\IDENT"; id = IDENT -> () | SYMBOL "\\OPT"; p = simple_pattern -> () | l = layout_schemata -> () | SYMBOL "["; p = pattern; SYMBOL "]" -> () ] ]; END let exc_located_wrapper f = try f () with | Stdpp.Exc_located (floc, Stream.Error msg) -> raise (Parse_error (floc, msg)) | Stdpp.Exc_located (floc, exn) -> raise (Parse_error (floc, (Printexc.to_string exn))) let parse_level1_pattern stream = exc_located_wrapper (fun () -> (Grammar.Entry.parse level1 stream)) (* vim:set encoding=utf8: *)