Shortened the parser's API.

Unfortunately, even thought all the front-ends use the same
ParserAPI.ml, that file cannot be moved to the folder `shared` due to
a dependency on AST.ml produced by Menhir.
This commit is contained in:
Christian Rinderknecht 2019-12-26 18:17:57 +01:00
parent 548b1267a4
commit 379311a748
7 changed files with 202 additions and 408 deletions

View File

@ -1,49 +1,16 @@
(** Generic parser for LIGO *) (** Generic parser for LIGO *)
module type PARSER =
sig
(* The type of tokens *)
type token
(* This exception is raised by the monolithic API functions *)
exception Error
(* The monolithic API *)
val contract : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> AST.t
(* The incremental API *)
module MenhirInterpreter :
sig
include MenhirLib.IncrementalEngine.INCREMENTAL_ENGINE
with type token = token
end
module Incremental :
sig
val contract : Lexing.position -> AST.t MenhirInterpreter.checkpoint
end
end
(* Errors *) (* Errors *)
module type PAR_ERR =
sig
val message : int -> string (* From error states to messages *)
end
let format_error ?(offsets=true) mode Region.{region; value} ~file = let format_error ?(offsets=true) mode Region.{region; value} ~file =
let reg = region#to_string ~file ~offsets mode in let reg = region#to_string ~file ~offsets mode in
Printf.sprintf "\027[31mParse error %s:\n%s\027[0m%!" reg value Printf.sprintf "\027[31mParse error %s:\n%s\027[0m%!" reg value
(* Main functor *) (* Main functor *)
module Make (Lexer: Lexer.S) module Make (Lexer: Lexer.S with module Token := LexToken)
(Parser: PARSER with type token = Lexer.Token.token) (Parser: module type of Parser)
(ParErr: PAR_ERR) = (ParErr: sig val message : int -> string end) =
struct struct
type message = string type message = string
type valid = Lexer.token type valid = Lexer.token
@ -94,5 +61,4 @@ module Make (Lexer: Lexer.S)
in close (); ast in close (); ast
let mono_contract = Parser.contract let mono_contract = Parser.contract
end end

View File

@ -1,50 +1,16 @@
(** Generic parser API for LIGO *) (** Generic parser API for LIGO *)
module type PARSER =
sig
(* The type of tokens *)
type token
(* This exception is raised by the monolithic API functions *)
exception Error
(* The monolithic API *)
val contract : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> AST.t
(* The incremental API *)
module MenhirInterpreter :
sig
include MenhirLib.IncrementalEngine.INCREMENTAL_ENGINE
with type token = token
end
module Incremental :
sig
val contract : Lexing.position -> AST.t MenhirInterpreter.checkpoint
end
end
(* Errors *) (* Errors *)
module type PAR_ERR =
sig
val message : int -> string (* From error states to messages *)
end
val format_error : val format_error :
?offsets:bool -> [`Byte | `Point] -> ?offsets:bool -> [`Byte | `Point] ->
string Region.reg -> file:bool -> string string Region.reg -> file:bool -> string
(* Main functor *) (* Main functor *)
module Make (Lexer: Lexer.S) module Make (Lexer: Lexer.S with module Token := LexToken)
(Parser: PARSER with type token = Lexer.Token.token) (Parser: module type of Parser)
(ParErr: PAR_ERR) : (ParErr: sig val message: int -> string end) :
sig sig
type message = string type message = string
type valid = Lexer.token type valid = Lexer.token

View File

@ -1,49 +1,16 @@
(** Generic parser for LIGO *) (** Generic parser for LIGO *)
module type PARSER =
sig
(* The type of tokens *)
type token
(* This exception is raised by the monolithic API functions *)
exception Error
(* The monolithic API *)
val contract : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> AST.t
(* The incremental API *)
module MenhirInterpreter :
sig
include MenhirLib.IncrementalEngine.INCREMENTAL_ENGINE
with type token = token
end
module Incremental :
sig
val contract : Lexing.position -> AST.t MenhirInterpreter.checkpoint
end
end
(* Errors *) (* Errors *)
module type PAR_ERR =
sig
val message : int -> string (* From error states to messages *)
end
let format_error ?(offsets=true) mode Region.{region; value} ~file = let format_error ?(offsets=true) mode Region.{region; value} ~file =
let reg = region#to_string ~file ~offsets mode in let reg = region#to_string ~file ~offsets mode in
Printf.sprintf "\027[31mParse error %s:\n%s\027[0m%!" reg value Printf.sprintf "\027[31mParse error %s:\n%s\027[0m%!" reg value
(* Main functor *) (* Main functor *)
module Make (Lexer: Lexer.S) module Make (Lexer: Lexer.S with module Token := LexToken)
(Parser: PARSER with type token = Lexer.Token.token) (Parser: module type of Parser)
(ParErr: PAR_ERR) = (ParErr: sig val message : int -> string end) =
struct struct
type message = string type message = string
type valid = Lexer.token type valid = Lexer.token
@ -94,5 +61,4 @@ module Make (Lexer: Lexer.S)
in close (); ast in close (); ast
let mono_contract = Parser.contract let mono_contract = Parser.contract
end end

View File

@ -1,50 +1,16 @@
(** Generic parser API for LIGO *) (** Generic parser API for LIGO *)
module type PARSER =
sig
(* The type of tokens *)
type token
(* This exception is raised by the monolithic API functions *)
exception Error
(* The monolithic API *)
val contract : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> AST.t
(* The incremental API *)
module MenhirInterpreter :
sig
include MenhirLib.IncrementalEngine.INCREMENTAL_ENGINE
with type token = token
end
module Incremental :
sig
val contract : Lexing.position -> AST.t MenhirInterpreter.checkpoint
end
end
(* Errors *) (* Errors *)
module type PAR_ERR =
sig
val message : int -> string (* From error states to messages *)
end
val format_error : val format_error :
?offsets:bool -> [`Byte | `Point] -> ?offsets:bool -> [`Byte | `Point] ->
string Region.reg -> file:bool -> string string Region.reg -> file:bool -> string
(* Main functor *) (* Main functor *)
module Make (Lexer: Lexer.S) module Make (Lexer: Lexer.S with module Token := LexToken)
(Parser: PARSER with type token = Lexer.Token.token) (Parser: module type of Parser)
(ParErr: PAR_ERR) : (ParErr: sig val message: int -> string end) :
sig sig
type message = string type message = string
type valid = Lexer.token type valid = Lexer.token

View File

@ -1,49 +1,16 @@
(** Generic parser for LIGO *) (** Generic parser for LIGO *)
module type PARSER =
sig
(* The type of tokens *)
type token
(* This exception is raised by the monolithic API functions *)
exception Error
(* The monolithic API *)
val contract : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> AST.t
(* The incremental API *)
module MenhirInterpreter :
sig
include MenhirLib.IncrementalEngine.INCREMENTAL_ENGINE
with type token = token
end
module Incremental :
sig
val contract : Lexing.position -> AST.t MenhirInterpreter.checkpoint
end
end
(* Errors *) (* Errors *)
module type PAR_ERR =
sig
val message : int -> string (* From error states to messages *)
end
let format_error ?(offsets=true) mode Region.{region; value} ~file = let format_error ?(offsets=true) mode Region.{region; value} ~file =
let reg = region#to_string ~file ~offsets mode in let reg = region#to_string ~file ~offsets mode in
Printf.sprintf "\027[31mParse error %s:\n%s\027[0m%!" reg value Printf.sprintf "\027[31mParse error %s:\n%s\027[0m%!" reg value
(* Main functor *) (* Main functor *)
module Make (Lexer: Lexer.S) module Make (Lexer: Lexer.S with module Token := LexToken)
(Parser: PARSER with type token = Lexer.Token.token) (Parser: module type of Parser)
(ParErr: PAR_ERR) = (ParErr: sig val message : int -> string end) =
struct struct
type message = string type message = string
type valid = Lexer.token type valid = Lexer.token
@ -94,5 +61,4 @@ module Make (Lexer: Lexer.S)
in close (); ast in close (); ast
let mono_contract = Parser.contract let mono_contract = Parser.contract
end end

View File

@ -1,50 +1,16 @@
(** Generic parser API for LIGO *) (** Generic parser API for LIGO *)
module type PARSER =
sig
(* The type of tokens *)
type token
(* This exception is raised by the monolithic API functions *)
exception Error
(* The monolithic API *)
val contract : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> AST.t
(* The incremental API *)
module MenhirInterpreter :
sig
include MenhirLib.IncrementalEngine.INCREMENTAL_ENGINE
with type token = token
end
module Incremental :
sig
val contract : Lexing.position -> AST.t MenhirInterpreter.checkpoint
end
end
(* Errors *) (* Errors *)
module type PAR_ERR =
sig
val message : int -> string (* From error states to messages *)
end
val format_error : val format_error :
?offsets:bool -> [`Byte | `Point] -> ?offsets:bool -> [`Byte | `Point] ->
string Region.reg -> file:bool -> string string Region.reg -> file:bool -> string
(* Main functor *) (* Main functor *)
module Make (Lexer: Lexer.S) module Make (Lexer: Lexer.S with module Token := LexToken)
(Parser: PARSER with type token = Lexer.Token.token) (Parser: module type of Parser)
(ParErr: PAR_ERR) : (ParErr: sig val message: int -> string end) :
sig sig
type message = string type message = string
type valid = Lexer.token type valid = Lexer.token

View File

@ -15,9 +15,7 @@
Markup Markup
FQueue FQueue
EvalOpt EvalOpt
Version Version))
))
(rule (rule
(targets Version.ml) (targets Version.ml)