diff options
author | Emilio Jesus Gallego Arias <e+git@x80.org> | 2018-02-11 19:42:14 +0100 |
---|---|---|
committer | Emilio Jesus Gallego Arias <e+git@x80.org> | 2018-02-28 18:16:22 +0100 |
commit | 2a64471512ee7dcd6d6c65cd5a792344628616f0 (patch) | |
tree | 9c98439db32ece160fd08304bfc4f1b5a63584e2 /parsing/cLexer.ml4 | |
parent | 893f8a3a3c573ab6b11cc3938cc67ccdc1b6b4ea (diff) |
[toplevel] Move beautify to its own pass.
We first load the file, then we print it as a post-processing
step. This is both more flexible and clearer.
We also refactor the comments handling to minimize the logic that is
living in the Lexer. Indeed, the main API is now living in the
printer, and complex interactions with the state are not possible
anymore, including the removal of messing with low-level summary and
state setting!
Diffstat (limited to 'parsing/cLexer.ml4')
-rw-r--r-- | parsing/cLexer.ml4 | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/parsing/cLexer.ml4 b/parsing/cLexer.ml4 index 52a6fe16c..d7e3751fd 100644 --- a/parsing/cLexer.ml4 +++ b/parsing/cLexer.ml4 @@ -384,16 +384,6 @@ let comments = ref [] let current_comment = Buffer.create 8192 let between_commands = ref true -let rec split_comments comacc acc pos = function - [] -> comments := List.rev acc; comacc - | ((b,e),c as com)::coms -> - (* Take all comments that terminates before pos, or begin exactly - at pos (used to print comments attached after an expression) *) - if e<=pos || pos=b then split_comments (c::comacc) acc pos coms - else split_comments comacc (com::acc) pos coms - -let extract_comments pos = split_comments [] [] pos !comments - (* The state of the lexer visible from outside *) type lexer_state = int option * string * bool * ((int * int) * string) list * Loc.source @@ -410,6 +400,8 @@ let release_lexer_state = get_lexer_state let drop_lexer_state () = set_lexer_state (init_lexer_state Loc.ToplevelInput) +let get_comment_state (_,_,_,c,_) = c + let real_push_char c = Buffer.add_char current_comment c (* Add a char if it is between two commands, if it is a newline or |