In EvalOpt modules, the CLI input ["-"] is becomes now [None],
like the absence of an input filename. (This simplifies all the clients codes.) Fixed the dune file for the preprocessor. Fixed the build of PreprocMain.exe and PreprocMain.byte. Restricted preprocessing errors [Preproc.Newline_in_string] and [Preproc.Open_string] to the argument of the #include directive (instead of general strings: this is for the LIGO lexer to report the error). I removed the error [Preproc.Open_comment] as this is for the LIGO lexer to report. The preprocessor scanner [Preproc.lex] does not take a parameter [is_file:bool] now: the source file (if any) is determined from the lexing buffer. Accordingly, the field [is_file] of the state of the preprocessing lexer has been removed: the lexing buffer becomes now the reference for the input source (bug fix and interface improvement). Fixed the comments of the test contract pledge.religo. I removed the data constructor [Lexer.Stdin], as redundant with [Lexer.Channel].
This commit is contained in:
parent
46eecb4027
commit
3ed303f60d
@ -7,7 +7,7 @@ let%expect_test _ =
|
|||||||
let%expect_test _ =
|
let%expect_test _ =
|
||||||
run_ligo_bad ["interpret" ; "(\"thisisnotasignature\":signature)" ; "--syntax=pascaligo"] ;
|
run_ligo_bad ["interpret" ; "(\"thisisnotasignature\":signature)" ; "--syntax=pascaligo"] ;
|
||||||
[%expect {|
|
[%expect {|
|
||||||
ligo: in file ".", line 1, characters 1-32. Badly formatted literal: Signature thisisnotasignature {"location":"in file \".\", line 1, characters 1-32"}
|
ligo: in file "", line 0, characters 1-32. Badly formatted literal: Signature thisisnotasignature {"location":"in file \"\", line 0, characters 1-32"}
|
||||||
|
|
||||||
|
|
||||||
If you're not sure how to fix this error, you can
|
If you're not sure how to fix this error, you can
|
||||||
@ -25,7 +25,7 @@ let%expect_test _ =
|
|||||||
let%expect_test _ =
|
let%expect_test _ =
|
||||||
run_ligo_bad ["interpret" ; "(\"thisisnotapublickey\":key)" ; "--syntax=pascaligo"] ;
|
run_ligo_bad ["interpret" ; "(\"thisisnotapublickey\":key)" ; "--syntax=pascaligo"] ;
|
||||||
[%expect {|
|
[%expect {|
|
||||||
ligo: in file ".", line 1, characters 1-26. Badly formatted literal: key thisisnotapublickey {"location":"in file \".\", line 1, characters 1-26"}
|
ligo: in file "", line 0, characters 1-26. Badly formatted literal: key thisisnotapublickey {"location":"in file \"\", line 0, characters 1-26"}
|
||||||
|
|
||||||
|
|
||||||
If you're not sure how to fix this error, you can
|
If you're not sure how to fix this error, you can
|
||||||
|
@ -72,7 +72,5 @@ let wrap = function
|
|||||||
|
|
||||||
let () =
|
let () =
|
||||||
match IO.options#input with
|
match IO.options#input with
|
||||||
Some "-" | None ->
|
None -> Unit.contract_in_stdin () |> wrap
|
||||||
Unit.contract_in_stdin () |> wrap
|
| Some file_path -> Unit.contract_in_file file_path |> wrap
|
||||||
| Some file_path ->
|
|
||||||
Unit.contract_in_file file_path |> wrap
|
|
||||||
|
@ -72,7 +72,5 @@ let wrap = function
|
|||||||
|
|
||||||
let () =
|
let () =
|
||||||
match IO.options#input with
|
match IO.options#input with
|
||||||
Some "-" | None ->
|
None -> Unit.contract_in_stdin () |> wrap
|
||||||
Unit.contract_in_stdin () |> wrap
|
| Some file_path -> Unit.contract_in_file file_path |> wrap
|
||||||
| Some file_path ->
|
|
||||||
Unit.contract_in_file file_path |> wrap
|
|
||||||
|
@ -72,7 +72,5 @@ let wrap = function
|
|||||||
|
|
||||||
let () =
|
let () =
|
||||||
match IO.options#input with
|
match IO.options#input with
|
||||||
Some "-" | None ->
|
None -> Unit.contract_in_stdin () |> wrap
|
||||||
Unit.contract_in_stdin () |> wrap
|
| Some file_path -> Unit.contract_in_file file_path |> wrap
|
||||||
| Some file_path ->
|
|
||||||
Unit.contract_in_file file_path |> wrap
|
|
||||||
|
@ -162,7 +162,7 @@ let check lang ext =
|
|||||||
|
|
||||||
let input =
|
let input =
|
||||||
match !input with
|
match !input with
|
||||||
None | Some "-" -> !input
|
None | Some "-" -> None
|
||||||
| Some file_path ->
|
| Some file_path ->
|
||||||
if Filename.check_suffix file_path ext
|
if Filename.check_suffix file_path ext
|
||||||
then if Sys.file_exists file_path
|
then if Sys.file_exists file_path
|
||||||
|
@ -136,14 +136,11 @@ module type S =
|
|||||||
val slide : token -> window -> window
|
val slide : token -> window -> window
|
||||||
|
|
||||||
type input =
|
type input =
|
||||||
File of file_path (* "-" means stdin *)
|
File of file_path
|
||||||
| Stdin
|
|
||||||
| String of string
|
| String of string
|
||||||
| Channel of in_channel
|
| Channel of in_channel
|
||||||
| Buffer of Lexing.lexbuf
|
| Buffer of Lexing.lexbuf
|
||||||
|
|
||||||
val is_file : input -> bool
|
|
||||||
|
|
||||||
type instance = {
|
type instance = {
|
||||||
input : input;
|
input : input;
|
||||||
read : log:logger -> Lexing.lexbuf -> token;
|
read : log:logger -> Lexing.lexbuf -> token;
|
||||||
|
@ -158,14 +158,11 @@ module type S =
|
|||||||
val slide : token -> window -> window
|
val slide : token -> window -> window
|
||||||
|
|
||||||
type input =
|
type input =
|
||||||
File of file_path (* "-" means stdin *)
|
File of file_path
|
||||||
| Stdin
|
|
||||||
| String of string
|
| String of string
|
||||||
| Channel of in_channel
|
| Channel of in_channel
|
||||||
| Buffer of Lexing.lexbuf
|
| Buffer of Lexing.lexbuf
|
||||||
|
|
||||||
val is_file : input -> bool
|
|
||||||
|
|
||||||
type instance = {
|
type instance = {
|
||||||
input : input;
|
input : input;
|
||||||
read : log:logger -> Lexing.lexbuf -> token;
|
read : log:logger -> Lexing.lexbuf -> token;
|
||||||
@ -940,19 +937,11 @@ and scan_utf8_inline thread state = parse
|
|||||||
type logger = Markup.t list -> token -> unit
|
type logger = Markup.t list -> token -> unit
|
||||||
|
|
||||||
type input =
|
type input =
|
||||||
File of file_path (* "-" means stdin *)
|
File of file_path
|
||||||
| Stdin
|
|
||||||
| String of string
|
| String of string
|
||||||
| Channel of in_channel
|
| Channel of in_channel
|
||||||
| Buffer of Lexing.lexbuf
|
| Buffer of Lexing.lexbuf
|
||||||
|
|
||||||
(* Checking if a lexer input is a file *)
|
|
||||||
|
|
||||||
let is_file = function
|
|
||||||
File "-" | File "" -> false
|
|
||||||
| File _ -> true
|
|
||||||
| Stdin | String _ | Channel _ | Buffer _ -> false
|
|
||||||
|
|
||||||
type instance = {
|
type instance = {
|
||||||
input : input;
|
input : input;
|
||||||
read : log:logger -> Lexing.lexbuf -> token;
|
read : log:logger -> Lexing.lexbuf -> token;
|
||||||
@ -967,9 +956,7 @@ type instance = {
|
|||||||
type open_err = File_opening of string
|
type open_err = File_opening of string
|
||||||
|
|
||||||
let lexbuf_from_input = function
|
let lexbuf_from_input = function
|
||||||
File "" | File "-" | Stdin ->
|
File path ->
|
||||||
Ok (Lexing.from_channel stdin, fun () -> close_in stdin)
|
|
||||||
| File path ->
|
|
||||||
(try
|
(try
|
||||||
let chan = open_in path in
|
let chan = open_in path in
|
||||||
let close () = close_in chan in
|
let close () = close_in chan in
|
||||||
@ -988,8 +975,7 @@ let lexbuf_from_input = function
|
|||||||
|
|
||||||
let open_token_stream (lang: language) input =
|
let open_token_stream (lang: language) input =
|
||||||
let file_path = match input with
|
let file_path = match input with
|
||||||
File file_path ->
|
File path -> path
|
||||||
if file_path = "-" then "" else file_path
|
|
||||||
| _ -> "" in
|
| _ -> "" in
|
||||||
let pos = Pos.min ~file:file_path in
|
let pos = Pos.min ~file:file_path in
|
||||||
let buf_reg = ref (pos#byte, pos#byte)
|
let buf_reg = ref (pos#byte, pos#byte)
|
||||||
|
@ -69,12 +69,8 @@ module Make (Lexer: Lexer.S) : (S with module Lexer = Lexer) =
|
|||||||
then Stdlib.Ok ()
|
then Stdlib.Ok ()
|
||||||
else iter ()
|
else iter ()
|
||||||
| exception Lexer.Error error ->
|
| exception Lexer.Error error ->
|
||||||
let file =
|
|
||||||
match input with
|
|
||||||
Lexer.File name -> name <> "-"
|
|
||||||
| _ -> false in
|
|
||||||
let msg =
|
let msg =
|
||||||
Lexer.format_error ~offsets mode ~file error
|
Lexer.format_error ~offsets mode ~file:true error
|
||||||
in Stdlib.Error msg in
|
in Stdlib.Error msg in
|
||||||
let result = iter ()
|
let result = iter ()
|
||||||
in close_all (); result
|
in close_all (); result
|
||||||
|
@ -20,16 +20,16 @@ module Make (IO: IO) (Lexer: Lexer.S) =
|
|||||||
let scan () : (Lexer.token list, string Region.reg) Stdlib.result =
|
let scan () : (Lexer.token list, string Region.reg) Stdlib.result =
|
||||||
(* Preprocessing the input source *)
|
(* Preprocessing the input source *)
|
||||||
|
|
||||||
let preproc ~is_file cin =
|
let preproc cin =
|
||||||
let buffer = Lexing.from_channel cin in
|
let buffer = Lexing.from_channel cin in
|
||||||
let open Lexing in
|
let open Lexing in
|
||||||
let () =
|
let () =
|
||||||
match IO.options#input with
|
match IO.options#input with
|
||||||
None | Some "-" -> ()
|
None -> ()
|
||||||
| Some pos_fname ->
|
| Some pos_fname ->
|
||||||
buffer.lex_curr_p <- {buffer.lex_curr_p with pos_fname} in
|
buffer.lex_curr_p <- {buffer.lex_curr_p with pos_fname} in
|
||||||
let opt = (IO.options :> Preprocessor.EvalOpt.options) in
|
let opt = (IO.options :> Preprocessor.EvalOpt.options) in
|
||||||
match Preproc.lex ~is_file opt buffer with
|
match Preproc.lex opt buffer with
|
||||||
Stdlib.Error (pp_buffer, err) ->
|
Stdlib.Error (pp_buffer, err) ->
|
||||||
if SSet.mem "preproc" IO.options#verbose then
|
if SSet.mem "preproc" IO.options#verbose then
|
||||||
Printf.printf "%s\n%!" (Buffer.contents pp_buffer);
|
Printf.printf "%s\n%!" (Buffer.contents pp_buffer);
|
||||||
@ -39,33 +39,35 @@ module Make (IO: IO) (Lexer: Lexer.S) =
|
|||||||
| Stdlib.Ok pp_buffer ->
|
| Stdlib.Ok pp_buffer ->
|
||||||
(* Running the lexer on the preprocessed input *)
|
(* Running the lexer on the preprocessed input *)
|
||||||
|
|
||||||
let source = Lexer.String (Buffer.contents pp_buffer) in
|
let source = Lexer.String (Buffer.contents pp_buffer) in
|
||||||
match Lexer.open_token_stream IO.options#lang source with
|
match Lexer.open_token_stream IO.options#lang source with
|
||||||
Ok Lexer.{read; buffer; close; _} ->
|
Ok Lexer.{read; buffer; close; _} ->
|
||||||
let close_all () = flush_all (); close () in
|
let close_all () = flush_all (); close () in
|
||||||
let rec read_tokens tokens =
|
let rec read_tokens tokens =
|
||||||
match read ~log:(fun _ _ -> ()) buffer with
|
match read ~log:(fun _ _ -> ()) buffer with
|
||||||
token ->
|
token ->
|
||||||
if Lexer.Token.is_eof token
|
if Lexer.Token.is_eof token
|
||||||
then Stdlib.Ok (List.rev tokens)
|
then Stdlib.Ok (List.rev tokens)
|
||||||
else read_tokens (token::tokens)
|
else read_tokens (token::tokens)
|
||||||
| exception Lexer.Error error ->
|
| exception Lexer.Error error ->
|
||||||
let file =
|
let file =
|
||||||
match IO.options#input with
|
match IO.options#input with
|
||||||
None | Some "-" -> false
|
None | Some "-" -> false
|
||||||
| Some _ -> true in
|
| Some _ -> true in
|
||||||
let msg =
|
let () =
|
||||||
Lexer.format_error ~offsets:IO.options#offsets
|
Printf.eprintf "[LexerUnit] file = %b\n%!" file in
|
||||||
IO.options#mode ~file error
|
let msg =
|
||||||
in Stdlib.Error msg in
|
Lexer.format_error ~offsets:IO.options#offsets
|
||||||
let result = read_tokens []
|
IO.options#mode ~file error
|
||||||
in close_all (); result
|
in Stdlib.Error msg in
|
||||||
| Stdlib.Error (Lexer.File_opening msg) ->
|
let result = read_tokens []
|
||||||
flush_all (); Stdlib.Error (Region.wrap_ghost msg) in
|
in close_all (); result
|
||||||
|
| Stdlib.Error (Lexer.File_opening msg) ->
|
||||||
|
flush_all (); Stdlib.Error (Region.wrap_ghost msg) in
|
||||||
match IO.options#input with
|
match IO.options#input with
|
||||||
Some "-" | None -> preproc ~is_file:false stdin
|
None -> preproc stdin
|
||||||
| Some file_path ->
|
| Some file_path ->
|
||||||
try open_in file_path |> preproc ~is_file:true with
|
try open_in file_path |> preproc with
|
||||||
Sys_error msg -> Stdlib.Error (Region.wrap_ghost msg)
|
Sys_error msg -> Stdlib.Error (Region.wrap_ghost msg)
|
||||||
|
|
||||||
(* Tracing the lexing *)
|
(* Tracing the lexing *)
|
||||||
@ -74,7 +76,7 @@ module Make (IO: IO) (Lexer: Lexer.S) =
|
|||||||
|
|
||||||
let trace () : (unit, string Region.reg) Stdlib.result =
|
let trace () : (unit, string Region.reg) Stdlib.result =
|
||||||
(* Preprocessing the input *)
|
(* Preprocessing the input *)
|
||||||
let preproc ~is_file cin =
|
let preproc cin =
|
||||||
let buffer = Lexing.from_channel cin in
|
let buffer = Lexing.from_channel cin in
|
||||||
let open Lexing in
|
let open Lexing in
|
||||||
let () =
|
let () =
|
||||||
@ -83,7 +85,7 @@ module Make (IO: IO) (Lexer: Lexer.S) =
|
|||||||
| Some pos_fname ->
|
| Some pos_fname ->
|
||||||
buffer.lex_curr_p <- {buffer.lex_curr_p with pos_fname} in
|
buffer.lex_curr_p <- {buffer.lex_curr_p with pos_fname} in
|
||||||
let opt = (IO.options :> Preprocessor.EvalOpt.options) in
|
let opt = (IO.options :> Preprocessor.EvalOpt.options) in
|
||||||
match Preproc.lex ~is_file opt buffer with
|
match Preproc.lex opt buffer with
|
||||||
Stdlib.Error (pp_buffer, err) ->
|
Stdlib.Error (pp_buffer, err) ->
|
||||||
if SSet.mem "preproc" IO.options#verbose then
|
if SSet.mem "preproc" IO.options#verbose then
|
||||||
Printf.printf "%s\n%!" (Buffer.contents pp_buffer);
|
Printf.printf "%s\n%!" (Buffer.contents pp_buffer);
|
||||||
@ -103,8 +105,8 @@ module Make (IO: IO) (Lexer: Lexer.S) =
|
|||||||
(Lexer.String preproc_str)
|
(Lexer.String preproc_str)
|
||||||
IO.options#cmd
|
IO.options#cmd
|
||||||
in match IO.options#input with
|
in match IO.options#input with
|
||||||
Some "-" | None -> preproc ~is_file:false stdin
|
None -> preproc stdin
|
||||||
| Some file_path ->
|
| Some file_path ->
|
||||||
try open_in file_path |> preproc ~is_file:true with
|
try open_in file_path |> preproc with
|
||||||
Sys_error msg -> Stdlib.Error (Region.wrap_ghost msg)
|
Sys_error msg -> Stdlib.Error (Region.wrap_ghost msg)
|
||||||
end
|
end
|
||||||
|
@ -163,10 +163,11 @@ module Make (Lexer: Lexer.S)
|
|||||||
(* Lexing errors *)
|
(* Lexing errors *)
|
||||||
|
|
||||||
| exception Lexer.Error err ->
|
| exception Lexer.Error err ->
|
||||||
let file = Lexer.is_file lexer_inst.Lexer.input in
|
let file =
|
||||||
|
lexer_inst.Lexer.buffer.Lexing.lex_curr_p.Lexing.pos_fname in
|
||||||
let error =
|
let error =
|
||||||
Lexer.format_error ~offsets:SubIO.options#offsets
|
Lexer.format_error ~offsets:SubIO.options#offsets
|
||||||
SubIO.options#mode err ~file
|
SubIO.options#mode err ~file:(file <> "")
|
||||||
in Stdlib.Error error
|
in Stdlib.Error error
|
||||||
|
|
||||||
(* Incremental API of Menhir *)
|
(* Incremental API of Menhir *)
|
||||||
@ -199,8 +200,8 @@ module Make (Lexer: Lexer.S)
|
|||||||
|
|
||||||
(* Preprocessing the input source *)
|
(* Preprocessing the input source *)
|
||||||
|
|
||||||
let preproc ~is_file options lexbuf =
|
let preproc options lexbuf =
|
||||||
Preproc.lex ~is_file (options :> Preprocessor.EvalOpt.options) lexbuf
|
Preproc.lex (options :> Preprocessor.EvalOpt.options) lexbuf
|
||||||
|
|
||||||
(* Parsing a contract *)
|
(* Parsing a contract *)
|
||||||
|
|
||||||
@ -210,14 +211,14 @@ module Make (Lexer: Lexer.S)
|
|||||||
Stdlib.Error (Region.wrap_ghost msg)
|
Stdlib.Error (Region.wrap_ghost msg)
|
||||||
| Ok (lexbuf, close) ->
|
| Ok (lexbuf, close) ->
|
||||||
(* Preprocessing the input source *)
|
(* Preprocessing the input source *)
|
||||||
|
let file = Lexing.(lexbuf.lex_curr_p.pos_fname) in
|
||||||
match preproc ~is_file:(Lexer.is_file input) options lexbuf with
|
match preproc options lexbuf with
|
||||||
Stdlib.Error (pp_buffer, err) ->
|
Stdlib.Error (pp_buffer, err) ->
|
||||||
if SSet.mem "preproc" options#verbose then
|
if SSet.mem "preproc" options#verbose then
|
||||||
Printf.printf "%s\n%!" (Buffer.contents pp_buffer);
|
Printf.printf "%s\n%!" (Buffer.contents pp_buffer);
|
||||||
let formatted =
|
let formatted =
|
||||||
Preproc.format ~offsets:options#offsets
|
Preproc.format ~offsets:options#offsets
|
||||||
~file:(Lexer.is_file input)
|
~file:(file <> "")
|
||||||
err
|
err
|
||||||
in close (); Stdlib.Error formatted
|
in close (); Stdlib.Error formatted
|
||||||
| Stdlib.Ok buffer ->
|
| Stdlib.Ok buffer ->
|
||||||
@ -226,7 +227,11 @@ module Make (Lexer: Lexer.S)
|
|||||||
let () = close () in
|
let () = close () in
|
||||||
let input' = Lexer.String (Buffer.contents buffer) in
|
let input' = Lexer.String (Buffer.contents buffer) in
|
||||||
match Lexer.open_token_stream options#lang input' with
|
match Lexer.open_token_stream options#lang input' with
|
||||||
Ok instance -> apply instance parser
|
Ok instance ->
|
||||||
|
let open Lexing in
|
||||||
|
instance.Lexer.buffer.lex_curr_p <-
|
||||||
|
{instance.Lexer.buffer.lex_curr_p with pos_fname = file};
|
||||||
|
apply instance parser
|
||||||
| Stdlib.Error (Lexer.File_opening msg) ->
|
| Stdlib.Error (Lexer.File_opening msg) ->
|
||||||
Stdlib.Error (Region.wrap_ghost msg)
|
Stdlib.Error (Region.wrap_ghost msg)
|
||||||
|
|
||||||
@ -246,7 +251,7 @@ module Make (Lexer: Lexer.S)
|
|||||||
|
|
||||||
let contract_in_stdin () =
|
let contract_in_stdin () =
|
||||||
let options = SubIO.make ~input:None ~expr:false in
|
let options = SubIO.make ~input:None ~expr:false in
|
||||||
gen_parser options Lexer.Stdin parse_contract
|
gen_parser options (Lexer.Channel stdin) parse_contract
|
||||||
|
|
||||||
(* Parsing an expression in a string *)
|
(* Parsing an expression in a string *)
|
||||||
|
|
||||||
@ -258,6 +263,6 @@ module Make (Lexer: Lexer.S)
|
|||||||
|
|
||||||
let expr_in_stdin () =
|
let expr_in_stdin () =
|
||||||
let options = SubIO.make ~input:None ~expr:true in
|
let options = SubIO.make ~input:None ~expr:true in
|
||||||
gen_parser options Lexer.Stdin parse_expr
|
gen_parser options (Lexer.Channel stdin) parse_expr
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
(* Pledge-Distribute — Accept money from a number of contributors and then donate
|
/* Pledge-Distribute — Accept money from a number of contributors and then donate
|
||||||
to an address designated by an oracle *)
|
to an address designated by an oracle */
|
||||||
|
|
||||||
(* A lot of people (myself included) seem to expect an oracle to be more than it is.
|
/* A lot of people (myself included) seem to expect an oracle to be more than it is.
|
||||||
That is, they expect it to be something complicated when it's actually pretty simple.
|
That is, they expect it to be something complicated when it's actually pretty simple.
|
||||||
An oracle is just an authorized source of information external to the chain, like an
|
An oracle is just an authorized source of information external to the chain, like an
|
||||||
arbiter or moderator. For example, it's not possible to do an HTTP request to get
|
arbiter or moderator. For example, it's not possible to do an HTTP request to get
|
||||||
info from a weather site directly using a smart contract. So instead what you
|
info from a weather site directly using a smart contract. So instead what you
|
||||||
do is make (or use) an oracle service which uploads the data to the chain so
|
do is make (or use) an oracle service which uploads the data to the chain so
|
||||||
that contracts can use it.
|
that contracts can use it.
|
||||||
*)
|
*/
|
||||||
|
|
||||||
type storage = address
|
type storage = address
|
||||||
|
|
||||||
|
2
vendors/Preprocessor/EvalOpt.ml
vendored
2
vendors/Preprocessor/EvalOpt.ml
vendored
@ -101,7 +101,7 @@ let check lang ext =
|
|||||||
|
|
||||||
and input =
|
and input =
|
||||||
match !input with
|
match !input with
|
||||||
None | Some "-" -> !input
|
None | Some "-" -> None
|
||||||
| Some file_path ->
|
| Some file_path ->
|
||||||
if Filename.check_suffix file_path ext
|
if Filename.check_suffix file_path ext
|
||||||
then if Sys.file_exists file_path
|
then if Sys.file_exists file_path
|
||||||
|
6
vendors/Preprocessor/Preproc.mli
vendored
6
vendors/Preprocessor/Preproc.mli
vendored
@ -14,9 +14,8 @@ type error =
|
|||||||
| Invalid_line_indicator of string
|
| Invalid_line_indicator of string
|
||||||
| No_line_indicator
|
| No_line_indicator
|
||||||
| End_line_indicator
|
| End_line_indicator
|
||||||
| Newline_in_string (*XXX*)
|
| Newline_in_string (* For #include argument only *)
|
||||||
| Open_comment (*XXX*)
|
| Open_string (* For #include argument only *)
|
||||||
| Open_string (*XXX*)
|
|
||||||
| Dangling_endif
|
| Dangling_endif
|
||||||
| Open_region_in_conditional
|
| Open_region_in_conditional
|
||||||
| Dangling_endregion
|
| Dangling_endregion
|
||||||
@ -41,7 +40,6 @@ val format :
|
|||||||
(* Preprocessing a lexing buffer *)
|
(* Preprocessing a lexing buffer *)
|
||||||
|
|
||||||
val lex :
|
val lex :
|
||||||
is_file:bool ->
|
|
||||||
EvalOpt.options ->
|
EvalOpt.options ->
|
||||||
Lexing.lexbuf ->
|
Lexing.lexbuf ->
|
||||||
(Buffer.t, Buffer.t * error Region.reg) Stdlib.result
|
(Buffer.t, Buffer.t * error Region.reg) Stdlib.result
|
||||||
|
29
vendors/Preprocessor/Preproc.mll
vendored
29
vendors/Preprocessor/Preproc.mll
vendored
@ -97,8 +97,7 @@ type state = {
|
|||||||
out : Buffer.t;
|
out : Buffer.t;
|
||||||
incl : in_channel list;
|
incl : in_channel list;
|
||||||
opt : EvalOpt.options;
|
opt : EvalOpt.options;
|
||||||
dir : string list;
|
dir : string list
|
||||||
is_file : bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(* Directories *)
|
(* Directories *)
|
||||||
@ -118,7 +117,6 @@ type error =
|
|||||||
| No_line_indicator
|
| No_line_indicator
|
||||||
| End_line_indicator
|
| End_line_indicator
|
||||||
| Newline_in_string
|
| Newline_in_string
|
||||||
| Open_comment
|
|
||||||
| Open_string
|
| Open_string
|
||||||
| Dangling_endif
|
| Dangling_endif
|
||||||
| Open_region_in_conditional
|
| Open_region_in_conditional
|
||||||
@ -153,8 +151,6 @@ let error_to_string = function
|
|||||||
Hint: Try a string, end of line, or a line comment."
|
Hint: Try a string, end of line, or a line comment."
|
||||||
| Newline_in_string ->
|
| Newline_in_string ->
|
||||||
sprintf "Invalid newline character in string."
|
sprintf "Invalid newline character in string."
|
||||||
| Open_comment ->
|
|
||||||
sprintf "Unterminated comment."
|
|
||||||
| Open_string ->
|
| Open_string ->
|
||||||
sprintf "Unterminated string.\n\
|
sprintf "Unterminated string.\n\
|
||||||
Hint: Close with double quotes."
|
Hint: Close with double quotes."
|
||||||
@ -704,13 +700,13 @@ and in_line_com state = parse
|
|||||||
and reasonLIGO_com opening state = parse
|
and reasonLIGO_com opening state = parse
|
||||||
nl { proc_nl state lexbuf; reasonLIGO_com opening state lexbuf }
|
nl { proc_nl state lexbuf; reasonLIGO_com opening state lexbuf }
|
||||||
| "*/" { copy state lexbuf }
|
| "*/" { copy state lexbuf }
|
||||||
| eof { stop Open_comment state opening }
|
| eof { () }
|
||||||
| _ { copy state lexbuf; reasonLIGO_com opening state lexbuf }
|
| _ { copy state lexbuf; reasonLIGO_com opening state lexbuf }
|
||||||
|
|
||||||
and cameLIGO_com opening state = parse
|
and cameLIGO_com opening state = parse
|
||||||
nl { proc_nl state lexbuf; cameLIGO_com opening state lexbuf }
|
nl { proc_nl state lexbuf; cameLIGO_com opening state lexbuf }
|
||||||
| "*)" { copy state lexbuf }
|
| "*)" { copy state lexbuf }
|
||||||
| eof { stop Open_comment state opening }
|
| eof { () }
|
||||||
| _ { copy state lexbuf; cameLIGO_com opening state lexbuf }
|
| _ { copy state lexbuf; cameLIGO_com opening state lexbuf }
|
||||||
|
|
||||||
(* Included filename *)
|
(* Included filename *)
|
||||||
@ -732,17 +728,17 @@ and in_inclusion opening acc len state = parse
|
|||||||
and in_string opening state = parse
|
and in_string opening state = parse
|
||||||
"\\\"" { copy state lexbuf; in_string opening state lexbuf }
|
"\\\"" { copy state lexbuf; in_string opening state lexbuf }
|
||||||
| '"' { copy state lexbuf }
|
| '"' { copy state lexbuf }
|
||||||
| nl { fail Newline_in_string state lexbuf }
|
| eof { () }
|
||||||
| eof { stop Open_string state opening }
|
|
||||||
| _ { copy state lexbuf; in_string opening state lexbuf }
|
| _ { copy state lexbuf; in_string opening state lexbuf }
|
||||||
|
|
||||||
and preproc state = parse
|
and preproc state = parse
|
||||||
eof { state }
|
eof { state }
|
||||||
| _ { rollback lexbuf;
|
| _ { let open Lexing in
|
||||||
if state.is_file then
|
let () = rollback lexbuf in
|
||||||
print state (sprintf "# 1 \"%s\"\n"
|
let name = lexbuf.lex_start_p.pos_fname in
|
||||||
Lexing.(lexbuf.lex_start_p.pos_fname));
|
let () = if name <> "" then
|
||||||
scan state lexbuf }
|
print state (sprintf "# 1 \"%s\"\n" name)
|
||||||
|
in scan state lexbuf }
|
||||||
|
|
||||||
{
|
{
|
||||||
(* START OF TRAILER *)
|
(* START OF TRAILER *)
|
||||||
@ -751,7 +747,7 @@ and preproc state = parse
|
|||||||
the trace is empty at the end. Note that we discard the state at
|
the trace is empty at the end. Note that we discard the state at
|
||||||
the end. *)
|
the end. *)
|
||||||
|
|
||||||
let lex ~is_file opt buffer =
|
let lex opt buffer =
|
||||||
let state = {
|
let state = {
|
||||||
env = Env.empty;
|
env = Env.empty;
|
||||||
mode = Copy;
|
mode = Copy;
|
||||||
@ -760,8 +756,7 @@ let lex ~is_file opt buffer =
|
|||||||
out = Buffer.create 80;
|
out = Buffer.create 80;
|
||||||
incl = [];
|
incl = [];
|
||||||
opt;
|
opt;
|
||||||
dir = [];
|
dir = []
|
||||||
is_file;
|
|
||||||
} in
|
} in
|
||||||
match preproc state buffer with
|
match preproc state buffer with
|
||||||
state -> List.iter close_in state.incl;
|
state -> List.iter close_in state.incl;
|
||||||
|
8
vendors/Preprocessor/PreprocMain.ml
vendored
8
vendors/Preprocessor/PreprocMain.ml
vendored
@ -1,6 +1,8 @@
|
|||||||
(* Standalone preprocessor for PascaLIGO *)
|
(* Standalone preprocessor for PascaLIGO *)
|
||||||
|
|
||||||
module Region = Simple_utils.Region
|
module Region = Simple_utils.Region
|
||||||
|
module Preproc = Preprocessor.Preproc
|
||||||
|
module EvalOpt = Preprocessor.EvalOpt
|
||||||
|
|
||||||
let highlight msg = Printf.eprintf "\027[31m%s\027[0m\n%!" msg
|
let highlight msg = Printf.eprintf "\027[31m%s\027[0m\n%!" msg
|
||||||
|
|
||||||
@ -11,7 +13,7 @@ let preproc cin =
|
|||||||
let open Lexing in
|
let open Lexing in
|
||||||
let () =
|
let () =
|
||||||
match options#input with
|
match options#input with
|
||||||
None | Some "-" -> ()
|
None -> ()
|
||||||
| Some pos_fname ->
|
| Some pos_fname ->
|
||||||
buffer.lex_curr_p <- {buffer.lex_curr_p with pos_fname} in
|
buffer.lex_curr_p <- {buffer.lex_curr_p with pos_fname} in
|
||||||
match Preproc.lex options buffer with
|
match Preproc.lex options buffer with
|
||||||
@ -27,7 +29,7 @@ let preproc cin =
|
|||||||
|
|
||||||
let () =
|
let () =
|
||||||
match options#input with
|
match options#input with
|
||||||
Some "-" | None -> preproc stdin
|
None -> preproc stdin
|
||||||
| Some file_path ->
|
| Some file_path ->
|
||||||
try open_in file_path |> preproc with
|
try open_in file_path |> preproc with
|
||||||
Sys_error msg -> highlight msg
|
Sys_error msg -> highlight msg
|
||||||
|
35
vendors/Preprocessor/Preprocessor.install
vendored
35
vendors/Preprocessor/Preprocessor.install
vendored
@ -1,35 +0,0 @@
|
|||||||
lib: [
|
|
||||||
"_build/install/default/lib/Preprocessor/META"
|
|
||||||
"_build/install/default/lib/Preprocessor/E_Lexer.mli"
|
|
||||||
"_build/install/default/lib/Preprocessor/E_Lexer.mll"
|
|
||||||
"_build/install/default/lib/Preprocessor/EvalOpt.mli"
|
|
||||||
"_build/install/default/lib/Preprocessor/EvalOpt.ml"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preproc.mli"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preproc.mll"
|
|
||||||
"_build/install/default/lib/Preprocessor/E_AST.ml"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor.a"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor.cma"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor.cmxa"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor.cmxs"
|
|
||||||
"_build/install/default/lib/Preprocessor/dune-package"
|
|
||||||
"_build/install/default/lib/Preprocessor/opam"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor.cmi"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor.cmt"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor.cmx"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__E_Lexer.cmi"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__E_Lexer.cmt"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__E_Lexer.cmx"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__EvalOpt.cmi"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__EvalOpt.cmt"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__EvalOpt.cmx"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__Preproc.cmi"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__Preproc.cmt"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__Preproc.cmx"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__E_AST.cmi"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__E_AST.cmt"
|
|
||||||
"_build/install/default/lib/Preprocessor/Preprocessor__E_AST.cmx"
|
|
||||||
]
|
|
||||||
doc: [
|
|
||||||
"_build/install/default/doc/Preprocessor/LICENSE"
|
|
||||||
"_build/install/default/doc/Preprocessor/README.md"
|
|
||||||
]
|
|
2
vendors/Preprocessor/dune
vendored
2
vendors/Preprocessor/dune
vendored
@ -26,7 +26,7 @@
|
|||||||
(executable
|
(executable
|
||||||
(name PreprocMain)
|
(name PreprocMain)
|
||||||
(modules PreprocMain)
|
(modules PreprocMain)
|
||||||
(libraries Preproc)
|
(libraries Preprocessor)
|
||||||
(preprocess
|
(preprocess
|
||||||
(pps bisect_ppx --conditional)))
|
(pps bisect_ppx --conditional)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user