-*.cma
-*.cmo
-*.cmi
-*.cmx
-*.cmxa
+*.cm[aiox] *.cmxa *.[ao]
test_lexer
test_parser
+macro_table.ml
+make_table
disambiguateTypes.cmx: disambiguateTypes.cmi
disambiguateChoices.cmo: disambiguateTypes.cmi disambiguateChoices.cmi
disambiguateChoices.cmx: disambiguateTypes.cmx disambiguateChoices.cmi
-macro.cmo: macro.cmi
-macro.cmx: macro.cmi
-cicTextualLexer2.cmo: macro.cmi cicTextualLexer2.cmi
-cicTextualLexer2.cmx: macro.cmx cicTextualLexer2.cmi
+macro_table.cmo: macro_table.cmi
+macro_table.cmx: macro_table.cmi
+cicTextualParser2Macro.cmo: macro_table.cmi cicTextualParser2Macro.cmi
+cicTextualParser2Macro.cmx: macro_table.cmx cicTextualParser2Macro.cmi
+cicTextualLexer2.cmo: cicTextualParser2Macro.cmi cicTextualLexer2.cmi
+cicTextualLexer2.cmx: cicTextualParser2Macro.cmx cicTextualLexer2.cmi
cicTextualParser2.cmo: cicTextualLexer2.cmi disambiguateChoices.cmi \
disambiguateTypes.cmi cicTextualParser2.cmi
cicTextualParser2.cmx: cicTextualLexer2.cmx disambiguateChoices.cmx \
INTERFACE_FILES = \
disambiguateTypes.mli \
disambiguateChoices.mli \
- macro.mli \
+ macro_table.mli \
+ cicTextualParser2Macro.mli \
cicTextualLexer2.mli \
cicTextualParser2.mli \
disambiguate.mli
ULEXDIR := $(shell ocamlfind query ulex)
LEXER_P4_OPTS = -I $(ULEXDIR) pa_ulex.cma
-PARSER_P4_OPTS = pa_extend.cmo ./macro.cmo ./pa_unicode_macro.cmo
+PARSER_P4_OPTS = \
+ pa_extend.cmo \
+ ./macro_table.cmo \
+ ./cicTextualParser2Macro.cmo \
+ ./pa_unicode_macro.cmo
PA_P4_OPTS = q_MLast.cmo pa_extend.cmo
all:
cicTextualLexer2.cmo: cicTextualLexer2.ml
$(OCAMLC) -pp "camlp4o $(LEXER_P4_OPTS)" -c $<
-cicTextualParser2.cmo: cicTextualParser2.ml macro.cmo pa_unicode_macro.cmo
+cicTextualParser2.cmo: cicTextualParser2.ml cicTextualParser2Macro.cmo pa_unicode_macro.cmo
$(OCAMLC) -pp "camlp4o $(PARSER_P4_OPTS)" -c $<
cicTextualLexer2.cmx: cicTextualLexer2.ml
$(OCAMLOPT) -pp "camlp4o $(LEXER_P4_OPTS)" -c $<
-cicTextualParser2.cmx: cicTextualParser2.ml macro.cmo pa_unicode_macro.cmo
+cicTextualParser2.cmx: cicTextualParser2.ml cicTextualParser2Macro.cmo pa_unicode_macro.cmo
$(OCAMLOPT) -pp "camlp4o $(PARSER_P4_OPTS)" -c $<
%_notation.cmo: %_notation.ml cicTextualParser2.cmo
%_notation.cmx: %_notation.ml cicTextualParser2.cmx
$(OCAMLOPT) -pp "camlp4o $(PARSER_P4_OPTS)" -c $<
-pa_unicode_macro.cmo: pa_unicode_macro.ml macro.cmo
+pa_unicode_macro.cmo: pa_unicode_macro.ml cicTextualParser2Macro.cmo
$(OCAMLC) -pp "camlp4o $(PA_P4_OPTS)" -c $<
-pa_unicode_macro.cmx: pa_unicode_macro.ml macro.cmx
+pa_unicode_macro.cmx: pa_unicode_macro.ml cicTextualParser2Macro.cmx
$(OCAMLOPT) -pp "camlp4o $(PA_P4_OPTS)" -c $<
LOCAL_LINKOPTS = -linkpkg $(PACKAGE).cma
test_parser: test_parser.ml $(PACKAGE).cma
$(OCAMLC) $(LOCAL_LINKOPTS) -o $@ $<
make_table: make_table.ml
- $(OCAMLC) -linkpkg -o $@ $<
+ $(OCAMLFIND) ocamlc -package pxp -linkpkg -o $@ $^
-.PHONY: macro_table.dump
-macro_table.dump: make_table
+macro_table.ml: make_table
./make_table $@
+macro_table.cmo: macro_table.ml
+ $(OCAMLFIND) ocamlc -c $<
clean: extra_clean
distclean: extra_clean
include ../Makefile.common
.PHONY: depend
-depend: macro.cmi macro.cmo pa_unicode_macro.cmi pa_unicode_macro.cmo
+depend: cicTextualParser2Macro.cmi cicTextualParser2Macro.cmo pa_unicode_macro.cmi pa_unicode_macro.cmo
$(OCAMLDEP) -pp "camlp4o $(PARSER_P4_OPTS) $(LEXER_P4_OPTS)" $(INTERFACE_FILES) $(IMPLEMENTATION_FILES) > .depend
disambiguateTypes.cmi: disambiguateTypes.mli
Ulexing.utf8_sub_lexeme lexbuf 1 (Ulexing.lexeme_length lexbuf - 1)
in
(try
- return lexbuf ("SYMBOL", Macro.expand macro)
- with Macro.Macro_not_found _ ->
+ return lexbuf ("SYMBOL", CicTextualParser2Macro.expand macro)
+ with CicTextualParser2Macro.Macro_not_found _ ->
return lexbuf ("SYMBOL", Ulexing.utf8_lexeme lexbuf))
| eof -> return lexbuf ("EOI", "")
| _ -> error lexbuf "Invalid character"
--- /dev/null
+(* Copyright (C) 2004, 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/
+ *)
+
+exception Macro_not_found of string
+exception Utf8_not_found of string
+
+let expand macro =
+ try
+ Hashtbl.find Macro_table.macro2utf8 macro
+ with Not_found -> raise (Macro_not_found macro)
+
--- /dev/null
+(* Copyright (C) 2004, 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/
+ *)
+
+exception Macro_not_found of string
+exception Utf8_not_found of string
+
+ (* @param macro name
+ @return utf8 string *)
+val expand: string -> string
+
+++ /dev/null
-(* Copyright (C) 2004, 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/
- *)
-
-exception Macro_not_found of string
-exception Utf8_not_found of string
-
-let dump_file = "macro_table.dump"
-
-let init () =
- let ic = open_in dump_file in
- let (macro2utf8, utf82macro):
- ((string, string) Hashtbl.t * (string, string) Hashtbl.t)
- =
- Marshal.from_channel ic
- in
- close_in ic;
- (macro2utf8, utf82macro)
-
-let (macro2utf8, utf82macro) = init ()
-
-let expand macro =
- try
- Hashtbl.find macro2utf8 macro
- with Not_found -> raise (Macro_not_found macro)
-
-let contract utf8 =
- try
- Hashtbl.find utf82macro utf8
- with Not_found -> raise (Utf8_not_found utf8)
-
+++ /dev/null
-(* Copyright (C) 2004, 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/
- *)
-
-exception Macro_not_found of string
-exception Utf8_not_found of string
-
- (* @param macro name
- @return utf8 string *)
-val expand: string -> string
-
-val contract: string -> string
-
--- /dev/null
+(* Copyright (C) 2004, 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/
+ *)
+
+val macro2utf8: (string, string) Hashtbl.t
+
open Pxp_types
open Pxp_ev_parser
-(* Usage: make_table <hashtbls_dump_file> *)
-
let debug = false
let debug_print s = if debug then prerr_endline s
-let tables = [
+ (* source files for tables xml parsing (if unmarshall=false) *)
+let xml_tables = [
(*
`Entities, "/usr/share/gtkmathview/entities-table.xml";
`Dictionary, "/usr/share/editex/dictionary-tex.xml"
`Entities, "macros/extra-entities.xml";
]
-let macro2utf8 = Hashtbl.create 2000
-let utf82macro = Hashtbl.create 2000
-
-let add_macro macro utf8 =
- debug_print (sprintf "Adding macro %s = '%s'" macro utf8);
- Hashtbl.add macro2utf8 macro utf8;
- Hashtbl.add utf82macro utf8 macro
let rec find_first_tag pull_parser =
match pull_parser () with
in
aux ()
-let fill_table () =
- List.iter
- (fun (typ, fname) ->
- let entry = `Entry_document [ `Extend_dtd_fully; `Parse_xml_decl ] in
- let config = { default_config with encoding = `Enc_utf8 } in
- let entity_manager =
- create_entity_manager ~is_document:true config (from_file fname)
- in
- let pull_parser = create_pull_parser config entry entity_manager in
- match typ with
- | `Entities -> iter_entities_file add_macro pull_parser
- | `Dictionary -> iter_dictionary_file add_macro pull_parser)
- tables
+let parse_from_xml () =
+ let (macro2utf8, utf82macro) = (Hashtbl.create 2000, Hashtbl.create 2000) in
+ let add_macro macro utf8 =
+ debug_print (sprintf "Adding macro %s = '%s'" macro utf8);
+ Hashtbl.add macro2utf8 macro utf8;
+(* Hashtbl.add utf82macro utf8 macro *)
+ in
+ let fill_table () =
+ List.iter
+ (fun (typ, fname) ->
+ let entry = `Entry_document [ `Extend_dtd_fully; `Parse_xml_decl ] in
+ let config = { default_config with encoding = `Enc_utf8 } in
+ let entity_manager =
+ create_entity_manager ~is_document:true config (from_file fname)
+ in
+ let pull_parser = create_pull_parser config entry entity_manager in
+ match typ with
+ | `Entities -> iter_entities_file add_macro pull_parser
+ | `Dictionary -> iter_dictionary_file add_macro pull_parser)
+ xml_tables
+ in
+ fill_table ();
+ macro2utf8
let main () =
let oc = open_out Sys.argv.(1) in
- fill_table ();
- Marshal.to_channel oc (macro2utf8, utf82macro) [];
+ output_string oc "(* GENERATED by make_table: DO NOT EDIT! *)\n";
+ output_string oc "let macro2utf8 = Hashtbl.create 2000\n";
+ let macro2utf8 = parse_from_xml () in
+ Hashtbl.iter
+ (fun macro utf8 ->
+ fprintf oc "let _ = Hashtbl.add macro2utf8 \"%s\" \"%s\"\n"
+ macro (String.escaped utf8))
+ macro2utf8;
close_out oc
let _ = main ()
let expand_unicode_macro macro =
debug_print (Printf.sprintf "Expanding macro '%s' ..." macro);
- let expansion = Macro.expand macro in
+ let expansion = CicTextualParser2Macro.expand macro in
<:expr< $str:expansion$ >>
let _ =