2020-03-09 14:01:56 +03:00
|
|
|
(* This file is part of the Lawspec compiler, a specification language for tax and social benefits
|
2020-04-15 16:33:21 +03:00
|
|
|
computation rules. Copyright (C) 2020 Inria, contributor: Denis Merigoux
|
2020-03-09 14:01:56 +03:00
|
|
|
<denis.merigoux@inria.fr>
|
2020-03-08 02:21:55 +03:00
|
|
|
|
2020-03-09 14:01:56 +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
|
|
|
|
2020-03-09 14:01:56 +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
|
|
|
|
the License. *)
|
2020-03-08 02:21:55 +03:00
|
|
|
|
2020-04-14 12:46:48 +03:00
|
|
|
type constructor = string
|
2020-04-14 12:01:31 +03:00
|
|
|
|
2020-04-14 12:46:48 +03:00
|
|
|
type ident = string
|
|
|
|
|
2020-04-14 18:58:36 +03:00
|
|
|
type qident_element = Ident of ident | Constructor of constructor
|
|
|
|
|
|
|
|
type qident = qident_element Pos.marked list
|
|
|
|
|
2020-04-14 13:34:09 +03:00
|
|
|
type primitive_typ = Integer | Decimal | Boolean | Money | Date | Named of constructor
|
2020-04-14 12:46:48 +03:00
|
|
|
|
2020-04-14 13:34:09 +03:00
|
|
|
type base_typ_data = {
|
2020-04-14 12:46:48 +03:00
|
|
|
typ_data_collection : Pos.t option;
|
|
|
|
typ_data_optional : Pos.t option;
|
2020-04-14 13:34:09 +03:00
|
|
|
typ_data_base : primitive_typ Pos.marked;
|
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
|
|
|
|
|
|
|
|
type func_typ = { arg_typ : base_typ Pos.marked; return_typ : base_typ Pos.marked }
|
|
|
|
|
|
|
|
type typ = Base of base_typ | Func of func_typ
|
2020-04-14 12:46:48 +03:00
|
|
|
|
|
|
|
type struct_decl_field = {
|
|
|
|
struct_decl_field_name : ident Pos.marked;
|
|
|
|
struct_decl_field_typ : typ Pos.marked;
|
|
|
|
}
|
|
|
|
|
|
|
|
type struct_decl = {
|
|
|
|
struct_decl_name : constructor Pos.marked;
|
|
|
|
struct_decl_fields : struct_decl_field Pos.marked list;
|
|
|
|
}
|
|
|
|
|
2020-04-14 13:34:09 +03:00
|
|
|
type enum_decl_case = {
|
|
|
|
enum_decl_case_name : constructor Pos.marked;
|
|
|
|
enum_decl_case_typ : typ Pos.marked option;
|
|
|
|
}
|
|
|
|
|
|
|
|
type enum_decl = {
|
|
|
|
enum_decl_name : constructor Pos.marked;
|
|
|
|
enum_decl_cases : enum_decl_case Pos.marked list;
|
|
|
|
}
|
|
|
|
|
2020-04-14 13:54:40 +03:00
|
|
|
type field_decl_context_item = {
|
|
|
|
field_decl_context_item_name : ident Pos.marked;
|
|
|
|
field_decl_context_item_typ : typ Pos.marked;
|
|
|
|
}
|
|
|
|
|
|
|
|
type field_decl_include_join = {
|
|
|
|
parent_field_name : constructor Pos.marked;
|
|
|
|
parent_field_context_item : ident Pos.marked;
|
|
|
|
sub_field_name : constructor Pos.marked;
|
|
|
|
sub_field_context_item : ident Pos.marked;
|
|
|
|
}
|
|
|
|
|
|
|
|
type field_decl_include = {
|
|
|
|
field_decl_include_sub_field : constructor Pos.marked;
|
|
|
|
field_decl_include_joins : field_decl_include_join Pos.marked list;
|
|
|
|
}
|
|
|
|
|
|
|
|
type field_decl = {
|
|
|
|
field_decl_name : constructor Pos.marked;
|
|
|
|
field_decl_context : field_decl_context_item Pos.marked list;
|
|
|
|
field_decl_includes : field_decl_include Pos.marked list;
|
|
|
|
}
|
|
|
|
|
2020-04-14 20:13:20 +03:00
|
|
|
type match_case_pattern = constructor Pos.marked list * ident Pos.marked option
|
2020-04-14 18:58:36 +03:00
|
|
|
|
2020-04-14 20:13:20 +03:00
|
|
|
type binop = And | Or | Add | Sub | Mult | Div | Lt | Lte | Gt | Gte | Eq | Neq
|
2020-04-14 18:58:36 +03:00
|
|
|
|
2020-04-14 20:13:20 +03:00
|
|
|
type unop = Not | Minus
|
|
|
|
|
|
|
|
type builtin_expression = Cardinal | Now
|
|
|
|
|
|
|
|
type aggregate_func = AggregateSum | AggregateCount
|
|
|
|
|
2020-04-15 17:02:40 +03:00
|
|
|
type literal_date = {
|
|
|
|
literal_date_day : int Pos.marked;
|
|
|
|
literal_date_month : int Pos.marked;
|
|
|
|
literal_date_year : int Pos.marked;
|
|
|
|
}
|
|
|
|
|
2020-04-14 20:13:20 +03:00
|
|
|
type literal_number = Int of int | Dec of int * int
|
|
|
|
|
|
|
|
type literal_unit = Percent | Euro | Year | Month | Day
|
|
|
|
|
2020-04-15 17:26:30 +03:00
|
|
|
type collection_op = Exists | Forall | Aggregate of aggregate_func
|
|
|
|
|
2020-04-15 17:02:40 +03:00
|
|
|
type literal =
|
|
|
|
| Number of literal_number Pos.marked * literal_unit Pos.marked option
|
|
|
|
| Date of literal_date
|
2020-04-14 20:13:20 +03:00
|
|
|
|
|
|
|
type match_case = {
|
|
|
|
match_case_pattern : match_case_pattern Pos.marked;
|
|
|
|
match_case_expr : expression Pos.marked;
|
|
|
|
}
|
|
|
|
|
|
|
|
and match_cases = match_case Pos.marked list
|
|
|
|
|
|
|
|
and expression =
|
|
|
|
| MatchWith of expression Pos.marked * match_cases Pos.marked
|
|
|
|
| IfThenElse of expression Pos.marked * expression Pos.marked * expression Pos.marked
|
|
|
|
| Binop of binop Pos.marked * expression Pos.marked * expression Pos.marked
|
|
|
|
| Unop of unop Pos.marked * expression Pos.marked
|
2020-04-15 17:26:30 +03:00
|
|
|
| CollectionOp of
|
|
|
|
collection_op Pos.marked * ident Pos.marked * expression Pos.marked * expression Pos.marked
|
2020-04-14 20:13:20 +03:00
|
|
|
| MemCollection of expression Pos.marked * expression Pos.marked
|
|
|
|
| TestMatchCase of expression Pos.marked * constructor Pos.marked
|
|
|
|
| FunCall of expression Pos.marked * expression Pos.marked
|
|
|
|
| Builtin of builtin_expression
|
|
|
|
| Literal of literal
|
|
|
|
| Inject of constructor Pos.marked * expression Pos.marked option
|
|
|
|
| Project of expression Pos.marked * constructor Pos.marked
|
|
|
|
| Qident of qident
|
|
|
|
|
|
|
|
type rule = {
|
|
|
|
rule_parameter : ident Pos.marked option;
|
|
|
|
rule_condition : expression Pos.marked option;
|
2020-04-14 20:16:40 +03:00
|
|
|
rule_name : qident Pos.marked;
|
2020-04-16 12:13:53 +03:00
|
|
|
rule_consequence : bool;
|
2020-04-14 20:13:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type definition = {
|
|
|
|
definition_name : qident Pos.marked;
|
|
|
|
definition_parameter : ident Pos.marked option;
|
|
|
|
definition_condition : expression Pos.marked option;
|
|
|
|
definition_expr : expression Pos.marked;
|
|
|
|
}
|
2020-04-14 18:58:36 +03:00
|
|
|
|
|
|
|
type variation_typ = Increasing | Decreasing
|
|
|
|
|
|
|
|
type assertion_content =
|
|
|
|
| Assert of expression
|
|
|
|
| FixedBy of qident Pos.marked * ident Pos.marked
|
|
|
|
| VariesWith of qident Pos.marked * expression Pos.marked * variation_typ Pos.marked option
|
|
|
|
|
|
|
|
type assertion = {
|
|
|
|
assertion_condition : expression Pos.marked option;
|
|
|
|
assertion_content : assertion_content Pos.marked;
|
|
|
|
}
|
|
|
|
|
|
|
|
type field_use_item = Rule of rule | Definition of definition | Assertion of assertion
|
|
|
|
|
|
|
|
type field_use = {
|
|
|
|
field_use_name : constructor Pos.marked;
|
|
|
|
field_use_items : field_use_item Pos.marked list;
|
|
|
|
}
|
|
|
|
|
2020-04-14 12:46:48 +03:00
|
|
|
type code_item =
|
2020-04-14 18:58:36 +03:00
|
|
|
| FieldUse of field_use
|
2020-04-14 13:54:40 +03:00
|
|
|
| FieldDecl of field_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
|
2020-04-14 12:46:48 +03:00
|
|
|
|
|
|
|
type code_block = code_item Pos.marked list
|
2020-04-14 12:01:31 +03:00
|
|
|
|
|
|
|
type source_repr = string Pos.marked
|
|
|
|
|
2020-03-08 03:52:31 +03:00
|
|
|
type source_file_item =
|
2020-04-16 10:07:21 +03:00
|
|
|
| LawHeading of string * int
|
2020-03-08 03:52:31 +03:00
|
|
|
| LawArticle of string
|
|
|
|
| LawText of string
|
2020-04-14 12:01:31 +03:00
|
|
|
| CodeBlock of code_block * source_repr
|
|
|
|
| MetadataBlock of code_block * source_repr
|
2020-04-16 13:38:01 +03:00
|
|
|
| LawInclude of string * int option
|
2020-03-08 03:52:31 +03:00
|
|
|
|
|
|
|
type source_file = source_file_item list
|