From ce5464f9afe9a67a49b62a6ef399523431f57604 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Fri, 24 Apr 2020 20:54:13 +0200 Subject: [PATCH 1/4] The preprocessor library depends now on the kinds of comments instead of a closed set of languages. I also removed the offsets: I simply use the current region to determine whether the preprocessing directie starts at the beginning of a line. I also removed scanning line indicators, to make the lexer simpler. --- vendors/Preprocessor/E_LexerMain.ml | 2 +- vendors/Preprocessor/E_ParserMain.ml | 2 +- vendors/Preprocessor/EvalOpt.ml | 49 ++-- vendors/Preprocessor/EvalOpt.mli | 22 +- vendors/Preprocessor/Preproc.mli | 6 +- vendors/Preprocessor/Preproc.mll | 348 +++++++++++++-------------- vendors/Preprocessor/PreprocMain.ml | 7 +- vendors/Preprocessor/build.sh | 22 -- vendors/Preprocessor/clean.sh | 4 - 9 files changed, 212 insertions(+), 250 deletions(-) delete mode 100755 vendors/Preprocessor/build.sh delete mode 100755 vendors/Preprocessor/clean.sh diff --git a/vendors/Preprocessor/E_LexerMain.ml b/vendors/Preprocessor/E_LexerMain.ml index 93b0a5930..3c8f87403 100644 --- a/vendors/Preprocessor/E_LexerMain.ml +++ b/vendors/Preprocessor/E_LexerMain.ml @@ -5,7 +5,7 @@ module Region = Simple_utils.Region let highlight msg = Printf.eprintf "\027[31m%s\027[0m%!" msg -let options = EvalOpt.(read ~lang:`PascaLIGO ~ext:".ligo") +let options = EvalOpt.read ".ligo" (* No comments allowed *) let lex in_chan = let buffer = Lexing.from_channel in_chan in diff --git a/vendors/Preprocessor/E_ParserMain.ml b/vendors/Preprocessor/E_ParserMain.ml index 653e80425..d46d9eea1 100644 --- a/vendors/Preprocessor/E_ParserMain.ml +++ b/vendors/Preprocessor/E_ParserMain.ml @@ -5,7 +5,7 @@ module Region = Simple_utils.Region let highlight msg = Printf.eprintf "\027[31m%s\027[0m%!" msg -let options = EvalOpt.(read ~lang:`PascaLIGO ~ext:".ligo") +let options = EvalOpt.read ".ligo" (* No comments allowed *) let parse in_chan = let buffer = Lexing.from_channel in_chan in diff --git a/vendors/Preprocessor/EvalOpt.ml b/vendors/Preprocessor/EvalOpt.ml index 63c92fad1..2ce560cec 100644 --- a/vendors/Preprocessor/EvalOpt.ml +++ b/vendors/Preprocessor/EvalOpt.ml @@ -2,29 +2,33 @@ (* The type [options] gathers the command-line options. *) -type language = [`PascaLIGO | `CameLIGO | `ReasonLIGO] - -let lang_to_string = function - `PascaLIGO -> "PascaLIGO" -| `CameLIGO -> "CameLIGO" -| `ReasonLIGO -> "ReasonLIGO" - module SSet = Set.Make (String) +type line_comment = string (* Opening of a line comment *) +type block_comment = + +let mk_block ~opening ~closing : block_comment = + object + method opening = opening + method closing = closing + end + type options = < input : string option; libs : string list; verbose : SSet.t; offsets : bool; - lang : language; - ext : string (* ".ligo", ".mligo", ".religo" *) + block : block_comment option; + line : line_comment option; + ext : string > -let make ~input ~libs ~lang ~offsets ~verbose ~ext : options = +let make ~input ~libs ?block ?line ~offsets ~verbose ~ext : options = object method input = input method libs = libs - method lang = lang + method block = block + method line = line method offsets = offsets method verbose = verbose method ext = ext @@ -47,10 +51,10 @@ let abort msg = (* Help *) -let help lang ext () = +let help ext () = let file = Filename.basename Sys.argv.(0) in printf "Usage: %s [