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-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-03-08 06:28:45 +03:00
|
|
|
%token BEGIN_CODE CHOICE
|
2020-03-08 07:01:26 +03:00
|
|
|
%token COLON ALT DOT SITUATION SOURCE DATA
|
|
|
|
%token OF SEMICOLON INTEGER TYPE COLLECTION
|
|
|
|
%token RULE CONDITION CONSEQUENCE DEFINED AS
|
2020-03-08 07:12:12 +03:00
|
|
|
%token EXISTS IN SUCH THAT NOW LESSER GREATER
|
2020-03-08 07:27:46 +03:00
|
|
|
%token BANG AND OR LPAREN RPAREN OPTIONAL EQUAL
|
|
|
|
%token COMMA CARDINAL LESSER_EQUAL GREATER_EQUAL
|
2020-03-08 02:21:55 +03:00
|
|
|
|
|
|
|
%type <Ast.source_file> source_file
|
|
|
|
|
|
|
|
%start source_file
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2020-03-08 06:28:45 +03:00
|
|
|
choice:
|
|
|
|
| CONSTRUCTOR {}
|
|
|
|
|
|
|
|
choices:
|
|
|
|
| ALT choice choices {}
|
|
|
|
| {}
|
|
|
|
|
2020-03-08 07:01:26 +03:00
|
|
|
type_ident:
|
|
|
|
| IDENT {}
|
|
|
|
| INTEGER {}
|
|
|
|
|
|
|
|
situation_type_alt:
|
2020-03-08 06:28:45 +03:00
|
|
|
| CHOICE IDENT {}
|
2020-03-08 07:01:26 +03:00
|
|
|
| TYPE type_ident {}
|
|
|
|
| SITUATION CONSTRUCTOR {}
|
|
|
|
|
|
|
|
situation_type:
|
|
|
|
| OF situation_type_alt {}
|
|
|
|
| {}
|
|
|
|
|
|
|
|
qident:
|
|
|
|
| IDENT {}
|
2020-03-08 07:27:46 +03:00
|
|
|
| CONSTRUCTOR {}
|
2020-03-08 07:01:26 +03:00
|
|
|
| IDENT BANG IDENT {}
|
|
|
|
|
|
|
|
primitive_expression:
|
|
|
|
| NOW {}
|
|
|
|
|
2020-03-08 07:27:46 +03:00
|
|
|
literal:
|
|
|
|
| INT_LITERAL {}
|
|
|
|
|
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 {}
|
|
|
|
|
|
|
|
func:
|
|
|
|
| CARDINAL {}
|
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-03-08 07:27:46 +03:00
|
|
|
| literal {}
|
|
|
|
| func LPAREN separated_nonempty_list(COMMA, expression) RPAREN {}
|
2020-03-08 07:01:26 +03:00
|
|
|
| qident {}
|
2020-03-08 07:12:12 +03:00
|
|
|
| LPAREN expression RPAREN {}
|
|
|
|
|
|
|
|
sum_expression:
|
|
|
|
| base_expression {}
|
|
|
|
|
|
|
|
logical_op:
|
|
|
|
| AND {}
|
|
|
|
| OR {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
|
|
|
compare_expression:
|
2020-03-08 07:12:12 +03:00
|
|
|
| sum_expression {}
|
2020-03-08 07:01:26 +03:00
|
|
|
| sum_expression compare_op sum_expression {}
|
|
|
|
|
2020-03-08 07:12:12 +03:00
|
|
|
logical_expression:
|
|
|
|
| compare_expression {}
|
|
|
|
| compare_expression logical_op compare_expression {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
|
|
|
expression:
|
|
|
|
| EXISTS IDENT IN qident SUCH THAT expression {}
|
2020-03-08 07:12:12 +03:00
|
|
|
| logical_expression {}
|
2020-03-08 07:01:26 +03:00
|
|
|
|
|
|
|
condition:
|
|
|
|
| CONDITION expression CONSEQUENCE {}
|
|
|
|
|
|
|
|
rule_definition:
|
|
|
|
| AS expression {}
|
|
|
|
| {}
|
|
|
|
|
|
|
|
rule:
|
2020-03-08 07:27:46 +03:00
|
|
|
| option(condition) qident DEFINED rule_definition {}
|
2020-03-08 06:28:45 +03:00
|
|
|
|
|
|
|
situation:
|
2020-03-08 07:01:26 +03:00
|
|
|
| DATA IDENT option(COLLECTION) situation_type {}
|
2020-03-08 07:27:46 +03:00
|
|
|
| RULE option(OPTIONAL) rule {}
|
2020-03-08 06:28:45 +03:00
|
|
|
|
|
|
|
code_item:
|
2020-03-08 07:01:26 +03:00
|
|
|
| CHOICE IDENT COLON choices { }
|
|
|
|
| SITUATION CONSTRUCTOR SOURCE IDENT COLON separated_nonempty_list(SEMICOLON, situation) { }
|
2020-03-08 06:28:45 +03:00
|
|
|
|
|
|
|
code:
|
2020-03-08 07:01:26 +03:00
|
|
|
| code_item DOT code {}
|
2020-03-08 06:28:45 +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-03-08 06:28:45 +03:00
|
|
|
| BEGIN_CODE code text = END_CODE { CodeBlock text }
|
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 { [] }
|