From 982e4f574855ad1f6cc040ef19141a5230a9f0a0 Mon Sep 17 00:00:00 2001 From: Denis Merigoux Date: Sun, 17 May 2020 23:01:07 +0200 Subject: [PATCH] Added scope inclusion to tutorial --- .../allocations_familiales/metadata.catala | 10 +- .../securite_sociale_R.catala | 4 +- examples/tutorial/tutorial_en.catala | 70 +++++++++++ src/catala/parsing/ast.ml | 1 + src/catala/parsing/lexer_en.ml | 2 +- src/catala/parsing/parser.messages | 96 +++++++-------- src/catala/parsing/parser.mly | 3 +- src/catala/parsing/parser_errors.ml | 114 +++++++++--------- 8 files changed, 187 insertions(+), 113 deletions(-) diff --git a/examples/allocations_familiales/metadata.catala b/examples/allocations_familiales/metadata.catala index 3db1a46c..30d5a54a 100644 --- a/examples/allocations_familiales/metadata.catala +++ b/examples/allocations_familiales/metadata.catala @@ -191,7 +191,7 @@ déclaration champ d'application CalculPrestationsFamiliales : contexte l512_3 contenu L512_3 champ d'application CalculPrestationsFamiliales: - inclus champ d'application MénageBienFormé contexte + inclus ménage_bien_formé champ d'application MénageBienFormé contexte ménage = ménage déclaration champ d'application CalculAllocationsFamiliales : @@ -212,9 +212,11 @@ déclaration champ d'application CalculAllocationsFamiliales : contexte d521_3 contenu D521_3 champ d'application CalculAllocationsFamiliales: - inclus champ d'application CalculPrestationsFamiliales contexte - ménage = ménage - date_calcul = date_calcul + inclus calcul_prestations_familiales + champ d'application CalculPrestationsFamiliales + contexte + ménage = ménage + date_calcul = date_calcul # AllocationsFamiliales est un cas particulier de PrestationsFamiliales, # le dernier est donc inclus dans l'autre. Il est nécessaire de préciser # que les deux contextes parlent du même ménage pour caractériser diff --git a/examples/allocations_familiales/securite_sociale_R.catala b/examples/allocations_familiales/securite_sociale_R.catala index bfd880ea..c6228d7f 100644 --- a/examples/allocations_familiales/securite_sociale_R.catala +++ b/examples/allocations_familiales/securite_sociale_R.catala @@ -55,11 +55,11 @@ champ d'application CalculAllocationFamilialesAvril2008: définition l521_3.minimum_alinéa_2 de enfant égal à 16 an champ d'application CalculAllocationsFamiliales : - inclus champ d'application AllocationFamilialesAvril2008 + inclus calcul_avril_2008 champ d'application AllocationFamilialesAvril2008 définition l521_3.minimum_alinéa_2 de enfant sous condition (enfant.date_naissance + 11 an <= |30/04/2008|) conséquence égal à - CalculAllocationFamilialesAvril2008.l521_3.minimum_alinéa_2 de enfant + calcul_avril_2008.l521_3.minimum_alinéa_2 de enfant */ @Article R521-2|LEGIARTI000006750608@ Dans les situations visées au deuxième alinéa de l'article L. 521-2 , l'allocataire est celui des deux parents qu'ils désignent d'un commun accord. A défaut d'accord sur la désignation d'un allocataire unique, chacun des deux parents peut se voir reconnaître la qualité d'allocataire : diff --git a/examples/tutorial/tutorial_en.catala b/examples/tutorial/tutorial_en.catala index 29174b58..45af9436 100644 --- a/examples/tutorial/tutorial_en.catala +++ b/examples/tutorial/tutorial_en.catala @@ -97,3 +97,73 @@ scope IncomeTaxComputation: */ When the Catala program will execute, the right definition will be dynamically chosen by looking at which condition is true. A correctly drafted legislative source should always ensure that at most one condition is true at all times. However, if it is not the case, Catala will let you define a precedence on the conditions, which has to be justified by the law. + + +@@Functions@@ + +Catala lets you define functions anywhere in your data. Here's what it looks like in the metadata definition when we want to define a two-breackets tax computation: +@@Begin metadata@@ +/* +declaration structure TwoBrackets: + data breakpoint content amount + data rate1 content decimal + data rate2 content decimal + +declaration scope TwoBracketsTaxComputation : + context brackets content TwoBrackets + context tax_formula content amount depends on amount +*/ +@@End metadata@@ + +And in the code: + +@Article4@ The tax amount for a two-brackets computation is equal to the amount of income in each bracket multiplied by the rate of each bracket. + +/* +scope TwoBracketsTaxComputation : + definition tax of income equals + if income <= breakpoint then + income * rate1 + else ( + breakpoint * rate1 + (income - breakpoint) * rate2 + ) +*/ + +@@Scope inclusion@@ + +Now that we've defined our helper scope for computing a two-brackets tax, we want to use it in our main tax computation scope. + +@Article 5@ For individuals whose income is greater than \$100,000, the income tax of article 1 is computed with a two-brackets system. +/* +scope IncomeTaxComputation : + includes two_brackets_for_rich scope TwoBracketsTaxComputation + definition article1.income_tax under condition + individual.income >= $100,000 + consequence equals + two_brackets_for_rich.tax of individual.income +*/ + +Scope inclusion also comes with a syntactic sugar for quickly and conditionnaly +connecting context quantities : + +@@Begin metadata@@ +/* +declaration scope ExemptedOfTax: + context article1 content Article1 +*/ +@@End metadata@@ + +@Article 6@ +Individuals earning less than \$10,000 are exempted of the income tax mentionned at article 1. +/* +scope ExemptedOfTax : + definition article1.income_tax equals $0 + +scope IncomeTaxComputation: + includes tax_exempt scope ExemptedOfTax context + article1 = article1 + under condition + individual.income <= $10,000 +*/ + +This snippet of code actually brings the definition of article1.income_tax of ExemptedOfTax into the IncomeTaxComputation scope, prefixing it with the "income under \$10,000" condition. diff --git a/src/catala/parsing/ast.ml b/src/catala/parsing/ast.ml index e7120ae2..8f3d1e57 100644 --- a/src/catala/parsing/ast.ml +++ b/src/catala/parsing/ast.ml @@ -144,6 +144,7 @@ type scope_inclusion_join = { } type scope_inclusion = { + scope_inclusion_name : ident Pos.marked; scope_inclusion_sub_scope : constructor Pos.marked; scope_inclusion_joins : scope_inclusion_join Pos.marked list; scope_inclusion_condition : expression Pos.marked option; diff --git a/src/catala/parsing/lexer_en.ml b/src/catala/parsing/lexer_en.ml index 391d5238..4d6304c8 100644 --- a/src/catala/parsing/lexer_en.ml +++ b/src/catala/parsing/lexer_en.ml @@ -96,7 +96,7 @@ let rec lex_code_en (lexbuf : lexbuf) : token = | "data" -> update_acc lexbuf; DATA - | "depends" -> + | "depends on" -> update_acc lexbuf; DEPENDS | "declaration" -> diff --git a/src/catala/parsing/parser.messages b/src/catala/parsing/parser.messages index a3859006..e72c827e 100644 --- a/src/catala/parsing/parser.messages +++ b/src/catala/parsing/parser.messages @@ -1,6 +1,6 @@ source_file_or_master: BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON ALT CONSTRUCTOR CONTENT BOOLEAN INCLUDES ## -## Ends in an error in state: 262. +## Ends in an error in state: 263. ## ## nonempty_list(enum_decl_line) -> enum_decl_line . [ SCOPE END_CODE DECLARATION ] ## nonempty_list(enum_decl_line) -> enum_decl_line . nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ] @@ -13,7 +13,7 @@ Inclusion does not concern content of enumeration cases source_file_or_master: BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON ALT CONSTRUCTOR CONTENT YEAR ## -## Ends in an error in state: 257. +## Ends in an error in state: 258. ## ## enum_decl_line_payload -> CONTENT . typ [ SCOPE END_CODE DECLARATION ALT ] ## @@ -26,7 +26,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON ALT CONSTRUCTOR YEAR ## -## Ends in an error in state: 256. +## Ends in an error in state: 257. ## ## enum_decl_line -> ALT constructor . option(enum_decl_line_payload) [ SCOPE END_CODE DECLARATION ALT ] ## @@ -39,7 +39,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON ALT YEAR ## -## Ends in an error in state: 255. +## Ends in an error in state: 256. ## ## enum_decl_line -> ALT . constructor option(enum_decl_line_payload) [ SCOPE END_CODE DECLARATION ALT ] ## @@ -52,7 +52,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON YEAR ## -## Ends in an error in state: 254. +## Ends in an error in state: 255. ## ## code_item -> DECLARATION ENUM constructor COLON . nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ] ## @@ -65,7 +65,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION ENUM CONSTRUCTOR YEAR ## -## Ends in an error in state: 253. +## Ends in an error in state: 254. ## ## code_item -> DECLARATION ENUM constructor . COLON nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ] ## @@ -78,7 +78,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION ENUM YEAR ## -## Ends in an error in state: 252. +## Ends in an error in state: 253. ## ## code_item -> DECLARATION ENUM . constructor COLON nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ] ## @@ -91,7 +91,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT IDENT CONTENT BOOLEAN DEPENDS BOOLEAN DEPENDS ## -## Ends in an error in state: 249. +## Ends in an error in state: 250. ## ## nonempty_list(scope_decl_item) -> scope_decl_item . [ SCOPE END_CODE DECLARATION ] ## nonempty_list(scope_decl_item) -> scope_decl_item . nonempty_list(scope_decl_item) [ SCOPE END_CODE DECLARATION ] @@ -105,7 +105,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT IDENT CONTENT TEXT DATA ## -## Ends in an error in state: 247. +## Ends in an error in state: 248. ## ## scope_decl_item -> CONTEXT ident CONTENT typ . option(struct_scope_func) [ SCOPE END_CODE DECLARATION CONTEXT ] ## @@ -118,7 +118,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT IDENT CONTENT YEAR ## -## Ends in an error in state: 246. +## Ends in an error in state: 247. ## ## scope_decl_item -> CONTEXT ident CONTENT . typ option(struct_scope_func) [ SCOPE END_CODE DECLARATION CONTEXT ] ## @@ -131,7 +131,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT IDENT YEAR ## -## Ends in an error in state: 245. +## Ends in an error in state: 246. ## ## scope_decl_item -> CONTEXT ident . CONTENT typ option(struct_scope_func) [ SCOPE END_CODE DECLARATION CONTEXT ] ## @@ -144,7 +144,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT YEAR ## -## Ends in an error in state: 244. +## Ends in an error in state: 245. ## ## scope_decl_item -> CONTEXT . ident CONTENT typ option(struct_scope_func) [ SCOPE END_CODE DECLARATION CONTEXT ] ## @@ -157,7 +157,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON YEAR ## -## Ends in an error in state: 243. +## Ends in an error in state: 244. ## ## code_item -> DECLARATION SCOPE constructor COLON . nonempty_list(scope_decl_item) [ SCOPE END_CODE DECLARATION ] ## @@ -170,7 +170,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR YEAR ## -## Ends in an error in state: 242. +## Ends in an error in state: 243. ## ## code_item -> DECLARATION SCOPE constructor . COLON nonempty_list(scope_decl_item) [ SCOPE END_CODE DECLARATION ] ## @@ -183,7 +183,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION SCOPE YEAR ## -## Ends in an error in state: 241. +## Ends in an error in state: 242. ## ## code_item -> DECLARATION SCOPE . constructor COLON nonempty_list(scope_decl_item) [ SCOPE END_CODE DECLARATION ] ## @@ -196,7 +196,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION IDENT DEPENDS BOOLEAN INCLUDES ## -## Ends in an error in state: 236. +## Ends in an error in state: 237. ## ## list(struct_scope) -> struct_scope . list(struct_scope) [ SCOPE END_CODE DECLARATION ] ## @@ -209,7 +209,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION IDENT DEPENDS COLLECTION BEGIN_METADATA ## -## Ends in an error in state: 228. +## Ends in an error in state: 229. ## ## typ -> collection_marked . typ [ SCOPE END_CODE DEPENDS DECLARATION DATA CONTEXT CONDITION ALT ] ## @@ -222,7 +222,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION IDENT DEPENDS YEAR ## -## Ends in an error in state: 232. +## Ends in an error in state: 233. ## ## struct_scope_func -> DEPENDS . typ [ SCOPE END_CODE DECLARATION DATA CONTEXT CONDITION ] ## @@ -235,7 +235,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION IDENT YEAR ## -## Ends in an error in state: 231. +## Ends in an error in state: 232. ## ## struct_scope -> struct_scope_base . option(struct_scope_func) [ SCOPE END_CODE DECLARATION DATA CONDITION ] ## @@ -247,7 +247,7 @@ Unexpected token, struct scope declaration is over at this point source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION YEAR ## -## Ends in an error in state: 238. +## Ends in an error in state: 239. ## ## struct_scope_base -> condition_pos . ident [ SCOPE END_CODE DEPENDS DECLARATION DATA CONDITION ] ## @@ -260,7 +260,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON DATA IDENT CONTENT YEAR ## -## Ends in an error in state: 214. +## Ends in an error in state: 215. ## ## struct_scope_base -> DATA ident CONTENT . typ [ SCOPE END_CODE DEPENDS DECLARATION DATA CONDITION ] ## @@ -273,7 +273,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON DATA IDENT YEAR ## -## Ends in an error in state: 213. +## Ends in an error in state: 214. ## ## struct_scope_base -> DATA ident . CONTENT typ [ SCOPE END_CODE DEPENDS DECLARATION DATA CONDITION ] ## @@ -286,7 +286,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON DATA YEAR ## -## Ends in an error in state: 212. +## Ends in an error in state: 213. ## ## struct_scope_base -> DATA . ident CONTENT typ [ SCOPE END_CODE DEPENDS DECLARATION DATA CONDITION ] ## @@ -299,7 +299,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON YEAR ## -## Ends in an error in state: 211. +## Ends in an error in state: 212. ## ## code_item -> DECLARATION STRUCT constructor COLON . list(struct_scope) [ SCOPE END_CODE DECLARATION ] ## @@ -312,7 +312,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR YEAR ## -## Ends in an error in state: 210. +## Ends in an error in state: 211. ## ## code_item -> DECLARATION STRUCT constructor . COLON list(struct_scope) [ SCOPE END_CODE DECLARATION ] ## @@ -325,7 +325,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION STRUCT YEAR ## -## Ends in an error in state: 209. +## Ends in an error in state: 210. ## ## code_item -> DECLARATION STRUCT . constructor COLON list(struct_scope) [ SCOPE END_CODE DECLARATION ] ## @@ -338,7 +338,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE DECLARATION YEAR ## -## Ends in an error in state: 208. +## Ends in an error in state: 209. ## ## code_item -> DECLARATION . STRUCT constructor COLON list(struct_scope) [ SCOPE END_CODE DECLARATION ] ## code_item -> DECLARATION . SCOPE constructor COLON nonempty_list(scope_decl_item) [ SCOPE END_CODE DECLARATION ] @@ -353,7 +353,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON ASSERTION CARDINAL THEN ## -## Ends in an error in state: 205. +## Ends in an error in state: 206. ## ## nonempty_list(scope_item) -> scope_item . [ SCOPE END_CODE DECLARATION ] ## nonempty_list(scope_item) -> scope_item . nonempty_list(scope_item) [ SCOPE END_CODE DECLARATION ] @@ -372,9 +372,9 @@ source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON ASSERTION CARDINAL THE ## In state 96, spurious reduction of production compare_expression -> sum_expression ## In state 123, spurious reduction of production logical_expression -> compare_expression ## In state 107, spurious reduction of production expression -> logical_expression -## In state 202, spurious reduction of production assertion_base -> expression -## In state 203, spurious reduction of production assertion -> option(condition_consequence) assertion_base -## In state 204, spurious reduction of production scope_item -> ASSERTION assertion +## In state 203, spurious reduction of production assertion_base -> expression +## In state 204, spurious reduction of production assertion -> option(condition_consequence) assertion_base +## In state 205, spurious reduction of production scope_item -> ASSERTION assertion ## Unexpected token after a scope item @@ -514,7 +514,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON ASSERTION FIXED IDENT BY YEAR ## -## Ends in an error in state: 199. +## Ends in an error in state: 200. ## ## assertion -> FIXED qident BY . ident [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -527,7 +527,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON ASSERTION FIXED IDENT WITH_V ## -## Ends in an error in state: 198. +## Ends in an error in state: 199. ## ## assertion -> FIXED qident . BY ident [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -547,7 +547,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON ASSERTION FIXED YEAR ## -## Ends in an error in state: 197. +## Ends in an error in state: 198. ## ## assertion -> FIXED . qident BY ident [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1166,7 +1166,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON ASSERTION UNDER_CONDITION CARDINAL CONSEQUENCE BY ## -## Ends in an error in state: 201. +## Ends in an error in state: 202. ## ## assertion -> option(condition_consequence) . assertion_base [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1217,7 +1217,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON ASSERTION VARIES IDENT WITH ## -## Ends in an error in state: 190. +## Ends in an error in state: 191. ## ## assertion -> VARIES qident . WITH_V base_expression option(variation_type) [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1237,7 +1237,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON ASSERTION VARIES IDENT WITH_V NOW THEN ## -## Ends in an error in state: 192. +## Ends in an error in state: 193. ## ## assertion -> VARIES qident WITH_V base_expression . option(variation_type) [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1256,7 +1256,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON ASSERTION VARIES IDENT WITH_V YEAR ## -## Ends in an error in state: 191. +## Ends in an error in state: 192. ## ## assertion -> VARIES qident WITH_V . base_expression option(variation_type) [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1269,7 +1269,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON ASSERTION VARIES YEAR ## -## Ends in an error in state: 189. +## Ends in an error in state: 190. ## ## assertion -> VARIES . qident WITH_V base_expression option(variation_type) [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1357,7 +1357,7 @@ Expected date inside "|...|" source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON ASSERTION YEAR ## -## Ends in an error in state: 188. +## Ends in an error in state: 189. ## ## scope_item -> ASSERTION . assertion [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1370,7 +1370,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON DEFINITION IDENT DEFINED_AS YEAR ## -## Ends in an error in state: 185. +## Ends in an error in state: 186. ## ## definition -> qident option(definition_parameters) option(condition_consequence) DEFINED_AS . expression [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1383,7 +1383,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON DEFINITION IDENT OF IDENT DECREASING ## -## Ends in an error in state: 183. +## Ends in an error in state: 184. ## ## definition -> qident option(definition_parameters) . option(condition_consequence) DEFINED_AS expression [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1395,7 +1395,7 @@ Wrong token following function parameter source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON DEFINITION IDENT UNDER_CONDITION CARDINAL CONSEQUENCE DECREASING ## -## Ends in an error in state: 184. +## Ends in an error in state: 185. ## ## definition -> qident option(definition_parameters) option(condition_consequence) . DEFINED_AS expression [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1408,7 +1408,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON DEFINITION IDENT WITH_V ## -## Ends in an error in state: 182. +## Ends in an error in state: 183. ## ## definition -> qident . option(definition_parameters) option(condition_consequence) DEFINED_AS expression [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1427,7 +1427,7 @@ Only the identifier you wish to define should follow the definition introducing source_file_or_master: BEGIN_CODE SCOPE CONSTRUCTOR COLON DEFINITION YEAR ## -## Ends in an error in state: 181. +## Ends in an error in state: 182. ## ## scope_item -> DEFINITION . definition [ SCOPE RULE INCLUDES END_CODE DEFINITION DECLARATION ASSERTION ] ## @@ -1613,7 +1613,7 @@ Expecting the constructor for the scope source_file_or_master: BEGIN_CODE YEAR ## -## Ends in an error in state: 271. +## Ends in an error in state: 272. ## ## source_file_item -> BEGIN_CODE . code END_CODE [ LAW_TEXT LAW_INCLUDE LAW_HEADING LAW_ARTICLE EOF BEGIN_METADATA BEGIN_CODE ] ## @@ -1625,7 +1625,7 @@ Wrong way to begin a code section source_file_or_master: BEGIN_METADATA BEGIN_CODE END_CODE YEAR ## -## Ends in an error in state: 268. +## Ends in an error in state: 269. ## ## metadata_block -> BEGIN_CODE code END_CODE . END_METADATA [ LAW_TEXT LAW_INCLUDE LAW_HEADING LAW_ARTICLE EOF BEGIN_METADATA BEGIN_CODE ] ## @@ -1664,7 +1664,7 @@ To get a better error messsage, file an issue at https://github.com/CatalaLang/c source_file_or_master: LAW_TEXT YEAR ## -## Ends in an error in state: 275. +## Ends in an error in state: 276. ## ## source_file -> source_file_item . source_file [ # ] ## diff --git a/src/catala/parsing/parser.mly b/src/catala/parsing/parser.mly index c0b506d9..43e4f930 100644 --- a/src/catala/parsing/parser.mly +++ b/src/catala/parsing/parser.mly @@ -418,10 +418,11 @@ scope_inclusion_condition: | UNDER_CONDITION e = expression { e } scope_inclusion: -| SCOPE c = constructor context = option(scope_inclusion_context) +| name = ident SCOPE c = constructor context = option(scope_inclusion_context) condition = option(scope_inclusion_condition) { ({ + scope_inclusion_name = name; scope_inclusion_sub_scope = c; scope_inclusion_joins = begin match context with | None -> [] diff --git a/src/catala/parsing/parser_errors.ml b/src/catala/parsing/parser_errors.ml index b8df6702..5c1af787 100644 --- a/src/catala/parsing/parser_errors.ml +++ b/src/catala/parsing/parser_errors.ml @@ -16,7 +16,7 @@ let message s = "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#5\n" - | 275 -> + | 276 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#275\n" @@ -28,11 +28,11 @@ let message s = "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#13\n" - | 268 -> + | 269 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#268\n" - | 271 -> "Wrong way to begin a code section\n" + | 272 -> "Wrong way to begin a code section\n" | 14 -> "Expecting the constructor for the scope\n" | 16 -> "Expected a colon after scope constructor\n" | 17 -> "Expected a rule, a definition or an assertion\n" @@ -73,21 +73,21 @@ let message s = "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#64\n" - | 181 -> + | 182 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#162\n" - | 182 -> "Only the identifier you wish to define should follow the definition introducing token\n" - | 184 -> - "Unexpected token\n\ - To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#165\n" - | 183 -> "Wrong token following function parameter\n" + | 183 -> "Only the identifier you wish to define should follow the definition introducing token\n" | 185 -> + "Unexpected token\n\ + To get a better error messsage, file an issue at \ + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#165\n" + | 184 -> "Wrong token following function parameter\n" + | 186 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#166\n" - | 188 -> + | 189 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#169\n" @@ -106,19 +106,19 @@ let message s = "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#28\n" - | 189 -> + | 190 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#170\n" - | 191 -> - "Unexpected token\n\ - To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#172\n" | 192 -> + "Unexpected token\n\ + To get a better error messsage, file an issue at \ + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#172\n" + | 193 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#173\n" - | 190 -> + | 191 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#171\n" @@ -127,7 +127,7 @@ let message s = To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#21\n" | 156 -> "Unexpected token after a condition\n" - | 201 -> + | 202 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#182\n" @@ -278,15 +278,15 @@ let message s = "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#106\n" - | 197 -> - "Unexpected token\n\ - To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#178\n" | 198 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#179\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#178\n" | 199 -> + "Unexpected token\n\ + To get a better error messsage, file an issue at \ + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#179\n" + | 200 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#180\n" @@ -330,107 +330,107 @@ let message s = "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#43\n" - | 205 -> "Unexpected token after a scope item\n" - | 208 -> - "Unexpected token\n\ - To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#189\n" + | 206 -> "Unexpected token after a scope item\n" | 209 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#190\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#189\n" | 210 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#191\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#190\n" | 211 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#192\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#191\n" | 212 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#193\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#192\n" | 213 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#194\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#193\n" | 214 -> + "Unexpected token\n\ + To get a better error messsage, file an issue at \ + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#194\n" + | 215 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#195\n" - | 238 -> + | 239 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#219\n" - | 231 -> "Unexpected token, struct scope declaration is over at this point\n" - | 232 -> + | 232 -> "Unexpected token, struct scope declaration is over at this point\n" + | 233 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#213\n" - | 228 -> + | 229 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#198\n" - | 236 -> + | 237 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#217\n" - | 241 -> - "Unexpected token\n\ - To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#222\n" | 242 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#223\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#222\n" | 243 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#224\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#223\n" | 244 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#225\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#224\n" | 245 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#226\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#225\n" | 246 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#227\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#226\n" | 247 -> + "Unexpected token\n\ + To get a better error messsage, file an issue at \ + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#227\n" + | 248 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#228\n" - | 249 -> + | 250 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#250\n" - | 252 -> - "Unexpected token\n\ - To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#252\n" | 253 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#253\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#252\n" | 254 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#254\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#253\n" | 255 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#255\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#254\n" | 256 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ - https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#256\n" + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#255\n" | 257 -> + "Unexpected token\n\ + To get a better error messsage, file an issue at \ + https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#256\n" + | 258 -> "Unexpected token\n\ To get a better error messsage, file an issue at \ https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#257\n" - | 262 -> "Inclusion does not concern content of enumeration cases\n" + | 263 -> "Inclusion does not concern content of enumeration cases\n" | _ -> raise Not_found