| 1 | (************************************************************************) |
| 2 | (* * The Rocq Prover / The Rocq Development Team *) |
| 3 | (* v * Copyright INRIA, CNRS and contributors *) |
| 4 | (* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 | (* \VV/ **************************************************************) |
| 6 | (* // * This file is distributed under the terms of the *) |
| 7 | (* * GNU Lesser General Public License Version 2.1 *) |
| 8 | (* * (see LICENSE file for the text of the license) *) |
| 9 | (************************************************************************) |
| 10 | |
| 11 | (* Type of dictionaries *) |
| 12 | |
| 13 | type ttree |
| 14 | |
| 15 | val empty_ttree : ttree |
| 16 | |
| 17 | (* Add a string with some translation in dictionary *) |
| 18 | val ttree_add : ttree -> string -> string -> ttree |
| 19 | |
| 20 | (* Remove a translation from a dictionary: returns an equal dictionary |
| 21 | if the word not present *) |
| 22 | val ttree_remove : ttree -> string -> ttree |
| 23 | |
| 24 | (* Translate a string *) |
| 25 | val translate : string -> string option |
| 26 | |
| 27 | (* Sublexer automaton *) |
| 28 | |
| 29 | (* The sublexer buffers the chars it receives; if after some time, it |
| 30 | recognizes that a sequence of chars has a translation in the |
| 31 | current dictionary, it replaces the buffer by the translation *) |
| 32 | |
| 33 | (* Received chars can come with a "tag" (usually made from |
| 34 | informations from the globalization file). A sequence of chars can |
| 35 | be considered a word only, if all chars have the same "tag". Rules |
| 36 | for cutting words are the following: |
| 37 | |
| 38 | - in a sequence like "**" where * is in the dictionary but not **, |
| 39 | "**" is not translated; otherwise said, to be translated, a sequence |
| 40 | must not be surrounded by other symbol-like chars |
| 41 | |
| 42 | - in a sequence like "<>_h*", where <>_h is in the dictionary, the |
| 43 | translation is done because the switch from a letter to a symbol char |
| 44 | is an acceptable cutting point |
| 45 | |
| 46 | - in a sequence like "<>_ha", where <>_h is in the dictionary, the |
| 47 | translation is not done because it is considered that h and a are |
| 48 | not separable (however, if h and a have different tags, and h has |
| 49 | the same tags as <, > and _, the translation happens) |
| 50 | |
| 51 | - in a sequence like "<>_ha", where <> but not <>_h is in the |
| 52 | dictionary, the translation is done for <> and _ha is considered |
| 53 | independently because the switch from a symbol char to a letter |
| 54 | is considered to be an acceptable cutting point |
| 55 | |
| 56 | - the longest-word rule applies: if both <> and <>_h are in the |
| 57 | dictionary, "<>_h" is one word and gets translated |
| 58 | *) |
| 59 | |
| 60 | (* Warning: do not output anything on output channel in between a call |
| 61 | to [output_tagged_*] and [flush_sublexer]!! *) |
| 62 | |
| 63 | type out_function = |
| 64 | bool (* needs escape *) -> |
| 65 | bool (* it is a symbol, not a pure ident *) -> |
| 66 | Index.index_entry option (* the index type of the token if any *) -> |
| 67 | string -> unit |
| 68 | |
| 69 | (* This must be initialized before calling the sublexer *) |
| 70 | val token_tree : ttree ref ref |
| 71 | val outfun : out_function ref |
| 72 | |
| 73 | (* Process an ident part that might be a symbol part *) |
| 74 | val output_tagged_ident_string : string -> unit |
| 75 | |
| 76 | (* Process a non-ident char (possibly equipped with a tag) *) |
| 77 | val output_tagged_symbol_char : Index.index_entry option -> char -> unit |
| 78 | |
| 79 | (* Flush the buffered content of the lexer using [outfun] *) |
| 80 | val flush_sublexer : unit -> unit |