From cef86ed6f78e2efa703bd8772a43fbeba597bbe3 Mon Sep 17 00:00:00 2001 From: Pierre-Marie Pédrot Date: Thu, 20 Oct 2016 11:45:10 +0200 Subject: Adding a primitive to recover the set of keywords from the lexer. This is useful for debugging purposes. --- parsing/cLexer.ml4 | 11 +++++++++++ parsing/cLexer.mli | 1 + 2 files changed, 12 insertions(+) diff --git a/parsing/cLexer.ml4 b/parsing/cLexer.ml4 index 31025075cd..8a8e41956a 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 f69d953354..e0fdf8cb55 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 -- cgit v1.2.3