2022-03-08 17:03:14 +03:00
|
|
|
(* This file is part of the Catala compiler, a specification language for tax
|
|
|
|
and social benefits computation rules. Copyright (C) 2020 Inria,
|
|
|
|
contributors: Denis Merigoux <denis.merigoux@inria.fr>, Emile Rolley
|
|
|
|
<emile.rolley@tuta.io>
|
2020-03-08 02:21:55 +03:00
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
the License at
|
2020-03-08 02:21:55 +03:00
|
|
|
|
2020-03-09 14:01:56 +03:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2020-03-08 02:21:55 +03:00
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
License for the specific language governing permissions and limitations under
|
2020-03-09 14:01:56 +03:00
|
|
|
the License. *)
|
2020-03-08 02:21:55 +03:00
|
|
|
|
2021-05-03 19:03:17 +03:00
|
|
|
(** Abstract syntax tree built by the Catala parser *)
|
|
|
|
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@@ocaml.warning "-7"]
|
|
|
|
|
2022-11-21 12:46:17 +03:00
|
|
|
open Catala_utils
|
2021-05-03 19:03:17 +03:00
|
|
|
(** {1 Visitor classes for programs} *)
|
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
(** To allow for quick traversal and/or modification of this AST structure, we
|
|
|
|
provide a {{:https://en.wikipedia.org/wiki/Visitor_pattern} visitor design
|
|
|
|
pattern}. This feature is implemented via
|
|
|
|
{{:https://gitlab.inria.fr/fpottier/visitors} François Pottier's OCaml
|
|
|
|
visitors library}. *)
|
2021-05-03 19:03:17 +03:00
|
|
|
|
|
|
|
(** {1 Type definitions} *)
|
2020-11-23 11:22:47 +03:00
|
|
|
|
2021-01-20 18:06:04 +03:00
|
|
|
type constructor = (string[@opaque])
|
2021-01-21 02:14:23 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors { variety = "map"; name = "constructor_map"; nude = true },
|
|
|
|
visitors { variety = "iter"; name = "constructor_iter"; nude = true }]
|
2021-05-03 19:03:17 +03:00
|
|
|
(** Constructors are CamelCase *)
|
2020-04-14 12:01:31 +03:00
|
|
|
|
2021-01-20 18:06:04 +03:00
|
|
|
type ident = (string[@opaque])
|
2021-01-21 02:14:23 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors { variety = "map"; name = "ident_map"; nude = true },
|
|
|
|
visitors { variety = "iter"; name = "ident_iter"; nude = true }]
|
2021-05-03 19:03:17 +03:00
|
|
|
(** Idents are snake_case *)
|
2020-04-14 12:46:48 +03:00
|
|
|
|
2022-05-30 12:20:48 +03:00
|
|
|
type qident = ident Marked.pos list
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_map"; "ident_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "qident_map";
|
|
|
|
},
|
2021-01-21 02:14:23 +03:00
|
|
|
visitors
|
2022-03-08 17:03:14 +03:00
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_iter"; "ident_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "qident_iter";
|
|
|
|
}]
|
2020-04-14 18:58:36 +03:00
|
|
|
|
2020-12-10 13:35:56 +03:00
|
|
|
type primitive_typ =
|
|
|
|
| Integer
|
|
|
|
| Decimal
|
|
|
|
| Boolean
|
|
|
|
| Money
|
|
|
|
| Duration
|
|
|
|
| Text
|
|
|
|
| Date
|
|
|
|
| Named of constructor
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["constructor_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "primitive_typ_map";
|
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["constructor_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "primitive_typ_iter";
|
|
|
|
}]
|
2020-04-14 12:46:48 +03:00
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
type base_typ_data =
|
|
|
|
| Primitive of primitive_typ
|
2022-05-30 12:20:48 +03:00
|
|
|
| Collection of base_typ_data Marked.pos
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_map"; "primitive_typ_map"];
|
2021-01-20 18:06:04 +03:00
|
|
|
name = "base_typ_data_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_iter"; "primitive_typ_iter"];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "base_typ_data_iter";
|
|
|
|
}]
|
2020-04-14 12:46:48 +03:00
|
|
|
|
2020-04-14 13:34:09 +03:00
|
|
|
type base_typ = Condition | Data of base_typ_data
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
2022-03-08 17:03:14 +03:00
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["base_typ_data_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "base_typ_map";
|
|
|
|
nude = true;
|
|
|
|
},
|
2021-01-21 02:14:23 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["base_typ_data_iter"];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "base_typ_iter";
|
|
|
|
nude = true;
|
|
|
|
}]
|
2020-04-14 13:34:09 +03:00
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
type func_typ = {
|
2022-05-30 12:20:48 +03:00
|
|
|
arg_typ : base_typ Marked.pos;
|
|
|
|
return_typ : base_typ Marked.pos;
|
2022-03-08 17:03:14 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["base_typ_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "func_typ_map";
|
|
|
|
nude = true;
|
|
|
|
},
|
2021-01-21 02:14:23 +03:00
|
|
|
visitors
|
2022-03-08 17:03:14 +03:00
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["base_typ_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "func_typ_iter";
|
|
|
|
nude = true;
|
|
|
|
}]
|
2020-04-14 13:34:09 +03:00
|
|
|
|
2022-08-25 18:29:00 +03:00
|
|
|
type typ = naked_typ Marked.pos
|
2022-08-25 20:46:13 +03:00
|
|
|
|
2022-08-25 18:29:00 +03:00
|
|
|
and naked_typ = Base of base_typ | Func of func_typ
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["func_typ_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "typ_map";
|
|
|
|
nude = true;
|
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["func_typ_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "typ_iter";
|
|
|
|
nude = true;
|
|
|
|
}]
|
2020-04-14 12:46:48 +03:00
|
|
|
|
|
|
|
type struct_decl_field = {
|
2022-05-30 12:20:48 +03:00
|
|
|
struct_decl_field_name : ident Marked.pos;
|
2022-08-25 18:29:00 +03:00
|
|
|
struct_decl_field_typ : typ;
|
2020-04-14 12:46:48 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
2022-03-08 17:03:14 +03:00
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["typ_map"; "ident_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "struct_decl_field_map";
|
|
|
|
},
|
2021-01-21 02:14:23 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["typ_iter"; "ident_iter"];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "struct_decl_field_iter";
|
|
|
|
}]
|
2020-04-14 12:46:48 +03:00
|
|
|
|
|
|
|
type struct_decl = {
|
2022-05-30 12:20:48 +03:00
|
|
|
struct_decl_name : constructor Marked.pos;
|
|
|
|
struct_decl_fields : struct_decl_field Marked.pos list;
|
2020-04-14 12:46:48 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["struct_decl_field_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "struct_decl_map";
|
|
|
|
},
|
2021-01-21 02:14:23 +03:00
|
|
|
visitors
|
2022-03-08 17:03:14 +03:00
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["struct_decl_field_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "struct_decl_iter";
|
|
|
|
}]
|
2020-04-14 12:46:48 +03:00
|
|
|
|
2020-04-14 13:34:09 +03:00
|
|
|
type enum_decl_case = {
|
2022-05-30 12:20:48 +03:00
|
|
|
enum_decl_case_name : constructor Marked.pos;
|
2022-08-25 18:29:00 +03:00
|
|
|
enum_decl_case_typ : typ option;
|
2020-04-14 13:34:09 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["typ_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "enum_decl_case_map";
|
|
|
|
nude = true;
|
|
|
|
},
|
2021-01-21 02:14:23 +03:00
|
|
|
visitors
|
2022-03-08 17:03:14 +03:00
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["typ_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "enum_decl_case_iter";
|
|
|
|
nude = true;
|
|
|
|
}]
|
2020-04-14 13:34:09 +03:00
|
|
|
|
|
|
|
type enum_decl = {
|
2022-05-30 12:20:48 +03:00
|
|
|
enum_decl_name : constructor Marked.pos;
|
|
|
|
enum_decl_cases : enum_decl_case Marked.pos list;
|
2020-04-14 13:34:09 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
2022-03-08 17:03:14 +03:00
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["enum_decl_case_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "enum_decl_map";
|
|
|
|
nude = true;
|
|
|
|
},
|
2021-01-21 02:14:23 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["enum_decl_case_iter"];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "enum_decl_iter";
|
|
|
|
nude = true;
|
|
|
|
}]
|
2020-04-14 13:34:09 +03:00
|
|
|
|
2021-01-26 19:41:20 +03:00
|
|
|
type match_case_pattern =
|
2022-05-30 12:20:48 +03:00
|
|
|
(constructor Marked.pos option * constructor Marked.pos) list
|
|
|
|
* ident Marked.pos option
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["ident_map"; "constructor_map"; "Marked.pos_map"];
|
2021-01-20 18:06:04 +03:00
|
|
|
name = "match_case_pattern_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["ident_iter"; "constructor_iter"; "Marked.pos_iter"];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "match_case_pattern_iter";
|
|
|
|
}]
|
2020-04-14 18:58:36 +03:00
|
|
|
|
Add overloaded operators for the common operations
This uses the same disambiguation mechanism put in place for
structures, calling the typer on individual rules on the desugared AST
to propagate types, in order to resolve ambiguous operators like `+`
to their strongly typed counterparts (`+!`, `+.`, `+$`, `+@`, `+$`) in
the translation to scopelang.
The patch includes some normalisation of the definition of all the
operators, and classifies them based on their typing policy instead of
their arity. It also adds a little more flexibility:
- a couple new operators, like `-` on date and duration
- optional type annotation on some aggregation constructions
The `Shared_ast` lib is also lightly restructured, with the `Expr`
module split into `Type`, `Operator` and `Expr`.
2022-11-29 11:47:53 +03:00
|
|
|
type op_kind = KPoly | KInt | KDec | KMoney | KDate | KDuration
|
2021-01-21 02:14:23 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors { variety = "map"; name = "op_kind_map"; nude = true },
|
|
|
|
visitors { variety = "iter"; name = "op_kind_iter"; nude = true }]
|
2020-12-09 16:51:22 +03:00
|
|
|
|
|
|
|
type binop =
|
|
|
|
| And
|
|
|
|
| Or
|
2021-03-16 22:34:03 +03:00
|
|
|
| Xor
|
2020-12-09 16:51:22 +03:00
|
|
|
| Add of op_kind
|
|
|
|
| Sub of op_kind
|
|
|
|
| Mult of op_kind
|
|
|
|
| Div of op_kind
|
|
|
|
| Lt of op_kind
|
|
|
|
| Lte of op_kind
|
|
|
|
| Gt of op_kind
|
|
|
|
| Gte of op_kind
|
|
|
|
| Eq
|
|
|
|
| Neq
|
2021-07-08 17:27:46 +03:00
|
|
|
| Concat
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["op_kind_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "binop_map";
|
|
|
|
nude = true;
|
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["op_kind_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "binop_iter";
|
|
|
|
nude = true;
|
|
|
|
}]
|
2020-12-09 16:51:22 +03:00
|
|
|
|
|
|
|
type unop = Not | Minus of op_kind
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["op_kind_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "unop_map";
|
|
|
|
nude = true;
|
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["op_kind_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "unop_iter";
|
|
|
|
nude = true;
|
|
|
|
}]
|
2020-04-14 20:13:20 +03:00
|
|
|
|
2022-03-17 14:30:14 +03:00
|
|
|
type builtin_expression =
|
|
|
|
| Cardinal
|
2022-12-13 15:28:01 +03:00
|
|
|
| ToDecimal
|
|
|
|
| ToMoney
|
2022-03-17 14:30:14 +03:00
|
|
|
| GetDay
|
|
|
|
| GetMonth
|
|
|
|
| GetYear
|
2022-07-21 15:11:56 +03:00
|
|
|
| LastDayOfMonth
|
|
|
|
| FirstDayOfMonth
|
2022-12-13 15:28:01 +03:00
|
|
|
| Round
|
2021-01-21 02:14:23 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors { variety = "map"; name = "builtin_expression_map"; nude = true },
|
|
|
|
visitors { variety = "iter"; name = "builtin_expression_iter"; nude = true }]
|
2020-04-14 20:13:20 +03:00
|
|
|
|
2020-04-15 17:02:40 +03:00
|
|
|
type literal_date = {
|
2022-07-21 15:14:22 +03:00
|
|
|
literal_date_day : (int[@opaque]);
|
|
|
|
literal_date_month : (int[@opaque]);
|
|
|
|
literal_date_year : (int[@opaque]);
|
2020-04-15 17:02:40 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "literal_date_map";
|
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "literal_date_iter";
|
|
|
|
}]
|
2020-04-15 17:02:40 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
type literal_number =
|
2022-04-22 15:26:28 +03:00
|
|
|
| Int of (string[@opaque])
|
|
|
|
| Dec of (string[@opaque]) * (string[@opaque])
|
2021-01-21 02:14:23 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors { variety = "map"; name = "literal_number_map"; nude = true },
|
|
|
|
visitors { variety = "iter"; name = "literal_number_iter"; nude = true }]
|
2020-04-14 20:13:20 +03:00
|
|
|
|
2020-04-25 16:17:44 +03:00
|
|
|
type literal_unit = Percent | Year | Month | Day
|
2021-01-21 02:14:23 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors { variety = "map"; name = "literal_unit_map"; nude = true },
|
|
|
|
visitors { variety = "iter"; name = "literal_unit_iter"; nude = true }]
|
2020-04-14 20:13:20 +03:00
|
|
|
|
2021-03-05 21:16:56 +03:00
|
|
|
type money_amount = {
|
2022-04-22 15:26:28 +03:00
|
|
|
money_amount_units : (string[@opaque]);
|
|
|
|
money_amount_cents : (string[@opaque]);
|
2021-03-05 21:16:56 +03:00
|
|
|
}
|
2021-01-21 02:14:23 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors { variety = "map"; name = "money_amount_map"; nude = true },
|
|
|
|
visitors { variety = "iter"; name = "money_amount_iter"; nude = true }]
|
2020-04-25 16:17:44 +03:00
|
|
|
|
2020-04-15 17:02:40 +03:00
|
|
|
type literal =
|
2022-05-30 12:20:48 +03:00
|
|
|
| LNumber of literal_number Marked.pos * literal_unit Marked.pos option
|
2021-01-20 18:06:04 +03:00
|
|
|
| LBool of bool
|
|
|
|
| LMoneyAmount of money_amount
|
|
|
|
| LDate of literal_date
|
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
|
|
|
ancestors =
|
2022-03-08 17:03:14 +03:00
|
|
|
[
|
|
|
|
"literal_number_map";
|
|
|
|
"money_amount_map";
|
|
|
|
"literal_date_map";
|
|
|
|
"literal_unit_map";
|
|
|
|
];
|
2021-01-20 18:06:04 +03:00
|
|
|
name = "literal_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
|
|
|
ancestors =
|
2022-03-08 17:03:14 +03:00
|
|
|
[
|
|
|
|
"literal_number_iter";
|
|
|
|
"money_amount_iter";
|
|
|
|
"literal_date_iter";
|
|
|
|
"literal_unit_iter";
|
|
|
|
];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "literal_iter";
|
|
|
|
}]
|
2020-04-14 20:13:20 +03:00
|
|
|
|
2022-12-12 18:02:07 +03:00
|
|
|
type collection_op =
|
|
|
|
| Exists of { predicate : ident Marked.pos * expression }
|
|
|
|
| Forall of { predicate : ident Marked.pos * expression }
|
|
|
|
| Map of { f : ident Marked.pos * expression }
|
|
|
|
| Filter of { f : ident Marked.pos * expression }
|
|
|
|
| AggregateSum of { typ : primitive_typ }
|
Add overloaded operators for the common operations
This uses the same disambiguation mechanism put in place for
structures, calling the typer on individual rules on the desugared AST
to propagate types, in order to resolve ambiguous operators like `+`
to their strongly typed counterparts (`+!`, `+.`, `+$`, `+@`, `+$`) in
the translation to scopelang.
The patch includes some normalisation of the definition of all the
operators, and classifies them based on their typing policy instead of
their arity. It also adds a little more flexibility:
- a couple new operators, like `-` on date and duration
- optional type annotation on some aggregation constructions
The `Shared_ast` lib is also lightly restructured, with the `Expr`
module split into `Type`, `Operator` and `Expr`.
2022-11-29 11:47:53 +03:00
|
|
|
(* it would be nice to remove the need for specifying the type here like for
|
|
|
|
extremums, but we need an additionl overload for "neutral element for
|
|
|
|
addition across types" *)
|
2022-12-12 18:02:07 +03:00
|
|
|
| AggregateExtremum of { max : bool; default : expression }
|
|
|
|
| AggregateArgExtremum of {
|
|
|
|
max : bool;
|
|
|
|
default : expression;
|
|
|
|
f : ident Marked.pos * expression;
|
|
|
|
}
|
2021-01-06 14:41:24 +03:00
|
|
|
|
2021-06-01 19:56:03 +03:00
|
|
|
and explicit_match_case = {
|
2022-05-30 12:20:48 +03:00
|
|
|
match_case_pattern : match_case_pattern Marked.pos;
|
2022-12-12 18:02:07 +03:00
|
|
|
match_case_expr : expression;
|
2020-04-14 20:13:20 +03:00
|
|
|
}
|
|
|
|
|
2022-12-12 18:02:07 +03:00
|
|
|
and match_case = WildCard of expression | MatchCase of explicit_match_case
|
2022-05-30 12:20:48 +03:00
|
|
|
and match_cases = match_case Marked.pos list
|
2022-12-12 18:02:07 +03:00
|
|
|
and expression = naked_expression Marked.pos
|
|
|
|
|
|
|
|
and naked_expression =
|
|
|
|
| MatchWith of expression * match_cases Marked.pos
|
|
|
|
| IfThenElse of expression * expression * expression
|
|
|
|
| Binop of binop Marked.pos * expression * expression
|
|
|
|
| Unop of unop Marked.pos * expression
|
|
|
|
| CollectionOp of collection_op * expression
|
|
|
|
| MemCollection of expression * expression
|
|
|
|
| TestMatchCase of expression * match_case_pattern Marked.pos
|
|
|
|
| FunCall of expression * expression
|
|
|
|
| ScopeCall of constructor Marked.pos * (ident Marked.pos * expression) list
|
|
|
|
| LetIn of ident Marked.pos * expression * expression
|
2020-04-14 20:13:20 +03:00
|
|
|
| Builtin of builtin_expression
|
|
|
|
| Literal of literal
|
2021-01-26 18:38:10 +03:00
|
|
|
| EnumInject of
|
2022-12-12 18:02:07 +03:00
|
|
|
constructor Marked.pos option * constructor Marked.pos * expression option
|
|
|
|
| StructLit of constructor Marked.pos * (ident Marked.pos * expression) list
|
|
|
|
| ArrayLit of expression list
|
2020-07-01 00:15:14 +03:00
|
|
|
| Ident of ident
|
2022-12-12 18:02:07 +03:00
|
|
|
| Dotted of expression * constructor Marked.pos option * ident Marked.pos
|
2021-05-03 19:03:17 +03:00
|
|
|
(** Dotted is for both struct field projection and sub-scope variables *)
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
|
|
|
ancestors =
|
|
|
|
[
|
|
|
|
"primitive_typ_map";
|
|
|
|
"match_case_pattern_map";
|
|
|
|
"literal_map";
|
|
|
|
"binop_map";
|
|
|
|
"unop_map";
|
|
|
|
"builtin_expression_map";
|
|
|
|
];
|
|
|
|
name = "expression_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
|
|
|
ancestors =
|
|
|
|
[
|
|
|
|
"primitive_typ_iter";
|
|
|
|
"match_case_pattern_iter";
|
|
|
|
"literal_iter";
|
|
|
|
"binop_iter";
|
|
|
|
"unop_iter";
|
|
|
|
"builtin_expression_iter";
|
|
|
|
];
|
|
|
|
name = "expression_iter";
|
|
|
|
}]
|
2020-04-14 20:13:20 +03:00
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
type exception_to =
|
|
|
|
| NotAnException
|
|
|
|
| UnlabeledException
|
2022-05-30 12:20:48 +03:00
|
|
|
| ExceptionToLabel of ident Marked.pos
|
2021-01-21 21:53:25 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
2022-03-08 17:03:14 +03:00
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["ident_map"; "Marked.pos_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "exception_to_map";
|
|
|
|
},
|
2021-01-21 23:10:22 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["ident_iter"; "Marked.pos_iter"];
|
2021-01-21 23:10:22 +03:00
|
|
|
name = "exception_to_iter";
|
|
|
|
}]
|
2021-01-21 21:53:25 +03:00
|
|
|
|
2020-04-14 20:13:20 +03:00
|
|
|
type rule = {
|
2022-05-30 12:20:48 +03:00
|
|
|
rule_label : ident Marked.pos option;
|
2021-01-21 21:53:25 +03:00
|
|
|
rule_exception_to : exception_to;
|
2022-05-30 12:20:48 +03:00
|
|
|
rule_parameter : ident Marked.pos option;
|
2022-12-12 18:02:07 +03:00
|
|
|
rule_condition : expression option;
|
2022-05-30 12:20:48 +03:00
|
|
|
rule_name : qident Marked.pos;
|
2022-11-07 15:50:28 +03:00
|
|
|
rule_id : Shared_ast.RuleName.t; [@opaque]
|
2022-05-30 12:20:48 +03:00
|
|
|
rule_consequence : (bool[@opaque]) Marked.pos;
|
|
|
|
rule_state : ident Marked.pos option;
|
2020-04-14 20:13:20 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2021-01-21 21:53:25 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["expression_map"; "qident_map"; "exception_to_map"];
|
2021-01-21 21:53:25 +03:00
|
|
|
name = "rule_map";
|
2021-01-21 23:10:22 +03:00
|
|
|
},
|
2021-01-21 02:14:23 +03:00
|
|
|
visitors
|
2021-01-21 23:10:22 +03:00
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["expression_iter"; "qident_iter"; "exception_to_iter"];
|
2021-01-21 23:10:22 +03:00
|
|
|
name = "rule_iter";
|
|
|
|
}]
|
2020-04-14 20:13:20 +03:00
|
|
|
|
|
|
|
type definition = {
|
2022-05-30 12:20:48 +03:00
|
|
|
definition_label : ident Marked.pos option;
|
2021-01-21 21:53:25 +03:00
|
|
|
definition_exception_to : exception_to;
|
2022-05-30 12:20:48 +03:00
|
|
|
definition_name : qident Marked.pos;
|
|
|
|
definition_parameter : ident Marked.pos option;
|
2022-12-12 18:02:07 +03:00
|
|
|
definition_condition : expression option;
|
2022-11-07 15:50:28 +03:00
|
|
|
definition_id : Shared_ast.RuleName.t; [@opaque]
|
2022-12-12 18:02:07 +03:00
|
|
|
definition_expr : expression;
|
2022-05-30 12:20:48 +03:00
|
|
|
definition_state : ident Marked.pos option;
|
2020-04-14 20:13:20 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
2021-01-21 21:53:25 +03:00
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["expression_map"; "qident_map"; "exception_to_map"];
|
2021-01-21 21:53:25 +03:00
|
|
|
name = "definition_map";
|
2021-01-21 23:10:22 +03:00
|
|
|
},
|
2021-01-21 02:14:23 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["expression_iter"; "qident_iter"; "exception_to_iter"];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "definition_iter";
|
|
|
|
}]
|
2020-04-14 18:58:36 +03:00
|
|
|
|
|
|
|
type variation_typ = Increasing | Decreasing
|
2021-01-21 02:14:23 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors { variety = "map"; name = "variation_typ_map" },
|
|
|
|
visitors { variety = "iter"; name = "variation_typ_iter" }]
|
2020-04-14 18:58:36 +03:00
|
|
|
|
2020-04-25 15:21:26 +03:00
|
|
|
type meta_assertion =
|
2022-05-30 12:20:48 +03:00
|
|
|
| FixedBy of qident Marked.pos * ident Marked.pos
|
2022-03-08 17:03:14 +03:00
|
|
|
| VariesWith of
|
2022-12-12 18:02:07 +03:00
|
|
|
qident Marked.pos * expression * variation_typ Marked.pos option
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["variation_typ_map"; "qident_map"; "expression_map"];
|
2021-01-20 18:06:04 +03:00
|
|
|
name = "meta_assertion_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["variation_typ_iter"; "qident_iter"; "expression_iter"];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "meta_assertion_iter";
|
|
|
|
}]
|
2020-04-14 18:58:36 +03:00
|
|
|
|
|
|
|
type assertion = {
|
2022-12-12 18:02:07 +03:00
|
|
|
assertion_condition : expression option;
|
|
|
|
assertion_content : expression;
|
2020-04-14 18:58:36 +03:00
|
|
|
}
|
2021-01-21 02:14:23 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
2022-05-04 16:48:03 +03:00
|
|
|
{ variety = "map"; ancestors = ["expression_map"]; name = "assertion_map" },
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["expression_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "assertion_iter";
|
|
|
|
}]
|
2020-04-14 18:58:36 +03:00
|
|
|
|
2020-05-14 22:19:46 +03:00
|
|
|
type scope_use_item =
|
2020-04-25 15:21:26 +03:00
|
|
|
| Rule of rule
|
|
|
|
| Definition of definition
|
|
|
|
| Assertion of assertion
|
|
|
|
| MetaAssertion of meta_assertion
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-03-08 17:03:14 +03:00
|
|
|
ancestors =
|
2022-05-04 16:48:03 +03:00
|
|
|
["meta_assertion_map"; "definition_map"; "assertion_map"; "rule_map"];
|
2021-01-20 18:06:04 +03:00
|
|
|
name = "scope_use_item_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-03-08 17:03:14 +03:00
|
|
|
ancestors =
|
|
|
|
[
|
|
|
|
"meta_assertion_iter";
|
|
|
|
"definition_iter";
|
|
|
|
"assertion_iter";
|
|
|
|
"rule_iter";
|
|
|
|
];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "scope_use_item_iter";
|
|
|
|
}]
|
2020-04-14 18:58:36 +03:00
|
|
|
|
2020-05-14 22:19:46 +03:00
|
|
|
type scope_use = {
|
2022-12-12 18:02:07 +03:00
|
|
|
scope_use_condition : expression option;
|
2022-05-30 12:20:48 +03:00
|
|
|
scope_use_name : constructor Marked.pos;
|
|
|
|
scope_use_items : scope_use_item Marked.pos list;
|
2020-04-14 18:58:36 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["expression_map"; "scope_use_item_map"];
|
2021-01-20 18:06:04 +03:00
|
|
|
name = "scope_use_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["expression_iter"; "scope_use_item_iter"];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "scope_use_iter";
|
|
|
|
}]
|
2020-04-14 18:58:36 +03:00
|
|
|
|
2022-02-07 12:30:36 +03:00
|
|
|
type io_input = Input | Context | Internal
|
|
|
|
[@@deriving
|
|
|
|
visitors { variety = "map"; name = "io_input_map" },
|
|
|
|
visitors { variety = "iter"; name = "io_input_iter" }]
|
|
|
|
|
|
|
|
type scope_decl_context_io = {
|
2022-05-30 12:20:48 +03:00
|
|
|
scope_decl_context_io_input : io_input Marked.pos;
|
|
|
|
scope_decl_context_io_output : bool Marked.pos;
|
2022-02-07 12:30:36 +03:00
|
|
|
}
|
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["io_input_map"; "Marked.pos_map"];
|
2022-02-07 12:30:36 +03:00
|
|
|
name = "scope_decl_context_io_map";
|
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["io_input_iter"; "Marked.pos_iter"];
|
2022-02-07 12:30:36 +03:00
|
|
|
name = "scope_decl_context_io_iter";
|
|
|
|
}]
|
2022-01-27 20:03:47 +03:00
|
|
|
|
2020-05-19 15:30:52 +03:00
|
|
|
type scope_decl_context_scope = {
|
2022-05-30 12:20:48 +03:00
|
|
|
scope_decl_context_scope_name : ident Marked.pos;
|
|
|
|
scope_decl_context_scope_sub_scope : constructor Marked.pos;
|
2022-02-07 12:30:36 +03:00
|
|
|
scope_decl_context_scope_attribute : scope_decl_context_io;
|
2020-05-19 15:30:52 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-03-08 17:03:14 +03:00
|
|
|
ancestors =
|
|
|
|
[
|
|
|
|
"ident_map";
|
|
|
|
"constructor_map";
|
|
|
|
"scope_decl_context_io_map";
|
2022-05-30 12:20:48 +03:00
|
|
|
"Marked.pos_map";
|
2022-03-08 17:03:14 +03:00
|
|
|
];
|
2021-01-20 18:06:04 +03:00
|
|
|
name = "scope_decl_context_scope_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-02-07 12:30:36 +03:00
|
|
|
ancestors =
|
2022-03-08 17:03:14 +03:00
|
|
|
[
|
|
|
|
"ident_iter";
|
|
|
|
"constructor_iter";
|
|
|
|
"scope_decl_context_io_iter";
|
2022-05-30 12:20:48 +03:00
|
|
|
"Marked.pos_iter";
|
2022-03-08 17:03:14 +03:00
|
|
|
];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "scope_decl_context_scope_iter";
|
|
|
|
}]
|
2020-05-19 15:30:52 +03:00
|
|
|
|
|
|
|
type scope_decl_context_data = {
|
2022-05-30 12:20:48 +03:00
|
|
|
scope_decl_context_item_name : ident Marked.pos;
|
2022-08-25 18:29:00 +03:00
|
|
|
scope_decl_context_item_typ : typ;
|
2022-02-07 12:30:36 +03:00
|
|
|
scope_decl_context_item_attribute : scope_decl_context_io;
|
2022-05-30 12:20:48 +03:00
|
|
|
scope_decl_context_item_states : ident Marked.pos list;
|
2020-05-19 15:30:52 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["typ_map"; "scope_decl_context_io_map"; "ident_map"];
|
2021-01-20 18:06:04 +03:00
|
|
|
name = "scope_decl_context_data_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["typ_iter"; "scope_decl_context_io_iter"; "ident_iter"];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "scope_decl_context_data_iter";
|
|
|
|
}]
|
2020-05-19 15:30:52 +03:00
|
|
|
|
|
|
|
type scope_decl_context_item =
|
|
|
|
| ContextData of scope_decl_context_data
|
|
|
|
| ContextScope of scope_decl_context_scope
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-03-08 17:03:14 +03:00
|
|
|
ancestors =
|
2022-05-04 16:48:03 +03:00
|
|
|
["scope_decl_context_data_map"; "scope_decl_context_scope_map"];
|
2021-01-20 18:06:04 +03:00
|
|
|
name = "scope_decl_context_item_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-03-08 17:03:14 +03:00
|
|
|
ancestors =
|
2022-05-04 16:48:03 +03:00
|
|
|
["scope_decl_context_data_iter"; "scope_decl_context_scope_iter"];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "scope_decl_context_item_iter";
|
|
|
|
}]
|
2020-05-19 15:30:52 +03:00
|
|
|
|
|
|
|
type scope_decl = {
|
2022-05-30 12:20:48 +03:00
|
|
|
scope_decl_name : constructor Marked.pos;
|
|
|
|
scope_decl_context : scope_decl_context_item Marked.pos list;
|
2020-05-19 15:30:52 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
2022-03-08 17:03:14 +03:00
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["scope_decl_context_item_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "scope_decl_map";
|
|
|
|
},
|
2021-01-21 02:14:23 +03:00
|
|
|
visitors
|
2022-03-08 17:03:14 +03:00
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["scope_decl_context_item_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "scope_decl_iter";
|
|
|
|
}]
|
2020-05-19 15:30:52 +03:00
|
|
|
|
2020-04-14 12:46:48 +03:00
|
|
|
type code_item =
|
2020-05-14 22:19:46 +03:00
|
|
|
| ScopeUse of scope_use
|
|
|
|
| ScopeDecl of scope_decl
|
2020-04-14 12:46:48 +03:00
|
|
|
| StructDecl of struct_decl
|
2020-04-14 13:34:09 +03:00
|
|
|
| EnumDecl of enum_decl
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-03-08 17:03:14 +03:00
|
|
|
ancestors =
|
2022-05-04 16:48:03 +03:00
|
|
|
["scope_decl_map"; "enum_decl_map"; "struct_decl_map"; "scope_use_map"];
|
2021-01-20 18:06:04 +03:00
|
|
|
name = "code_item_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-03-08 17:03:14 +03:00
|
|
|
ancestors =
|
|
|
|
[
|
|
|
|
"scope_decl_iter";
|
|
|
|
"enum_decl_iter";
|
|
|
|
"struct_decl_iter";
|
|
|
|
"scope_use_iter";
|
|
|
|
];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "code_item_iter";
|
|
|
|
}]
|
2020-04-14 12:46:48 +03:00
|
|
|
|
2022-05-30 12:20:48 +03:00
|
|
|
type code_block = code_item Marked.pos list
|
2021-01-21 02:14:23 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
2022-05-04 16:48:03 +03:00
|
|
|
{ variety = "map"; ancestors = ["code_item_map"]; name = "code_block_map" },
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["code_item_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "code_block_iter";
|
|
|
|
}]
|
2020-04-14 12:01:31 +03:00
|
|
|
|
2022-05-30 12:20:48 +03:00
|
|
|
type source_repr = (string[@opaque]) Marked.pos
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "source_repr_map";
|
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "source_repr_iter";
|
|
|
|
}]
|
2020-04-14 12:01:31 +03:00
|
|
|
|
2021-05-15 02:16:08 +03:00
|
|
|
type law_heading = {
|
2022-05-30 12:20:48 +03:00
|
|
|
law_heading_name : (string[@opaque]) Marked.pos;
|
2021-05-15 02:16:08 +03:00
|
|
|
law_heading_id : (string[@opaque]) option;
|
2022-09-07 18:14:22 +03:00
|
|
|
law_heading_is_archive : bool; [@opaque]
|
2021-05-15 02:16:08 +03:00
|
|
|
law_heading_precedence : (int[@opaque]);
|
2020-04-22 13:36:33 +03:00
|
|
|
}
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "law_heading_map";
|
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "law_heading_iter";
|
|
|
|
}]
|
2020-04-22 12:51:17 +03:00
|
|
|
|
2020-04-30 11:19:45 +03:00
|
|
|
type law_include =
|
2022-05-30 12:20:48 +03:00
|
|
|
| PdfFile of (string[@opaque]) Marked.pos * (int[@opaque]) option
|
|
|
|
| CatalaFile of (string[@opaque]) Marked.pos
|
|
|
|
| LegislativeText of (string[@opaque]) Marked.pos
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_map"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "law_include_map";
|
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-30 12:20:48 +03:00
|
|
|
ancestors = ["Marked.pos_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "law_include_iter";
|
|
|
|
}]
|
2021-01-20 18:06:04 +03:00
|
|
|
|
2020-10-04 02:25:37 +03:00
|
|
|
type law_structure =
|
2020-12-11 23:17:01 +03:00
|
|
|
| LawInclude of law_include
|
2020-10-04 02:25:37 +03:00
|
|
|
| LawHeading of law_heading * law_structure list
|
2021-05-15 02:16:08 +03:00
|
|
|
| LawText of (string[@opaque])
|
|
|
|
| CodeBlock of code_block * source_repr * bool (* Metadata if true *)
|
2021-01-20 18:06:04 +03:00
|
|
|
[@@deriving
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "map";
|
2022-03-08 17:03:14 +03:00
|
|
|
ancestors =
|
|
|
|
[
|
|
|
|
"law_include_map";
|
|
|
|
"code_block_map";
|
|
|
|
"source_repr_map";
|
|
|
|
"law_heading_map";
|
|
|
|
];
|
2021-01-20 18:06:04 +03:00
|
|
|
name = "law_structure_map";
|
2021-01-21 02:14:23 +03:00
|
|
|
},
|
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
|
|
|
ancestors =
|
2022-03-08 17:03:14 +03:00
|
|
|
[
|
|
|
|
"law_include_iter";
|
|
|
|
"code_block_iter";
|
|
|
|
"source_repr_iter";
|
|
|
|
"law_heading_iter";
|
|
|
|
];
|
2021-01-21 02:14:23 +03:00
|
|
|
name = "law_structure_iter";
|
|
|
|
}]
|
2020-10-04 02:25:37 +03:00
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
type program = {
|
|
|
|
program_items : law_structure list;
|
|
|
|
program_source_files : (string[@opaque]) list;
|
|
|
|
}
|
2021-01-21 02:14:23 +03:00
|
|
|
[@@deriving
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
2022-05-04 16:48:03 +03:00
|
|
|
{ variety = "map"; ancestors = ["law_structure_map"]; name = "program_map" },
|
2022-03-08 17:03:14 +03:00
|
|
|
visitors
|
|
|
|
{
|
|
|
|
variety = "iter";
|
2022-05-04 16:48:03 +03:00
|
|
|
ancestors = ["law_structure_iter"];
|
2022-03-08 17:03:14 +03:00
|
|
|
name = "program_iter";
|
|
|
|
}]
|
2020-04-19 16:53:35 +03:00
|
|
|
|
2021-05-15 02:16:08 +03:00
|
|
|
type source_file = law_structure list
|
2021-11-28 15:09:44 +03:00
|
|
|
|
|
|
|
(** {1 Helpers}*)
|
|
|
|
|
|
|
|
(** Translates a {!type: rule} into the corresponding {!type: definition} *)
|
|
|
|
let rule_to_def (rule : rule) : definition =
|
2022-05-30 12:20:48 +03:00
|
|
|
let consequence_expr =
|
|
|
|
Literal (LBool (Marked.unmark rule.rule_consequence))
|
|
|
|
in
|
2021-11-28 15:09:44 +03:00
|
|
|
{
|
|
|
|
definition_label = rule.rule_label;
|
|
|
|
definition_exception_to = rule.rule_exception_to;
|
|
|
|
definition_name = rule.rule_name;
|
|
|
|
definition_parameter = rule.rule_parameter;
|
|
|
|
definition_condition = rule.rule_condition;
|
|
|
|
definition_id = rule.rule_id;
|
2022-05-30 12:20:48 +03:00
|
|
|
definition_expr = consequence_expr, Marked.get_mark rule.rule_consequence;
|
2022-02-28 16:33:07 +03:00
|
|
|
definition_state = rule.rule_state;
|
2021-11-28 15:09:44 +03:00
|
|
|
}
|