2020-03-08 02:21:55 +03:00
|
|
|
(*
|
|
|
|
This file is part of the Lawspec compiler, a specification language for tax and social benefits
|
|
|
|
computation rules.
|
|
|
|
Copyright (C) 2019 Inria, contributor: Denis Merigoux <denis.merigoux@inria.fr>
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
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 03:52:31 +03:00
|
|
|
open Ast
|
2020-04-10 13:14:16 +03:00
|
|
|
open Parse_utils
|
2020-03-08 02:21:55 +03:00
|
|
|
%}
|
|
|
|
|
|
|
|
%token EOF
|
2020-03-08 03:52:31 +03:00
|
|
|
%token<string> LAW_ARTICLE
|
|
|
|
%token<string> LAW_CODE
|
|
|
|
%token<string> LAW_TEXT
|
2020-03-08 06:28:45 +03:00
|
|
|
%token<string> CONSTRUCTOR IDENT
|
|
|
|
%token<string> END_CODE
|
2020-03-08 07:27:46 +03:00
|
|
|
%token<int> INT_LITERAL
|
2020-04-11 19:16:15 +03:00
|
|
|
%token<int * int> DECIMAL_LITERAL
|
2020-04-03 23:58:34 +03:00
|
|
|
%token BEGIN_CODE
|
|
|
|
%token COLON ALT DATA
|
|
|
|
%token OF INTEGER COLLECTION
|
|
|
|
%token RULE CONDITION DEFINED_AS
|
2020-03-08 07:12:12 +03:00
|
|
|
%token EXISTS IN SUCH THAT NOW LESSER GREATER
|
2020-04-03 23:34:11 +03:00
|
|
|
%token DOT AND OR LPAREN RPAREN OPTIONAL EQUAL
|
2020-03-08 07:27:46 +03:00
|
|
|
%token COMMA CARDINAL LESSER_EQUAL GREATER_EQUAL
|
2020-04-03 23:58:34 +03:00
|
|
|
%token ASSERTION FIXED BY YEAR
|
2020-03-08 08:06:32 +03:00
|
|
|
%token PLUS MINUS MULT DIV MATCH WITH VARIES_WITH
|
2020-04-11 19:16:15 +03:00
|
|
|
%token FOR ALL WE_HAVE INCREASING DECREASING
|
2020-04-11 22:23:52 +03:00
|
|
|
%token NOT BOOLEAN PERCENT
|
2020-04-03 23:34:11 +03:00
|
|
|
%token FIELD FILLED IFF EURO NOT_EQUAL DEFINITION
|
2020-04-03 23:58:34 +03:00
|
|
|
%token STRUCT CONTENT IF THEN DEPENDS DECLARATION
|
2020-04-11 19:16:15 +03:00
|
|
|
%token CONTEXT INCLUDES ENUM ELSE DATE SUM
|
|
|
|
%token BEGIN_METADATA END_METADATA MONEY DECIMAL
|
2020-04-03 23:34:11 +03:00
|
|
|
|
2020-03-08 02:21:55 +03:00
|
|
|
%type <Ast.source_file> source_file
|
|
|
|
|
|
|
|
%start source_file
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2020-04-03 23:58:34 +03:00
|
|
|
typ_base:
|
2020-03-08 07:01:26 +03:00
|
|
|
| INTEGER {}
|
2020-03-09 21:14:06 +03:00
|
|
|
| BOOLEAN {}
|
2020-04-11 19:16:15 +03:00
|
|
|
| MONEY {}
|
|
|
|
| DECIMAL {}
|
|
|
|
| DATE {}
|
2020-04-03 23:58:34 +03:00
|
|
|
| CONSTRUCTOR {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
2020-04-03 23:58:34 +03:00
|
|
|
typ:
|
|
|
|
| typ_base option(OPTIONAL) {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
2020-04-10 19:46:06 +03:00
|
|
|
qident_late:
|
|
|
|
| IDENT {}
|
|
|
|
| CONSTRUCTOR {}
|
|
|
|
| IDENT DOT qident_late {}
|
|
|
|
| CONSTRUCTOR DOT qident_late {}
|
|
|
|
|
2020-03-08 07:01:26 +03:00
|
|
|
qident:
|
|
|
|
| IDENT {}
|
2020-04-10 19:46:06 +03:00
|
|
|
| IDENT DOT qident_late {}
|
|
|
|
| CONSTRUCTOR DOT qident_late {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
|
|
|
primitive_expression:
|
|
|
|
| NOW {}
|
2020-04-03 23:34:11 +03:00
|
|
|
| qident {}
|
2020-04-10 19:46:06 +03:00
|
|
|
| LPAREN expression RPAREN {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
2020-03-08 08:06:32 +03:00
|
|
|
date_qualifier:
|
|
|
|
| YEAR {}
|
|
|
|
|
2020-03-08 08:30:05 +03:00
|
|
|
constructor_payload:
|
|
|
|
| OF base_expression {}
|
|
|
|
|
2020-04-11 19:16:15 +03:00
|
|
|
num_literal:
|
2020-03-08 07:27:46 +03:00
|
|
|
| INT_LITERAL {}
|
2020-04-11 19:16:15 +03:00
|
|
|
| DECIMAL_LITERAL {}
|
|
|
|
|
|
|
|
literal:
|
|
|
|
| num_literal {}
|
2020-04-11 22:23:52 +03:00
|
|
|
| num_literal PERCENT {}
|
2020-04-11 19:16:15 +03:00
|
|
|
| num_literal EURO {}
|
2020-03-08 08:06:32 +03:00
|
|
|
| INT_LITERAL date_qualifier {}
|
2020-03-08 08:30:05 +03:00
|
|
|
| CONSTRUCTOR option(constructor_payload) {}
|
2020-03-08 07:27:46 +03:00
|
|
|
|
2020-03-08 07:01:26 +03:00
|
|
|
compare_op:
|
|
|
|
| LESSER {}
|
2020-03-08 07:27:46 +03:00
|
|
|
| LESSER_EQUAL {}
|
2020-03-08 07:12:12 +03:00
|
|
|
| GREATER {}
|
2020-03-08 07:27:46 +03:00
|
|
|
| GREATER_EQUAL {}
|
|
|
|
| EQUAL {}
|
2020-04-03 23:34:11 +03:00
|
|
|
| NOT_EQUAL {}
|
2020-03-08 07:27:46 +03:00
|
|
|
|
|
|
|
func:
|
|
|
|
| CARDINAL {}
|
2020-04-03 23:34:11 +03:00
|
|
|
| qident {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
2020-03-08 07:12:12 +03:00
|
|
|
base_expression:
|
2020-03-08 07:01:26 +03:00
|
|
|
| primitive_expression {}
|
2020-04-10 19:46:06 +03:00
|
|
|
| qident IN qident {}
|
2020-03-08 07:27:46 +03:00
|
|
|
| literal {}
|
2020-04-11 19:16:15 +03:00
|
|
|
| SUM FOR IDENT IN primitive_expression OF base_expression {}
|
2020-04-03 23:34:11 +03:00
|
|
|
| func OF separated_nonempty_list(COMMA, primitive_expression) {}
|
2020-04-10 19:46:06 +03:00
|
|
|
| qident WITH CONSTRUCTOR {}
|
2020-03-08 07:12:12 +03:00
|
|
|
|
2020-03-08 08:06:32 +03:00
|
|
|
mult_op:
|
|
|
|
| MULT {}
|
|
|
|
| DIV {}
|
|
|
|
|
|
|
|
mult_expression:
|
2020-03-08 07:12:12 +03:00
|
|
|
| base_expression {}
|
2020-04-03 23:34:11 +03:00
|
|
|
| base_expression mult_op mult_expression {}
|
2020-03-08 08:06:32 +03:00
|
|
|
|
|
|
|
sum_op:
|
|
|
|
| PLUS {}
|
|
|
|
| MINUS {}
|
|
|
|
|
|
|
|
sum_expression:
|
|
|
|
| mult_expression {}
|
2020-04-03 23:34:11 +03:00
|
|
|
| mult_expression sum_op sum_expression {}
|
2020-03-08 07:12:12 +03:00
|
|
|
|
|
|
|
logical_op:
|
|
|
|
| AND {}
|
|
|
|
| OR {}
|
2020-04-03 23:34:11 +03:00
|
|
|
| IFF {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
2020-03-08 08:49:29 +03:00
|
|
|
logical_unop:
|
|
|
|
| NOT {}
|
|
|
|
|
2020-03-08 07:01:26 +03:00
|
|
|
compare_expression:
|
2020-03-08 07:12:12 +03:00
|
|
|
| sum_expression {}
|
2020-04-03 23:34:11 +03:00
|
|
|
| sum_expression compare_op compare_expression {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
2020-03-08 07:12:12 +03:00
|
|
|
logical_expression:
|
|
|
|
| compare_expression {}
|
2020-03-08 08:49:29 +03:00
|
|
|
| logical_unop compare_expression {}
|
2020-04-03 23:34:11 +03:00
|
|
|
| compare_expression logical_op logical_expression {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
2020-03-08 08:06:32 +03:00
|
|
|
optional_binding:
|
|
|
|
| {}
|
2020-03-08 08:49:29 +03:00
|
|
|
| OF IDENT {}
|
|
|
|
| OF LPAREN constructor_binding RPAREN {}
|
|
|
|
|
|
|
|
constructor_binding:
|
|
|
|
| CONSTRUCTOR optional_binding {}
|
2020-03-08 08:06:32 +03:00
|
|
|
|
|
|
|
match_arm:
|
2020-03-08 08:49:29 +03:00
|
|
|
| constructor_binding COLON logical_expression {}
|
2020-03-08 08:06:32 +03:00
|
|
|
|
|
|
|
match_arms:
|
|
|
|
| ALT match_arm match_arms {}
|
|
|
|
| {}
|
|
|
|
|
2020-03-08 08:30:05 +03:00
|
|
|
forall_prefix:
|
2020-04-11 19:16:15 +03:00
|
|
|
| FOR ALL separated_nonempty_list(COMMA,IDENT) IN separated_nonempty_list(COMMA,qident) WE_HAVE {}
|
2020-03-08 08:30:05 +03:00
|
|
|
|
|
|
|
exists_prefix:
|
|
|
|
| EXISTS IDENT IN qident SUCH THAT {}
|
|
|
|
|
2020-03-08 07:01:26 +03:00
|
|
|
expression:
|
2020-03-08 08:30:05 +03:00
|
|
|
| exists_prefix expression {}
|
|
|
|
| forall_prefix expression {}
|
2020-04-10 19:46:06 +03:00
|
|
|
| MATCH primitive_expression WITH match_arms {}
|
|
|
|
| IF expression THEN expression ELSE base_expression {}
|
2020-03-08 07:12:12 +03:00
|
|
|
| logical_expression {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
|
|
|
condition:
|
2020-04-07 14:59:52 +03:00
|
|
|
| IF expression {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
2020-04-07 14:59:52 +03:00
|
|
|
condition_consequence:
|
|
|
|
| condition THEN {}
|
2020-03-08 08:30:05 +03:00
|
|
|
|
2020-04-10 13:55:18 +03:00
|
|
|
rule_parameters:
|
|
|
|
| DEPENDS definition_parameters {}
|
|
|
|
|
2020-04-03 23:34:11 +03:00
|
|
|
rule:
|
2020-04-10 19:46:06 +03:00
|
|
|
| option(rule_parameters) option(condition_consequence) option(forall_prefix) base_expression FILLED {}
|
2020-03-08 08:49:29 +03:00
|
|
|
|
2020-04-03 23:34:11 +03:00
|
|
|
definition_parameters:
|
|
|
|
| OF separated_nonempty_list(COMMA, IDENT) {}
|
2020-03-08 08:30:05 +03:00
|
|
|
|
2020-04-03 23:34:11 +03:00
|
|
|
definition:
|
2020-04-07 14:59:52 +03:00
|
|
|
| option(forall_prefix) qident option(definition_parameters) option(condition_consequence) DEFINED_AS expression {}
|
2020-03-08 06:28:45 +03:00
|
|
|
|
2020-03-08 08:06:32 +03:00
|
|
|
variation_type:
|
|
|
|
| INCREASING {}
|
|
|
|
| DECREASING {}
|
|
|
|
|
2020-04-10 19:46:06 +03:00
|
|
|
assertion_base:
|
2020-03-08 08:06:32 +03:00
|
|
|
| logical_expression {}
|
|
|
|
| qident FIXED BY IDENT {}
|
2020-04-03 23:34:11 +03:00
|
|
|
| qident VARIES_WITH base_expression option(variation_type) {}
|
2020-04-10 19:46:06 +03:00
|
|
|
|
|
|
|
assertion:
|
|
|
|
| option(condition_consequence) assertion_base {}
|
2020-03-08 08:30:05 +03:00
|
|
|
| exists_prefix assertion {}
|
|
|
|
| forall_prefix assertion {}
|
2020-03-08 08:06:32 +03:00
|
|
|
|
2020-04-03 23:34:11 +03:00
|
|
|
application_field_item:
|
2020-03-08 07:27:46 +03:00
|
|
|
| RULE option(OPTIONAL) rule {}
|
2020-04-03 23:34:11 +03:00
|
|
|
| DEFINITION option(OPTIONAL) definition {}
|
2020-04-10 19:46:06 +03:00
|
|
|
| ASSERTION assertion {}
|
2020-04-07 14:59:52 +03:00
|
|
|
| field_decl_includes {}
|
2020-03-08 06:28:45 +03:00
|
|
|
|
2020-04-03 23:58:34 +03:00
|
|
|
struct_field_base:
|
|
|
|
| DATA IDENT option(COLLECTION) CONTENT typ {}
|
|
|
|
| CONDITION IDENT {}
|
|
|
|
|
|
|
|
struct_field_func:
|
|
|
|
| DEPENDS OF typ {}
|
|
|
|
|
|
|
|
struct_field:
|
|
|
|
| struct_field_base option(struct_field_func) {}
|
|
|
|
|
|
|
|
field_decl_item:
|
|
|
|
| CONTEXT IDENT STRUCT CONSTRUCTOR {}
|
|
|
|
|
|
|
|
field_decl_include:
|
2020-04-07 14:59:52 +03:00
|
|
|
| CONSTRUCTOR DOT IDENT EQUAL CONSTRUCTOR DOT IDENT option(condition) {}
|
|
|
|
|
|
|
|
field_decl_includes_context:
|
|
|
|
| CONTEXT nonempty_list(field_decl_include) {}
|
2020-04-03 23:58:34 +03:00
|
|
|
|
|
|
|
field_decl_includes:
|
2020-04-07 14:59:52 +03:00
|
|
|
| INCLUDES FIELD CONSTRUCTOR option(field_decl_includes_context) {}
|
2020-04-03 23:58:34 +03:00
|
|
|
|
2020-04-10 13:55:18 +03:00
|
|
|
enum_decl_line_payload:
|
2020-04-10 19:46:06 +03:00
|
|
|
| CONTENT typ {}
|
2020-04-10 13:55:18 +03:00
|
|
|
|
|
|
|
enum_decl_line:
|
|
|
|
| ALT CONSTRUCTOR option(enum_decl_line_payload) {}
|
|
|
|
|
2020-03-08 06:28:45 +03:00
|
|
|
code_item:
|
2020-04-03 23:34:11 +03:00
|
|
|
| FIELD CONSTRUCTOR COLON nonempty_list(application_field_item) { }
|
2020-04-10 19:46:06 +03:00
|
|
|
| DECLARATION STRUCT CONSTRUCTOR COLON list(struct_field) {}
|
2020-04-07 14:59:52 +03:00
|
|
|
| DECLARATION FIELD CONSTRUCTOR COLON nonempty_list(field_decl_item) list(field_decl_includes) {}
|
2020-04-10 13:55:18 +03:00
|
|
|
| DECLARATION ENUM CONSTRUCTOR COLON nonempty_list(enum_decl_line) {}
|
2020-03-08 06:28:45 +03:00
|
|
|
|
|
|
|
code:
|
2020-04-10 13:14:16 +03:00
|
|
|
| list(code_item) { mk_position $sloc }
|
2020-03-08 06:28:45 +03:00
|
|
|
|
2020-04-10 13:02:05 +03:00
|
|
|
metadata_block:
|
2020-04-10 13:14:16 +03:00
|
|
|
| BEGIN_CODE pos = code text = END_CODE END_METADATA { (text, pos) }
|
2020-04-10 13:02:05 +03:00
|
|
|
|
2020-03-08 02:21:55 +03:00
|
|
|
source_file_item:
|
2020-03-08 03:52:31 +03:00
|
|
|
| title = LAW_ARTICLE { LawArticle title }
|
|
|
|
| code = LAW_CODE { LawCode code }
|
|
|
|
| text = LAW_TEXT { LawText text }
|
2020-04-10 13:02:05 +03:00
|
|
|
| BEGIN_METADATA text = metadata_block { MetadataBlock text }
|
2020-04-10 13:14:16 +03:00
|
|
|
| BEGIN_CODE pos = code text = END_CODE { CodeBlock (text, pos) }
|
2020-03-08 02:21:55 +03:00
|
|
|
|
|
|
|
source_file:
|
2020-03-08 03:52:31 +03:00
|
|
|
| i = source_file_item f = source_file { i::f }
|
|
|
|
| EOF { [] }
|