aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Pierre-Marie Pédrot <pierre-marie.pedrot@inria.fr>2016-10-20 11:45:10 +0200
committerGravatar Pierre-Marie Pédrot <pierre-marie.pedrot@inria.fr>2016-10-21 18:00:13 +0200
commitcef86ed6f78e2efa703bd8772a43fbeba597bbe3 (patch)
tree8aa3382cfee8cfdbe73cab67594b556ff13cf795
parentf667e270116aaf46f1c27b5a925d3ffaf0d31365 (diff)
Adding a primitive to recover the set of keywords from the lexer.
This is useful for debugging purposes.
-rw-r--r--parsing/cLexer.ml411
-rw-r--r--parsing/cLexer.mli1
2 files changed, 12 insertions, 0 deletions
diff --git a/parsing/cLexer.ml4 b/parsing/cLexer.ml4
index 31025075c..8a8e41956 100644
--- a/parsing/cLexer.ml4
+++ b/parsing/cLexer.ml4
@@ -69,6 +69,15 @@ let ttree_remove ttree str =
in
remove ttree 0
+let ttree_elements ttree =
+ let rec elts tt accu =
+ let accu = match tt.node with
+ | None -> accu
+ | Some s -> CString.Set.add s accu
+ in
+ CharMap.fold (fun _ tt accu -> elts tt accu) tt.branch accu
+ in
+ elts ttree CString.Set.empty
(* Errors occurring while lexing (explained as "Lexer error: ...") *)
@@ -221,6 +230,8 @@ let add_keyword str =
let remove_keyword str =
token_tree := ttree_remove !token_tree str
+let keywords () = ttree_elements !token_tree
+
(* Freeze and unfreeze the state of the lexer *)
type frozen_t = ttree
diff --git a/parsing/cLexer.mli b/parsing/cLexer.mli
index f69d95335..e0fdf8cb5 100644
--- a/parsing/cLexer.mli
+++ b/parsing/cLexer.mli
@@ -9,6 +9,7 @@
val add_keyword : string -> unit
val remove_keyword : string -> unit
val is_keyword : string -> bool
+val keywords : unit -> CString.Set.t
val check_ident : string -> unit
val is_ident : string -> bool