aboutsummaryrefslogtreecommitdiff
path: root/parsing/cLexer.mli
blob: b9f89f50528e26ca479ddf093146d3994de25e10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *   INRIA, CNRS and contributors - Copyright 1999-2018       *)
(* <O___,, *       (see CREDITS file for the list of authors)           *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)

(** This should be functional but it is not due to the interface *)
type starts_quotation = NoQuotation | Quotation

val add_keyword : ?quotation:starts_quotation -> string -> unit
val remove_keyword : string -> unit
val is_keyword : string -> bool
val keywords : unit -> CString.Set.t

type keyword_state
val set_keyword_state : keyword_state -> unit
val get_keyword_state : unit -> keyword_state

val check_ident : string -> unit
val is_ident : string -> bool
val check_keyword : string -> unit
val terminal : string -> Tok.pattern

(** The lexer of Coq: *)

(* modtype Grammar.GLexerType: sig
     type te val
     lexer : te Plexing.lexer
   end

where

  type lexer 'te =
    { tok_func : lexer_func 'te;
      tok_using : pattern -> unit;
      tok_removing : pattern -> unit;
      tok_match : pattern -> 'te -> string;
      tok_text : pattern -> string;
      tok_comm : mutable option (list location) }
 *)
include Gramlib.Grammar.GLexerType with type te = Tok.t

module Error : sig
  type t
  exception E of t
  val to_string : t -> string
end

(* Mainly for comments state, etc... *)
type lexer_state

val init_lexer_state : unit -> lexer_state
val set_lexer_state : lexer_state -> unit
val get_lexer_state : unit -> lexer_state
val drop_lexer_state : unit -> unit
val get_comment_state : lexer_state -> ((int * int) * string) list

(** Create a lexer.  true enables alternate handling for computing diffs.
It ensures that, ignoring white space, the concatenated tokens equal the input
string.  Specifically:
- for strings, return the enclosing quotes as tokens and treat the quoted value
as if it was unquoted, possibly becoming multiple tokens
- for comments, return the "(*" as a token and treat the contents of the comment as if
it was not in a comment, possibly becoming multiple tokens
- return any unrecognized Ascii or UTF-8 character as a string
*)
val make_lexer : diff_mode:bool -> Tok.t Gramlib.Plexing.lexer