2019-12-10 13:47:31 +00:00
|
|
|
%{
|
|
|
|
(* START HEADER *)
|
|
|
|
|
|
|
|
[@@@warning "-42"]
|
|
|
|
|
|
|
|
open Region
|
2019-12-12 14:35:07 +01:00
|
|
|
module AST = Parser_cameligo.AST
|
2019-12-15 17:46:08 +01:00
|
|
|
open! AST
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
type 'a sequence_elements = {
|
2019-12-15 17:46:08 +01:00
|
|
|
s_elts : ('a, semi) Utils.nsepseq;
|
|
|
|
s_terminator : semi option
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type 'a record_elements = {
|
2019-12-15 17:46:08 +01:00
|
|
|
r_elts : (field_assign reg, semi) Utils.nsepseq;
|
|
|
|
r_terminator : semi option
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type 'a sequence_or_record =
|
2019-12-15 17:46:08 +01:00
|
|
|
PaSequence of 'a sequence_elements
|
|
|
|
| PaRecord of 'a record_elements
|
2019-12-10 13:47:31 +00:00
|
|
|
| PaSingleExpr of expr
|
|
|
|
|
2019-12-15 20:59:04 +01:00
|
|
|
let (<@) f g x = f (g x)
|
|
|
|
|
2020-03-04 16:45:05 +01:00
|
|
|
(*
|
|
|
|
Convert a nsepseq to a chain of TFun's.
|
2020-02-25 18:07:53 +01:00
|
|
|
|
2020-01-30 17:38:01 +00:00
|
|
|
Necessary to handle cases like:
|
2020-03-04 16:45:05 +01:00
|
|
|
[type foo = (int, int) => int;]
|
2020-01-30 17:38:01 +00:00
|
|
|
*)
|
2020-03-04 16:45:05 +01:00
|
|
|
|
|
|
|
let rec curry hd = function
|
|
|
|
(sep, item)::rest ->
|
|
|
|
let stop = nsepseq_to_region type_expr_to_region (hd, rest)
|
|
|
|
and start = type_expr_to_region hd in
|
|
|
|
let region = cover start stop
|
|
|
|
and value = hd, sep, curry item rest
|
|
|
|
in TFun {value; region}
|
|
|
|
| [] -> hd
|
2020-01-30 17:38:01 +00:00
|
|
|
|
2019-12-10 13:47:31 +00:00
|
|
|
(* END HEADER *)
|
|
|
|
%}
|
|
|
|
|
|
|
|
(* See [ParToken.mly] for the definition of tokens. *)
|
|
|
|
|
|
|
|
(* Entry points *)
|
|
|
|
|
|
|
|
%start contract interactive_expr
|
|
|
|
%type <AST.t> contract
|
|
|
|
%type <AST.expr> interactive_expr
|
|
|
|
|
2019-12-15 20:59:04 +01:00
|
|
|
(* Solves a shift/reduce problem that happens with record and
|
|
|
|
sequences. To elaborate: [sequence_or_record_in]
|
|
|
|
can be reduced to [expr -> Ident], but also to
|
|
|
|
[field_assignment -> Ident].
|
|
|
|
*)
|
2020-03-04 16:45:05 +01:00
|
|
|
|
2019-12-10 13:47:31 +00:00
|
|
|
%nonassoc Ident
|
2019-12-15 20:59:04 +01:00
|
|
|
%nonassoc COLON
|
|
|
|
|
2019-12-10 13:47:31 +00:00
|
|
|
%%
|
|
|
|
|
|
|
|
(* RULES *)
|
|
|
|
|
|
|
|
(* The rule [sep_or_term(item,sep)] ("separated or terminated list")
|
|
|
|
parses a non-empty list of items separated by [sep], and optionally
|
|
|
|
terminated by [sep]. *)
|
|
|
|
|
|
|
|
sep_or_term_list(item,sep):
|
|
|
|
nsepseq(item,sep) {
|
|
|
|
$1, None
|
|
|
|
}
|
|
|
|
| nseq(item sep {$1,$2}) {
|
|
|
|
let (first,sep), tail = $1 in
|
|
|
|
let rec trans (seq, prev_sep as acc) = function
|
|
|
|
[] -> acc
|
|
|
|
| (item,next_sep)::others ->
|
|
|
|
trans ((prev_sep,item)::seq, next_sep) others in
|
|
|
|
let list, term = trans ([],sep) tail
|
|
|
|
in (first, List.rev list), Some term }
|
|
|
|
|
|
|
|
(* Compound constructs *)
|
|
|
|
|
|
|
|
par(X):
|
2019-12-15 17:46:08 +01:00
|
|
|
"(" X ")" {
|
2019-12-10 13:47:31 +00:00
|
|
|
let region = cover $1 $3
|
2019-12-15 17:46:08 +01:00
|
|
|
and value = {lpar=$1; inside=$2; rpar=$3}
|
|
|
|
in {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
(* Sequences
|
|
|
|
|
|
|
|
Series of instances of the same syntactical category have often to
|
|
|
|
be parsed, like lists of expressions, patterns etc. The simplest of
|
|
|
|
all is the possibly empty sequence (series), parsed below by
|
|
|
|
[seq]. The non-empty sequence is parsed by [nseq]. Note that the
|
|
|
|
latter returns a pair made of the first parsed item (the parameter
|
|
|
|
[X]) and the rest of the sequence (possibly empty). This way, the
|
|
|
|
OCaml typechecker can keep track of this information along the
|
|
|
|
static control-flow graph. The rule [sepseq] parses possibly empty
|
|
|
|
sequences of items separated by some token (e.g., a comma), and
|
|
|
|
rule [nsepseq] is for non-empty such sequences. See module [Utils]
|
|
|
|
for the types corresponding to the semantic actions of those
|
|
|
|
rules.
|
|
|
|
*)
|
|
|
|
|
|
|
|
(* Possibly empty sequence of items *)
|
|
|
|
|
|
|
|
seq(item):
|
|
|
|
(**) { [] }
|
|
|
|
| item seq(item) { $1::$2 }
|
|
|
|
|
|
|
|
(* Non-empty sequence of items *)
|
|
|
|
|
|
|
|
nseq(item):
|
|
|
|
item seq(item) { $1,$2 }
|
|
|
|
|
|
|
|
(* Non-empty separated sequence of items *)
|
|
|
|
|
|
|
|
nsepseq(item,sep):
|
|
|
|
item { $1, [] }
|
|
|
|
| item sep nsepseq(item,sep) { let h,t = $3 in $1, ($2,h)::t }
|
|
|
|
|
|
|
|
(* Helpers *)
|
|
|
|
|
2019-12-15 17:46:08 +01:00
|
|
|
%inline type_name : "<ident>" { $1 }
|
|
|
|
%inline field_name : "<ident>" { $1 }
|
|
|
|
%inline struct_name : "<ident>" { $1 }
|
|
|
|
%inline module_name : "<constr>" { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
(* Non-empty comma-separated values (at least two values) *)
|
|
|
|
|
|
|
|
tuple(item):
|
2019-12-15 17:46:08 +01:00
|
|
|
item "," nsepseq(item,",") { let h,t = $3 in $1,($2,h)::t }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
(* Possibly empty semicolon-separated values between brackets *)
|
|
|
|
|
2020-01-27 16:05:47 +01:00
|
|
|
list__(item):
|
2019-12-15 17:46:08 +01:00
|
|
|
"[" sep_or_term_list(item,";")? "]" {
|
|
|
|
let compound = Brackets ($1,$3)
|
|
|
|
and region = cover $1 $3 in
|
|
|
|
let elements, terminator =
|
|
|
|
match $2 with
|
|
|
|
None -> None, None
|
|
|
|
| Some (elements, terminator) ->
|
|
|
|
Some elements, terminator in
|
|
|
|
let value = {compound; elements; terminator}
|
|
|
|
in {region; value} }
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
|
2019-12-10 13:47:31 +00:00
|
|
|
(* Main *)
|
|
|
|
|
|
|
|
contract:
|
2019-12-15 17:46:08 +01:00
|
|
|
declarations EOF { {decl=$1; eof=$2} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
declarations:
|
|
|
|
declaration { $1,[] : AST.declaration Utils.nseq }
|
|
|
|
| declaration declarations { Utils.nseq_cons $1 $2 }
|
|
|
|
|
|
|
|
declaration:
|
2020-02-04 12:52:12 +01:00
|
|
|
| type_decl ";"? { TypeDecl $1 }
|
|
|
|
| let_declaration ";"? { Let $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
(* Type declarations *)
|
|
|
|
|
|
|
|
type_decl:
|
2019-12-15 17:46:08 +01:00
|
|
|
"type" type_name "=" type_expr {
|
2020-01-14 01:27:35 +01:00
|
|
|
Scoping.check_reserved_name $2;
|
2019-12-15 20:59:04 +01:00
|
|
|
let region = cover $1 (type_expr_to_region $4)
|
|
|
|
and value = {kwd_type = $1;
|
|
|
|
name = $2;
|
|
|
|
eq = $3;
|
|
|
|
type_expr = $4}
|
2019-12-15 17:46:08 +01:00
|
|
|
in {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
type_expr:
|
2020-03-04 16:45:05 +01:00
|
|
|
fun_type | sum_type | record_type { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
2020-03-04 16:45:05 +01:00
|
|
|
fun_type:
|
|
|
|
type_name "=>" fun_type {
|
|
|
|
let region = cover $1.region (type_expr_to_region $3)
|
|
|
|
in TFun {region; value = TVar $1, $2, $3}
|
2020-01-30 17:38:01 +00:00
|
|
|
}
|
2020-03-04 16:45:05 +01:00
|
|
|
| "(" fun_type ")" "=>" fun_type {
|
|
|
|
let region = cover $1 (type_expr_to_region $5)
|
|
|
|
in TFun {region; value = $2,$4,$5}
|
|
|
|
}
|
|
|
|
| "(" tuple(fun_type) ")" "=>" fun_type {
|
|
|
|
let hd, rest = $2 in curry hd (rest @ [($4,$5)])
|
|
|
|
}
|
|
|
|
| "(" tuple(fun_type) ")" {
|
|
|
|
TProd {region = cover $1 $3; value = $2}
|
2020-01-30 17:38:01 +00:00
|
|
|
}
|
2020-03-04 16:45:05 +01:00
|
|
|
| core_type { $1 }
|
|
|
|
|
|
|
|
type_args:
|
|
|
|
tuple(fun_type) { $1 }
|
|
|
|
| fun_type { $1, [] }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
core_type:
|
2019-12-15 17:46:08 +01:00
|
|
|
type_name { TVar $1 }
|
2020-03-04 16:45:05 +01:00
|
|
|
| par(fun_type) { TPar $1 }
|
2019-12-15 17:46:08 +01:00
|
|
|
| module_name "." type_name {
|
2019-12-10 13:47:31 +00:00
|
|
|
let module_name = $1.value in
|
2019-12-15 20:59:04 +01:00
|
|
|
let type_name = $3.value in
|
|
|
|
let value = module_name ^ "." ^ type_name in
|
|
|
|
let region = cover $1.region $3.region
|
2019-12-15 17:46:08 +01:00
|
|
|
in TVar {region; value}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2020-03-04 16:45:05 +01:00
|
|
|
| type_name par(type_args) {
|
|
|
|
let region = cover $1.region $2.region
|
|
|
|
in TApp {region; value = $1,$2} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
sum_type:
|
2020-02-04 10:39:15 +00:00
|
|
|
ioption("|") nsepseq(variant,"|") {
|
2020-01-14 01:27:35 +01:00
|
|
|
Scoping.check_variants (Utils.nsepseq_to_list $2);
|
2019-12-10 13:47:31 +00:00
|
|
|
let region = nsepseq_to_region (fun x -> x.region) $2
|
2019-12-15 17:46:08 +01:00
|
|
|
in TSum {region; value=$2} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
variant:
|
2019-12-15 17:46:08 +01:00
|
|
|
"<constr>" { {$1 with value={constr=$1; arg=None}} }
|
2020-03-04 16:45:05 +01:00
|
|
|
| "<constr>" "(" fun_type ")" {
|
2019-12-10 13:47:31 +00:00
|
|
|
let region = cover $1.region $4
|
2019-12-15 20:59:04 +01:00
|
|
|
and value = {constr=$1; arg = Some (ghost,$3)}
|
2019-12-15 17:46:08 +01:00
|
|
|
in {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
record_type:
|
2019-12-15 17:46:08 +01:00
|
|
|
"{" sep_or_term_list(field_decl,",") "}" {
|
2019-12-10 13:47:31 +00:00
|
|
|
let ne_elements, terminator = $2 in
|
2020-01-14 01:27:35 +01:00
|
|
|
let () = Utils.nsepseq_to_list ne_elements
|
|
|
|
|> Scoping.check_fields in
|
2019-12-10 13:47:31 +00:00
|
|
|
let region = cover $1 $3
|
2019-12-15 17:46:08 +01:00
|
|
|
and value = {compound = Braces ($1,$3); ne_elements; terminator}
|
|
|
|
in TRecord {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
type_expr_field:
|
2019-12-15 17:46:08 +01:00
|
|
|
core_type | sum_type | record_type { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
field_decl:
|
|
|
|
field_name {
|
2019-12-15 20:59:04 +01:00
|
|
|
let value = {field_name=$1; colon=ghost; field_type = TVar $1}
|
2019-12-15 17:46:08 +01:00
|
|
|
in {$1 with value}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| field_name ":" type_expr_field {
|
2019-12-10 13:47:31 +00:00
|
|
|
let stop = type_expr_to_region $3 in
|
|
|
|
let region = cover $1.region stop
|
2019-12-15 17:46:08 +01:00
|
|
|
and value = {field_name=$1; colon=$2; field_type=$3}
|
|
|
|
in {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
2020-03-11 11:18:39 +01:00
|
|
|
(* Top-level definitions *)
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
let_declaration:
|
2020-02-21 16:10:02 +01:00
|
|
|
seq(Attr) "let" ioption("rec") let_binding {
|
2020-01-16 19:36:04 +00:00
|
|
|
let attributes = $1 in
|
2020-01-23 18:28:04 +01:00
|
|
|
let kwd_let = $2 in
|
2020-02-21 16:10:02 +01:00
|
|
|
let kwd_rec = $3 in
|
|
|
|
let binding = $4 in
|
|
|
|
let value = kwd_let, kwd_rec, binding, attributes in
|
2020-01-23 18:28:04 +01:00
|
|
|
let stop = expr_to_region binding.let_rhs in
|
|
|
|
let region = cover $2 stop
|
2019-12-15 17:46:08 +01:00
|
|
|
in {region; value} }
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
|
2019-12-10 13:47:31 +00:00
|
|
|
let_binding:
|
2019-12-15 17:46:08 +01:00
|
|
|
"<ident>" type_annotation? "=" expr {
|
2020-01-14 01:27:35 +01:00
|
|
|
Scoping.check_reserved_name $1;
|
|
|
|
{binders = PVar $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| "_" type_annotation? "=" expr {
|
2020-01-14 01:27:35 +01:00
|
|
|
{binders = PWild $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| unit type_annotation? "=" expr {
|
2020-01-14 01:27:35 +01:00
|
|
|
{binders = PUnit $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| record_pattern type_annotation? "=" expr {
|
2020-01-14 01:27:35 +01:00
|
|
|
Scoping.check_pattern (PRecord $1);
|
2019-12-15 17:46:08 +01:00
|
|
|
{binders = PRecord $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| par(closed_irrefutable) type_annotation? "=" expr {
|
2020-01-14 01:27:35 +01:00
|
|
|
Scoping.check_pattern $1.value.inside;
|
2019-12-15 20:59:04 +01:00
|
|
|
{binders = PPar $1, []; lhs_type=$2; eq=$3; let_rhs=$4}
|
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| tuple(sub_irrefutable) type_annotation? "=" expr {
|
2020-01-14 01:27:35 +01:00
|
|
|
Utils.nsepseq_iter Scoping.check_pattern $1;
|
2019-12-15 17:46:08 +01:00
|
|
|
let hd, tl = $1 in
|
|
|
|
let start = pattern_to_region hd in
|
|
|
|
let stop = last fst tl in
|
|
|
|
let region = cover start stop in
|
|
|
|
let binders = PTuple {value=$1; region}, [] in
|
|
|
|
{binders; lhs_type=$2; eq=$3; let_rhs=$4} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
type_annotation:
|
2019-12-15 17:46:08 +01:00
|
|
|
":" type_expr { $1,$2 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
(* Patterns *)
|
|
|
|
|
|
|
|
irrefutable:
|
2019-12-15 17:46:08 +01:00
|
|
|
sub_irrefutable { $1 }
|
|
|
|
| tuple(sub_irrefutable) {
|
|
|
|
let hd, tl = $1 in
|
|
|
|
let start = pattern_to_region hd in
|
|
|
|
let stop = last fst tl in
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
let region = cover start stop in
|
2019-12-15 17:46:08 +01:00
|
|
|
PTuple {region; value=$1} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
sub_irrefutable:
|
2019-12-15 17:46:08 +01:00
|
|
|
"<ident>" { PVar $1 }
|
|
|
|
| "_" { PWild $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
| unit { PUnit $1 }
|
|
|
|
| record_pattern { PRecord $1 }
|
|
|
|
| par(closed_irrefutable) { PPar $1 }
|
|
|
|
|
|
|
|
closed_irrefutable:
|
|
|
|
irrefutable { $1 }
|
|
|
|
| constr_pattern { PConstr $1 }
|
|
|
|
| typed_pattern { PTyped $1 }
|
|
|
|
|
|
|
|
typed_pattern:
|
2019-12-15 17:46:08 +01:00
|
|
|
irrefutable ":" type_expr {
|
|
|
|
let start = pattern_to_region $1 in
|
|
|
|
let stop = type_expr_to_region $3 in
|
2019-12-10 13:47:31 +00:00
|
|
|
let region = cover start stop in
|
2019-12-15 20:59:04 +01:00
|
|
|
let value = {pattern=$1; colon=$2; type_expr=$3}
|
2019-12-15 17:46:08 +01:00
|
|
|
in {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
pattern:
|
2019-12-15 20:59:04 +01:00
|
|
|
core_pattern { $1 }
|
|
|
|
| "[" sub_pattern "," "..." sub_pattern "]" {
|
2019-12-15 17:46:08 +01:00
|
|
|
let start = pattern_to_region $2 in
|
|
|
|
let stop = pattern_to_region $5 in
|
2019-12-10 13:47:31 +00:00
|
|
|
let region = cover start stop in
|
2019-12-15 17:46:08 +01:00
|
|
|
let cons = {value=$2,$3,$5; region}
|
|
|
|
in PList (PCons cons)
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
| tuple(sub_pattern) {
|
2019-12-15 17:46:08 +01:00
|
|
|
let hd, tl = $1 in
|
|
|
|
let start = pattern_to_region hd in
|
|
|
|
let stop = last fst tl in
|
|
|
|
let region = cover start stop
|
2019-12-15 20:59:04 +01:00
|
|
|
in PTuple {value=$1; region} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
sub_pattern:
|
2019-12-15 17:46:08 +01:00
|
|
|
par(sub_pattern) { PPar $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
| core_pattern { $1 }
|
|
|
|
|
|
|
|
core_pattern:
|
2019-12-15 17:46:08 +01:00
|
|
|
"<ident>" { PVar $1 }
|
|
|
|
| "_" { PWild $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
| unit { PUnit $1 }
|
2019-12-15 17:46:08 +01:00
|
|
|
| "<int>" { PInt $1 }
|
2019-12-24 17:01:39 +01:00
|
|
|
| "<nat>" { PNat $1 }
|
|
|
|
| "<bytes>" { PBytes $1 }
|
2019-12-15 17:46:08 +01:00
|
|
|
| "true" { PTrue $1 }
|
|
|
|
| "false" { PFalse $1 }
|
|
|
|
| "<string>" { PString $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
| par(ptuple) { PPar $1 }
|
2020-01-27 16:05:47 +01:00
|
|
|
| list__(sub_pattern) { PList (PListComp $1) }
|
2019-12-10 13:47:31 +00:00
|
|
|
| constr_pattern { PConstr $1 }
|
|
|
|
| record_pattern { PRecord $1 }
|
|
|
|
|
|
|
|
record_pattern:
|
2019-12-15 17:46:08 +01:00
|
|
|
"{" sep_or_term_list(field_pattern,",") "}" {
|
2019-12-10 13:47:31 +00:00
|
|
|
let ne_elements, terminator = $2 in
|
|
|
|
let region = cover $1 $3 in
|
2019-12-15 20:59:04 +01:00
|
|
|
let value = {compound = Braces ($1,$3);
|
|
|
|
ne_elements;
|
|
|
|
terminator}
|
2019-12-15 17:46:08 +01:00
|
|
|
in {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
field_pattern:
|
2019-12-15 17:46:08 +01:00
|
|
|
field_name "=" sub_pattern {
|
|
|
|
let start = $1.region in
|
|
|
|
let stop = pattern_to_region $3 in
|
2019-12-10 13:47:31 +00:00
|
|
|
let region = cover start stop in
|
2019-12-15 17:46:08 +01:00
|
|
|
let value = {field_name=$1; eq=$2; pattern=$3}
|
|
|
|
in {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
constr_pattern:
|
2019-12-15 17:46:08 +01:00
|
|
|
"None" { PNone $1 }
|
|
|
|
| "Some" sub_pattern {
|
2019-12-10 13:47:31 +00:00
|
|
|
let stop = pattern_to_region $2 in
|
|
|
|
let region = cover $1 stop
|
2019-12-15 17:46:08 +01:00
|
|
|
and value = $1, $2 in
|
|
|
|
PSomeApp {region; value}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| "<constr>" sub_pattern {
|
|
|
|
let region = cover $1.region (pattern_to_region $2)
|
|
|
|
in PConstrApp {region; value = $1, Some $2}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| "<constr>" { PConstrApp {$1 with value=$1,None} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
ptuple:
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
tuple(sub_pattern) {
|
2019-12-15 17:46:08 +01:00
|
|
|
let hd, tl = $1 in
|
|
|
|
let start = pattern_to_region hd in
|
|
|
|
let stop = last fst tl in
|
|
|
|
let region = cover start stop
|
|
|
|
in PTuple {value=$1; region} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
unit:
|
2020-01-08 16:39:52 +01:00
|
|
|
"(" ")" { {region = cover $1 $2; value = $1, $2} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
(* Expressions *)
|
|
|
|
|
|
|
|
interactive_expr:
|
2020-02-03 10:53:44 +01:00
|
|
|
expr_with_let_expr EOF { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
expr:
|
2019-12-15 20:59:04 +01:00
|
|
|
base_cond__open(expr) | switch_expr(base_cond) { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
base_cond__open(x):
|
2020-02-03 10:53:44 +01:00
|
|
|
base_expr(x) | conditional(expr_with_let_expr) { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
base_cond:
|
2019-12-15 17:46:08 +01:00
|
|
|
base_cond__open(base_cond) { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
type_expr_simple_args:
|
2019-12-15 20:59:04 +01:00
|
|
|
par(nsepseq(type_expr_simple, ",")) { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
type_expr_simple:
|
2019-12-16 14:54:12 +01:00
|
|
|
type_name type_expr_simple_args? {
|
2019-12-10 13:47:31 +00:00
|
|
|
let args = $2 in
|
2019-12-16 14:54:12 +01:00
|
|
|
match args with
|
|
|
|
Some {value; _} ->
|
|
|
|
let region = cover $1.region value.rpar in
|
|
|
|
let value = $1, {region; value}
|
|
|
|
in TApp {region; value}
|
|
|
|
| None -> TVar $1
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| "(" nsepseq(type_expr_simple, ",") ")" {
|
2019-12-15 20:59:04 +01:00
|
|
|
TProd {region = cover $1 $3; value=$2}
|
2019-12-15 17:46:08 +01:00
|
|
|
}
|
|
|
|
| "(" type_expr_simple "=>" type_expr_simple ")" {
|
2019-12-15 20:59:04 +01:00
|
|
|
TFun {region = cover $1 $5; value=$2,$3,$4} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
type_annotation_simple:
|
2019-12-15 17:46:08 +01:00
|
|
|
":" type_expr_simple { $1,$2 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
fun_expr:
|
2020-03-04 16:45:05 +01:00
|
|
|
disj_expr_level "=>" expr {
|
|
|
|
let arrow, body = $2, $3
|
|
|
|
and kwd_fun = ghost in
|
|
|
|
let start = expr_to_region $1
|
|
|
|
and stop = expr_to_region body in
|
2019-12-15 20:59:04 +01:00
|
|
|
let region = cover start stop in
|
|
|
|
|
|
|
|
let rec arg_to_pattern = function
|
2020-01-14 01:27:35 +01:00
|
|
|
EVar v ->
|
|
|
|
Scoping.check_reserved_name v;
|
|
|
|
PVar v
|
2019-12-15 20:59:04 +01:00
|
|
|
| EAnnot {region; value = {inside = EVar v, colon, typ; _}} ->
|
2020-01-14 01:27:35 +01:00
|
|
|
Scoping.check_reserved_name v;
|
2019-12-15 20:59:04 +01:00
|
|
|
let value = {pattern = PVar v; colon; type_expr = typ}
|
|
|
|
in PTyped {region; value}
|
|
|
|
| EPar p ->
|
|
|
|
let value =
|
|
|
|
{p.value with inside = arg_to_pattern p.value.inside}
|
|
|
|
in PPar {p with value}
|
|
|
|
| EUnit u -> PUnit u
|
2020-01-23 18:28:04 +01:00
|
|
|
| ETuple { value; region } ->
|
2020-01-20 19:03:00 +01:00
|
|
|
PTuple { value = Utils.nsepseq_map arg_to_pattern value; region}
|
2020-01-23 18:28:04 +01:00
|
|
|
| EAnnot {region; value = {inside = t, colon, typ; _}} ->
|
2020-01-20 19:03:00 +01:00
|
|
|
let value = { pattern = arg_to_pattern t; colon; type_expr = typ} in
|
|
|
|
PPar {
|
|
|
|
value = {
|
|
|
|
lpar = Region.ghost;
|
2020-01-23 18:28:04 +01:00
|
|
|
rpar = Region.ghost;
|
2020-01-20 19:03:00 +01:00
|
|
|
inside = PTyped {region; value}
|
|
|
|
};
|
|
|
|
region
|
|
|
|
}
|
2020-01-23 18:28:04 +01:00
|
|
|
| e ->
|
|
|
|
let open! SyntaxError in
|
|
|
|
raise (Error (WrongFunctionArguments e)) in
|
2019-12-15 20:59:04 +01:00
|
|
|
let fun_args_to_pattern = function
|
2019-12-15 17:46:08 +01:00
|
|
|
EAnnot {
|
|
|
|
value = {
|
|
|
|
inside = ETuple {value=fun_args; _}, _, _;
|
|
|
|
_};
|
|
|
|
_} ->
|
|
|
|
(* ((foo:x, bar) : type) *)
|
|
|
|
let bindings =
|
2019-12-15 20:59:04 +01:00
|
|
|
List.map (arg_to_pattern <@ snd) (snd fun_args)
|
2019-12-15 17:46:08 +01:00
|
|
|
in arg_to_pattern (fst fun_args), bindings
|
|
|
|
| EAnnot {
|
|
|
|
value = {
|
|
|
|
inside = EPar {value = {inside=fun_arg; _}; _}, _, _;
|
|
|
|
_};
|
|
|
|
_} ->
|
|
|
|
(* ((foo:x, bar) : type) *)
|
2019-12-15 20:59:04 +01:00
|
|
|
(arg_to_pattern fun_arg, [])
|
2020-01-30 17:38:01 +00:00
|
|
|
| EPar {value = {inside = EFun {
|
|
|
|
value = {
|
|
|
|
binders = PTyped { value = { pattern; colon; type_expr }; region = fun_region }, [];
|
|
|
|
arrow;
|
|
|
|
body;
|
|
|
|
_
|
|
|
|
};
|
|
|
|
_
|
|
|
|
}; _ }; region} ->
|
|
|
|
|
2020-02-25 18:07:53 +01:00
|
|
|
let expr_to_type = function
|
2020-01-30 17:38:01 +00:00
|
|
|
| EVar v -> TVar v
|
|
|
|
| e -> let open! SyntaxError
|
|
|
|
in raise (Error (WrongFunctionArguments e))
|
|
|
|
in
|
|
|
|
let type_expr = (
|
|
|
|
match type_expr with
|
2020-02-25 18:07:53 +01:00
|
|
|
| TProd {value; _} ->
|
2020-01-30 17:38:01 +00:00
|
|
|
let (hd, rest) = value in
|
2020-03-04 16:45:05 +01:00
|
|
|
let rest = rest @ [(arrow, expr_to_type body)]
|
|
|
|
in curry hd rest
|
2020-02-25 18:07:53 +01:00
|
|
|
| e ->
|
2020-01-30 17:38:01 +00:00
|
|
|
TFun {
|
|
|
|
value = e, arrow, expr_to_type body;
|
|
|
|
region = fun_region
|
2020-02-25 18:07:53 +01:00
|
|
|
}
|
2020-01-30 17:38:01 +00:00
|
|
|
)
|
2020-02-25 18:07:53 +01:00
|
|
|
in
|
2020-01-30 17:38:01 +00:00
|
|
|
PTyped {
|
|
|
|
value = {
|
|
|
|
pattern;
|
|
|
|
colon;
|
|
|
|
type_expr
|
2020-02-25 18:07:53 +01:00
|
|
|
};
|
2020-01-30 17:38:01 +00:00
|
|
|
region;
|
|
|
|
}, []
|
|
|
|
| EPar {value = {inside = fun_arg; _ }; _} ->
|
2019-12-15 17:46:08 +01:00
|
|
|
arg_to_pattern fun_arg, []
|
2020-01-30 17:38:01 +00:00
|
|
|
| EAnnot _ as e ->
|
|
|
|
arg_to_pattern e, []
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
| ETuple {value = fun_args; _} ->
|
2019-12-15 20:59:04 +01:00
|
|
|
let bindings =
|
2020-01-14 01:27:35 +01:00
|
|
|
List.map (arg_to_pattern <@ snd) (snd fun_args) in
|
|
|
|
List.iter Scoping.check_pattern bindings;
|
|
|
|
arg_to_pattern (fst fun_args), bindings
|
2020-01-30 17:38:01 +00:00
|
|
|
| EUnit _ as e ->
|
|
|
|
arg_to_pattern e, []
|
2020-02-25 18:07:53 +01:00
|
|
|
| EVar _ as e ->
|
2020-01-30 17:38:01 +00:00
|
|
|
arg_to_pattern e, []
|
2019-12-24 17:01:39 +01:00
|
|
|
| e -> let open! SyntaxError
|
|
|
|
in raise (Error (WrongFunctionArguments e))
|
2019-12-16 15:52:45 +01:00
|
|
|
in
|
2019-12-10 13:47:31 +00:00
|
|
|
let binders = fun_args_to_pattern $1 in
|
2020-03-07 02:00:29 +01:00
|
|
|
let lhs_type = match $1 with
|
|
|
|
EAnnot {value = {inside = _ , _, t; _}; region = r} -> Some (r,t)
|
|
|
|
| _ -> None
|
|
|
|
in
|
2019-12-15 20:59:04 +01:00
|
|
|
let f = {kwd_fun;
|
|
|
|
binders;
|
2020-03-07 02:00:29 +01:00
|
|
|
lhs_type;
|
2019-12-15 20:59:04 +01:00
|
|
|
arrow;
|
2020-01-16 19:36:04 +00:00
|
|
|
body
|
|
|
|
}
|
2019-12-15 20:59:04 +01:00
|
|
|
in EFun {region; value=f} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
base_expr(right_expr):
|
2020-02-03 10:53:44 +01:00
|
|
|
disj_expr_level | fun_expr { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
conditional(right_expr):
|
2019-12-15 17:46:08 +01:00
|
|
|
if_then_else(right_expr) | if_then(right_expr) { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
parenthesized_expr:
|
2019-12-15 17:46:08 +01:00
|
|
|
"{" expr "}" | "(" expr ")" { $2 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
if_then(right_expr):
|
2020-02-04 12:52:12 +01:00
|
|
|
"if" parenthesized_expr "{" closed_if ";"? "}" {
|
2019-12-10 13:47:31 +00:00
|
|
|
let the_unit = ghost, ghost in
|
|
|
|
let ifnot = EUnit {region=ghost; value=the_unit} in
|
2020-02-04 12:52:12 +01:00
|
|
|
let region = cover $1 $6 in
|
2019-12-15 20:59:04 +01:00
|
|
|
let value = {kwd_if = $1;
|
|
|
|
test = $2;
|
|
|
|
kwd_then = $3;
|
|
|
|
ifso = $4;
|
|
|
|
kwd_else = ghost;
|
|
|
|
ifnot}
|
|
|
|
in ECond {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
if_then_else(right_expr):
|
2020-02-04 12:52:12 +01:00
|
|
|
"if" parenthesized_expr "{" closed_if ";"? "}"
|
|
|
|
"else" "{" right_expr ";"? "}" {
|
2019-12-10 13:47:31 +00:00
|
|
|
let region = cover $1 $11 in
|
2019-12-15 20:59:04 +01:00
|
|
|
let value = {kwd_if = $1;
|
|
|
|
test = $2;
|
|
|
|
kwd_then = $3;
|
|
|
|
ifso = $4;
|
|
|
|
kwd_else = $6;
|
|
|
|
ifnot = $9}
|
|
|
|
in ECond {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
base_if_then_else__open(x):
|
2019-12-15 17:46:08 +01:00
|
|
|
base_expr(x) | if_then_else(x) { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
base_if_then_else:
|
2019-12-15 17:46:08 +01:00
|
|
|
base_if_then_else__open(base_if_then_else) { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
closed_if:
|
2019-12-15 17:46:08 +01:00
|
|
|
base_if_then_else__open(closed_if)
|
|
|
|
| switch_expr(base_if_then_else) { $1 }
|
2020-02-03 10:53:44 +01:00
|
|
|
| let_expr(expr_with_let_expr) { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
switch_expr(right_expr):
|
2019-12-15 17:46:08 +01:00
|
|
|
"switch" switch_expr_ "{" cases(right_expr) "}" {
|
2019-12-15 20:59:04 +01:00
|
|
|
let start = $1
|
|
|
|
and stop = $5 in
|
2019-12-15 17:46:08 +01:00
|
|
|
let region = cover start stop
|
2019-12-15 20:59:04 +01:00
|
|
|
and cases = {
|
|
|
|
region = nsepseq_to_region (fun x -> x.region) $4;
|
2020-01-14 01:27:35 +01:00
|
|
|
value = $4} in
|
2019-12-15 20:59:04 +01:00
|
|
|
let value = {
|
|
|
|
kwd_match = $1;
|
|
|
|
expr = $2;
|
|
|
|
lead_vbar = None;
|
|
|
|
kwd_with = ghost;
|
|
|
|
cases}
|
2019-12-15 17:46:08 +01:00
|
|
|
in ECase {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
switch_expr_:
|
2019-12-15 17:46:08 +01:00
|
|
|
par(expr) { $1.value.inside }
|
|
|
|
| core_expr_2 { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
cases(right_expr):
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
nseq(case_clause(right_expr)) {
|
2019-12-15 17:46:08 +01:00
|
|
|
let hd, tl = $1 in
|
2019-12-15 20:59:04 +01:00
|
|
|
hd, List.map (fun f -> expr_to_region f.value.rhs, f) tl }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
case_clause(right_expr):
|
2019-12-15 17:46:08 +01:00
|
|
|
"|" pattern "=>" right_expr ";"? {
|
2020-01-14 01:27:35 +01:00
|
|
|
Scoping.check_pattern $2;
|
2019-12-15 17:46:08 +01:00
|
|
|
let start = pattern_to_region $2
|
|
|
|
and stop = expr_to_region $4 in
|
|
|
|
let region = cover start stop
|
|
|
|
and value = {pattern=$2; arrow=$3; rhs=$4}
|
|
|
|
in {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
let_expr(right_expr):
|
2020-02-20 22:31:47 +01:00
|
|
|
seq(Attr) "let" ioption("rec") let_binding ";" right_expr {
|
2020-01-23 18:28:04 +01:00
|
|
|
let attributes = $1 in
|
|
|
|
let kwd_let = $2 in
|
2020-02-20 22:31:47 +01:00
|
|
|
let kwd_rec = $3 in
|
|
|
|
let binding = $4 in
|
|
|
|
let kwd_in = $5 in
|
|
|
|
let body = $6 in
|
|
|
|
let stop = expr_to_region $6 in
|
2020-01-16 19:36:04 +00:00
|
|
|
let region = cover $2 stop
|
2020-02-20 22:31:47 +01:00
|
|
|
and value = {kwd_let; kwd_rec; binding; kwd_in; body; attributes}
|
2019-12-15 17:46:08 +01:00
|
|
|
in ELetIn {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
disj_expr_level:
|
2019-12-15 17:46:08 +01:00
|
|
|
disj_expr
|
|
|
|
| conj_expr_level { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
| par(tuple(disj_expr_level)) type_annotation_simple? {
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
let region = $1.region in
|
2019-12-15 20:59:04 +01:00
|
|
|
let tuple = ETuple {value=$1.value.inside; region} in
|
2019-12-15 17:46:08 +01:00
|
|
|
let region =
|
|
|
|
match $2 with
|
|
|
|
Some (_,s) -> cover $1.region (type_expr_to_region s)
|
2019-12-15 20:59:04 +01:00
|
|
|
| None -> region in
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
match $2 with
|
2019-12-15 17:46:08 +01:00
|
|
|
Some (colon, typ) ->
|
|
|
|
let value = {$1.value with inside = tuple,colon,typ}
|
|
|
|
in EAnnot {region; value}
|
|
|
|
| None -> tuple }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
bin_op(arg1,op,arg2):
|
2019-12-15 17:46:08 +01:00
|
|
|
arg1 op arg2 {
|
2019-12-10 13:47:31 +00:00
|
|
|
let start = expr_to_region $1 in
|
|
|
|
let stop = expr_to_region $3 in
|
2019-12-15 17:46:08 +01:00
|
|
|
let region = cover start stop
|
|
|
|
and value = { arg1=$1; op=$2; arg2=$3}
|
|
|
|
in {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
disj_expr:
|
2019-12-15 17:46:08 +01:00
|
|
|
bin_op(disj_expr_level, "||", conj_expr_level)
|
|
|
|
| bin_op(disj_expr_level, "or", conj_expr_level) {
|
|
|
|
ELogic (BoolExpr (Or $1)) }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
conj_expr_level:
|
2019-12-15 20:59:04 +01:00
|
|
|
comp_expr_level { $1 }
|
|
|
|
| bin_op(conj_expr_level, "&&", comp_expr_level) {
|
2019-12-15 17:46:08 +01:00
|
|
|
ELogic (BoolExpr (And $1)) }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
comp_expr_level:
|
2019-12-15 17:46:08 +01:00
|
|
|
bin_op(comp_expr_level, "<", cat_expr_level) {
|
|
|
|
ELogic (CompExpr (Lt $1)) }
|
|
|
|
| bin_op(comp_expr_level, "<=", cat_expr_level) {
|
|
|
|
ELogic (CompExpr (Leq $1)) }
|
|
|
|
| bin_op(comp_expr_level, ">", cat_expr_level) {
|
|
|
|
ELogic (CompExpr (Gt $1)) }
|
|
|
|
| bin_op(comp_expr_level, ">=", cat_expr_level) {
|
|
|
|
ELogic (CompExpr (Geq $1)) }
|
|
|
|
| bin_op(comp_expr_level, "==", cat_expr_level) {
|
|
|
|
ELogic (CompExpr (Equal $1)) }
|
|
|
|
| bin_op(comp_expr_level, "!=", cat_expr_level) {
|
|
|
|
ELogic (CompExpr (Neq $1)) }
|
|
|
|
| cat_expr_level { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
cat_expr_level:
|
2019-12-24 17:01:39 +01:00
|
|
|
bin_op(add_expr_level, "++", cat_expr_level) { EString (Cat $1) }
|
2019-12-10 13:47:31 +00:00
|
|
|
| add_expr_level { $1 }
|
|
|
|
|
|
|
|
add_expr_level:
|
2019-12-15 17:46:08 +01:00
|
|
|
bin_op(add_expr_level, "+", mult_expr_level) { EArith (Add $1) }
|
|
|
|
| bin_op(add_expr_level, "-", mult_expr_level) { EArith (Sub $1) }
|
2019-12-10 13:47:31 +00:00
|
|
|
| mult_expr_level { $1 }
|
|
|
|
|
|
|
|
mult_expr_level:
|
2019-12-15 17:46:08 +01:00
|
|
|
bin_op(mult_expr_level, "*", unary_expr_level) { EArith (Mult $1) }
|
|
|
|
| bin_op(mult_expr_level, "/", unary_expr_level) { EArith (Div $1) }
|
|
|
|
| bin_op(mult_expr_level, "mod", unary_expr_level) { EArith (Mod $1) }
|
|
|
|
| unary_expr_level { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
unary_expr_level:
|
2019-12-15 17:46:08 +01:00
|
|
|
call_expr_level { $1 }
|
|
|
|
| "-" call_expr_level {
|
|
|
|
let start = $1 in
|
|
|
|
let stop = expr_to_region $2 in
|
|
|
|
let region = cover start stop
|
|
|
|
and value = {op=$1; arg=$2}
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
in EArith (Neg {region; value})
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| "!" call_expr_level {
|
|
|
|
let start = $1 in
|
|
|
|
let stop = expr_to_region $2 in
|
|
|
|
let region = cover start stop
|
|
|
|
and value = {op=$1; arg=$2} in
|
|
|
|
ELogic (BoolExpr (Not {region; value})) }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
call_expr_level:
|
2019-12-10 13:47:31 +00:00
|
|
|
call_expr_level_in type_annotation_simple? {
|
2019-12-15 17:46:08 +01:00
|
|
|
let region =
|
|
|
|
match $2 with
|
|
|
|
Some (_, s) ->
|
|
|
|
cover (expr_to_region $1) (type_expr_to_region s)
|
|
|
|
| None -> expr_to_region $1 in
|
2019-12-10 13:47:31 +00:00
|
|
|
match $2 with
|
2019-12-15 17:46:08 +01:00
|
|
|
Some (colon, t) ->
|
2019-12-15 20:59:04 +01:00
|
|
|
let value = {lpar=ghost; inside=$1,colon,t; rpar=ghost}
|
2019-12-15 17:46:08 +01:00
|
|
|
in EAnnot {region; value}
|
|
|
|
| None -> $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
call_expr_level_in:
|
2019-12-15 17:46:08 +01:00
|
|
|
call_expr | constr_expr | core_expr { $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
constr_expr:
|
2019-12-15 17:46:08 +01:00
|
|
|
"None" {
|
|
|
|
EConstr (ENone $1)
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| "Some" core_expr {
|
2019-12-10 13:47:31 +00:00
|
|
|
let region = cover $1 (expr_to_region $2)
|
2019-12-15 17:46:08 +01:00
|
|
|
in EConstr (ESomeApp {value=$1,$2; region})
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| "<constr>" core_expr {
|
|
|
|
let region = cover $1.region (expr_to_region $2) in
|
|
|
|
EConstr (EConstrApp {region; value=$1, Some $2})
|
|
|
|
}
|
|
|
|
| "<constr>" {
|
|
|
|
EConstr (EConstrApp {$1 with value=$1, None}) }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
call_expr:
|
2019-12-15 17:46:08 +01:00
|
|
|
core_expr "(" nsepseq(expr, ",") ")" {
|
|
|
|
let start = expr_to_region $1 in
|
|
|
|
let stop = $4 in
|
2019-12-10 13:47:31 +00:00
|
|
|
let region = cover start stop in
|
|
|
|
let hd, tl = $3 in
|
2019-12-15 17:46:08 +01:00
|
|
|
let tl = List.map snd tl in
|
|
|
|
ECall {region; value = $1,(hd,tl)}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| core_expr unit {
|
|
|
|
let start = expr_to_region $1 in
|
|
|
|
let stop = $2.region in
|
|
|
|
let region = cover start stop
|
|
|
|
and value = $1, (EUnit $2, [])
|
|
|
|
in ECall {region; value} }
|
|
|
|
|
|
|
|
common_expr:
|
|
|
|
"<int>" { EArith (Int $1) }
|
|
|
|
| "<mutez>" { EArith (Mutez $1) }
|
|
|
|
| "<nat>" { EArith (Nat $1) }
|
2019-12-24 17:01:39 +01:00
|
|
|
| "<bytes>" { EBytes $1 }
|
2019-12-15 17:46:08 +01:00
|
|
|
| "<ident>" | module_field { EVar $1 }
|
|
|
|
| projection { EProj $1 }
|
2020-01-10 14:55:14 +01:00
|
|
|
| update_record { EUpdate $1 }
|
2019-12-15 17:46:08 +01:00
|
|
|
| "<string>" { EString (String $1) }
|
|
|
|
| unit { EUnit $1 }
|
|
|
|
| "false" { ELogic (BoolExpr (False $1)) }
|
|
|
|
| "true" { ELogic (BoolExpr (True $1)) }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
core_expr_2:
|
2020-01-27 16:05:47 +01:00
|
|
|
common_expr { $1 }
|
|
|
|
| list__(expr) { EList (EListComp $1) }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
list_or_spread:
|
2019-12-15 17:46:08 +01:00
|
|
|
"[" expr "," sep_or_term_list(expr, ",") "]" {
|
|
|
|
let elts, terminator = $4 in
|
|
|
|
let elts = Utils.nsepseq_cons $2 $3 elts in
|
|
|
|
let value = {
|
|
|
|
compound = Brackets ($1,$5);
|
|
|
|
elements = Some elts;
|
|
|
|
terminator}
|
|
|
|
and region = cover $1 $5 in
|
|
|
|
EList (EListComp {region; value})
|
|
|
|
}
|
|
|
|
| "[" expr "," "..." expr "]" {
|
|
|
|
let region = cover $1 $6
|
|
|
|
and value = {arg1=$2; op=$4; arg2=$5}
|
|
|
|
in EList (ECons {region; value})
|
|
|
|
}
|
|
|
|
| "[" expr? "]" {
|
|
|
|
let compound = Brackets ($1,$3)
|
|
|
|
and elements =
|
|
|
|
match $2 with
|
|
|
|
None -> None
|
|
|
|
| Some element -> Some (element, []) in
|
|
|
|
let value = {compound; elements; terminator=None}
|
|
|
|
and region = cover $1 $3 in
|
|
|
|
EList (EListComp {region; value}) }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
core_expr:
|
2019-12-15 17:46:08 +01:00
|
|
|
common_expr
|
|
|
|
| list_or_spread
|
|
|
|
| sequence_or_record { $1 }
|
|
|
|
| par(expr) { EPar $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
module_field:
|
2020-02-25 18:07:53 +01:00
|
|
|
module_name "." module_fun {
|
|
|
|
let region = cover $1.region $3.region in
|
|
|
|
{region; value = $1.value ^ "." ^ $3.value} }
|
|
|
|
|
|
|
|
module_fun:
|
|
|
|
field_name { $1 }
|
|
|
|
| "or" { {value="or"; region=$1} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
selection:
|
2019-12-15 17:46:08 +01:00
|
|
|
"[" "<int>" "]" selection {
|
2019-12-15 20:59:04 +01:00
|
|
|
let r, (hd, tl) = $4 in
|
2019-12-15 17:46:08 +01:00
|
|
|
let result: (selection, dot) Utils.nsepseq =
|
2019-12-15 20:59:04 +01:00
|
|
|
Component $2, (ghost, hd) :: tl
|
2019-12-15 17:46:08 +01:00
|
|
|
in r, result
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| "." field_name selection {
|
2019-12-15 20:59:04 +01:00
|
|
|
let r, (hd, tl) = $3 in
|
2019-12-15 17:46:08 +01:00
|
|
|
let result: (selection, dot) Utils.nsepseq =
|
2019-12-15 20:59:04 +01:00
|
|
|
FieldName $2, ($1, hd) :: tl
|
2019-12-15 17:46:08 +01:00
|
|
|
in r, result
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 20:59:04 +01:00
|
|
|
| "." field_name { $1, (FieldName $2, []) }
|
|
|
|
| "[" "<int>" "]" { ghost, (Component $2, []) }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
projection:
|
|
|
|
struct_name selection {
|
2019-12-15 17:46:08 +01:00
|
|
|
let start = $1.region in
|
|
|
|
let stop = nsepseq_to_region selection_to_region (snd $2) in
|
|
|
|
let region = cover start stop
|
2019-12-15 20:59:04 +01:00
|
|
|
and value = {struct_name = $1;
|
|
|
|
selector = fst $2;
|
|
|
|
field_path = snd $2}
|
2019-12-15 17:46:08 +01:00
|
|
|
in {region; value}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| module_name "." field_name selection {
|
2019-12-10 13:47:31 +00:00
|
|
|
let module_name = $1 in
|
2019-12-15 17:46:08 +01:00
|
|
|
let field_name = $3 in
|
|
|
|
let value = module_name.value ^ "." ^ field_name.value in
|
2019-12-10 13:47:31 +00:00
|
|
|
let struct_name = {$1 with value} in
|
2019-12-15 17:46:08 +01:00
|
|
|
let start = $1.region in
|
|
|
|
let stop = nsepseq_to_region selection_to_region (snd $4) in
|
|
|
|
let region = cover start stop
|
2019-12-15 20:59:04 +01:00
|
|
|
and value = {struct_name;
|
|
|
|
selector = fst $4;
|
|
|
|
field_path = snd $4}
|
2019-12-15 17:46:08 +01:00
|
|
|
in {region; value} }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
2020-01-29 16:49:42 +01:00
|
|
|
path:
|
|
|
|
"<ident>" { Name $1 }
|
|
|
|
| projection { Path $1 }
|
2020-01-10 14:55:14 +01:00
|
|
|
|
2020-01-29 16:49:42 +01:00
|
|
|
update_record:
|
2020-01-28 14:12:46 +00:00
|
|
|
"{""..."path "," sep_or_term_list(field_path_assignment,",") "}" {
|
2020-01-10 14:55:14 +01:00
|
|
|
let region = cover $1 $6 in
|
|
|
|
let ne_elements, terminator = $5 in
|
|
|
|
let value = {
|
|
|
|
lbrace = $1;
|
|
|
|
record = $3;
|
|
|
|
kwd_with = $4;
|
|
|
|
updates = { value = {compound = Braces($1,$6);
|
|
|
|
ne_elements;
|
|
|
|
terminator};
|
|
|
|
region = cover $4 $6};
|
|
|
|
rbrace = $6}
|
|
|
|
in {region; value} }
|
|
|
|
|
2020-02-03 10:53:44 +01:00
|
|
|
expr_with_let_expr:
|
|
|
|
expr { $1 }
|
|
|
|
| let_expr(expr_with_let_expr) { $1 }
|
|
|
|
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
sequence_or_record_in:
|
2020-02-03 10:53:44 +01:00
|
|
|
expr_with_let_expr ";" sep_or_term_list(expr_with_let_expr,";") {
|
2019-12-15 17:46:08 +01:00
|
|
|
let elts, _region = $3 in
|
|
|
|
let s_elts = Utils.nsepseq_cons $1 $2 elts
|
|
|
|
in PaSequence {s_elts; s_terminator=None}
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| field_assignment "," sep_or_term_list(field_assignment,",") {
|
|
|
|
let elts, _region = $3 in
|
|
|
|
let r_elts = Utils.nsepseq_cons $1 $2 elts
|
|
|
|
in PaRecord {r_elts; r_terminator = None}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2020-02-03 10:53:44 +01:00
|
|
|
| expr_with_let_expr ";"? { PaSingleExpr $1 }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
sequence_or_record:
|
2019-12-15 17:46:08 +01:00
|
|
|
"{" sequence_or_record_in "}" {
|
2020-01-08 16:39:52 +01:00
|
|
|
let compound = Braces ($1,$3) in
|
2019-12-15 20:59:04 +01:00
|
|
|
let region = cover $1 $3 in
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
match $2 with
|
2019-12-15 17:46:08 +01:00
|
|
|
PaSequence s ->
|
2019-12-15 20:59:04 +01:00
|
|
|
let value = {compound;
|
|
|
|
elements = Some s.s_elts;
|
|
|
|
terminator = s.s_terminator}
|
|
|
|
in ESeq {region; value}
|
2019-12-15 17:46:08 +01:00
|
|
|
| PaRecord r ->
|
2019-12-15 20:59:04 +01:00
|
|
|
let value = {compound;
|
|
|
|
ne_elements = r.r_elts;
|
|
|
|
terminator = r.r_terminator}
|
|
|
|
in ERecord {region; value}
|
2019-12-15 17:46:08 +01:00
|
|
|
| PaSingleExpr e -> e }
|
2019-12-10 13:47:31 +00:00
|
|
|
|
|
|
|
field_assignment:
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
field_name {
|
2019-12-15 17:46:08 +01:00
|
|
|
let value = {
|
|
|
|
field_name = $1;
|
2019-12-15 20:59:04 +01:00
|
|
|
assignment = ghost;
|
2019-12-15 17:46:08 +01:00
|
|
|
field_expr = EVar $1 }
|
|
|
|
in {$1 with value}
|
2019-12-10 13:47:31 +00:00
|
|
|
}
|
2019-12-15 17:46:08 +01:00
|
|
|
| field_name ":" expr {
|
|
|
|
let start = $1.region in
|
|
|
|
let stop = expr_to_region $3 in
|
2019-12-10 13:47:31 +00:00
|
|
|
let region = cover start stop in
|
2019-12-15 17:46:08 +01:00
|
|
|
let value = {
|
|
|
|
field_name = $1;
|
|
|
|
assignment = $2;
|
|
|
|
field_expr = $3}
|
|
|
|
in {region; value} }
|
2020-01-28 14:12:46 +00:00
|
|
|
|
|
|
|
field_path_assignment:
|
|
|
|
field_name {
|
|
|
|
let value = {
|
|
|
|
field_path = ($1,[]);
|
|
|
|
assignment = ghost;
|
|
|
|
field_expr = EVar $1 }
|
|
|
|
in {$1 with value}
|
|
|
|
}
|
|
|
|
| nsepseq(field_name,".") ":" expr {
|
|
|
|
let start = nsepseq_to_region (fun x -> x.region) $1 in
|
|
|
|
let stop = expr_to_region $3 in
|
|
|
|
let region = cover start stop in
|
|
|
|
let value = {
|
|
|
|
field_path = $1;
|
|
|
|
assignment = $2;
|
|
|
|
field_expr = $3}
|
|
|
|
in {region; value} }
|