Fixed surface ast with optional and collection type decorators

This commit is contained in:
Denis Merigoux 2020-05-07 09:40:09 +02:00
parent 39ee3a260e
commit d243c562a4
7 changed files with 88 additions and 142 deletions

View File

@ -81,7 +81,7 @@ grammar.html: src/catala/parsing/parser.mly
catala.html: src/catala/cli.ml
dune exec src/catala.exe -- --help=groff | groff -T html > $@
legifrance_catala.html: src/legifrance_catala/main.ml
legifrance_catala.html: src/legifrance_catala/main.ml
dune exec src/legifrance_catala.exe -- --help=groff | groff -T html > $@
clean:

View File

@ -35,10 +35,10 @@ déclaration énumération Collectivité :
déclaration structure Ménage :
donnée enfants contenu collection Enfant
donnée parent_en_charge contenu Personne dépend de Enfant
donnée enfant_plus_âgé contenu Enfant optionnel
donnée enfant_plus_âgé contenu optionnel Enfant
donnée parents contenu collection Personne
donnée parent1 contenu Personne
donnée parent2 contenu Personne optionnel
donnée parent2 contenu optionnel Personne
donnée résidence contenu Collectivité
# Le mot optionnel permet de prévoir le cas où le
# ménage n'a pas d'enfants
@ -131,7 +131,7 @@ déclaration énumération ChoixParentAllocataire :
-- DeuxParents
déclaration structure AllocationsGardeAlternée :
donnée choix_allocataire contenu ChoixParentAllocataire optionnel
donnée choix_allocataire contenu optionnel ChoixParentAllocataire
dépend de Enfant
condition unique_allocataire dépend de Enfant
condition allocataire_double dépend de Enfant

View File

@ -36,24 +36,25 @@ let retrieve_loc_text (pos : Pos.t) : string =
let input_line_opt () : string option = try Some (input_line oc) with End_of_file -> None in
let print_matched_line (line : string) (line_no : int) : string =
let line_indent = indent_number line in
let error_indicator_style = [ ANSITerminal.red; ANSITerminal.Bold ] in
line
^
if line_no >= sline && line_no <= eline then
"\n"
^
if line_no = sline && line_no = eline then
ANSITerminal.sprintf [ ANSITerminal.red ] "%*s"
ANSITerminal.sprintf error_indicator_style "%*s"
(Pos.get_end_column pos - 1)
(String.make (Pos.get_end_column pos - Pos.get_start_column pos) '^')
else if line_no = sline && line_no <> eline then
ANSITerminal.sprintf [ ANSITerminal.red ] "%*s"
ANSITerminal.sprintf error_indicator_style "%*s"
(String.length line - 1)
(String.make (String.length line - Pos.get_start_column pos) '^')
else if line_no <> sline && line_no <> eline then
ANSITerminal.sprintf [ ANSITerminal.red ] "%*s%s" line_indent ""
ANSITerminal.sprintf error_indicator_style "%*s%s" line_indent ""
(String.make (String.length line - line_indent) '^')
else if line_no <> sline && line_no = eline then
ANSITerminal.sprintf [ ANSITerminal.red ] "%*s%*s" line_indent ""
ANSITerminal.sprintf error_indicator_style "%*s%*s" line_indent ""
(Pos.get_end_column pos - 1 - line_indent)
(String.make (Pos.get_end_column pos - line_indent) '^')
else assert false (* should not happen *)
@ -70,7 +71,7 @@ let retrieve_loc_text (pos : Pos.t) : string =
| None -> []
in
let pos_lines = get_lines 1 in
let spaces = int_of_float (log (float_of_int eline)) - 2 in
let spaces = int_of_float (log (float_of_int eline)) in
close_in oc;
Printf.sprintf "%*s--> %s\n%s" spaces "" filename
(Cli.add_prefix_to_each_line

View File

@ -20,11 +20,10 @@ type qident = { qident_prefix : constructor Pos.marked option; qident_path : ide
type primitive_typ = Integer | Decimal | Boolean | Money | Text | Date | Named of constructor
type base_typ_data = {
typ_data_collection : Pos.t option;
typ_data_optional : Pos.t option;
typ_data_base : primitive_typ Pos.marked;
}
type base_typ_data =
| Primitive of primitive_typ
| Collection of base_typ_data Pos.marked
| Optional of base_typ_data Pos.marked
type base_typ = Condition | Data of base_typ_data

View File

@ -8,16 +8,6 @@ source_file_or_master: BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON ALT CONSTRU
## The known suffix of the stack is as follows:
## enum_decl_line
##
## WARNING: This example involves spurious reductions.
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 207, spurious reduction of production option(optional_marked) ->
## In state 210, spurious reduction of production typ -> option(collection_marked) typ_base option(optional_marked)
## In state 260, spurious reduction of production enum_decl_line_payload -> CONTENT typ
## In state 262, spurious reduction of production option(enum_decl_line_payload) -> enum_decl_line_payload
## In state 261, spurious reduction of production enum_decl_line -> ALT constructor option(enum_decl_line_payload)
##
Inclusion does not concern content of enumeration cases
@ -109,16 +99,6 @@ source_file_or_master: BEGIN_CODE DECLARATION FIELD CONSTRUCTOR COLON CONTEXT ID
## The known suffix of the stack is as follows:
## field_decl_item
##
## WARNING: This example involves spurious reductions.
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 207, spurious reduction of production option(optional_marked) ->
## In state 210, spurious reduction of production typ -> option(collection_marked) typ_base option(optional_marked)
## In state 216, spurious reduction of production struct_field_func -> DEPENDS typ
## In state 217, spurious reduction of production option(struct_field_func) -> struct_field_func
## In state 231, spurious reduction of production field_decl_item -> CONTEXT ident CONTENT typ option(struct_field_func)
##
Unexpected token
To get a better error messsage, file an issue at https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#250
@ -276,13 +256,6 @@ source_file_or_master: BEGIN_CODE DECLARATION FIELD CONSTRUCTOR COLON CONTEXT ID
## The known suffix of the stack is as follows:
## CONTEXT ident CONTENT typ
##
## WARNING: This example involves spurious reductions.
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 207, spurious reduction of production option(optional_marked) ->
## In state 210, spurious reduction of production typ -> option(collection_marked) typ_base option(optional_marked)
##
Unexpected token
To get a better error messsage, file an issue at https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#228
@ -374,46 +347,23 @@ source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION
## The known suffix of the stack is as follows:
## struct_field
##
## WARNING: This example involves spurious reductions.
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 207, spurious reduction of production option(optional_marked) ->
## In state 210, spurious reduction of production typ -> option(collection_marked) typ_base option(optional_marked)
## In state 216, spurious reduction of production struct_field_func -> DEPENDS typ
## In state 217, spurious reduction of production option(struct_field_func) -> struct_field_func
## In state 218, spurious reduction of production struct_field -> struct_field_base option(struct_field_func)
##
Unexpected token
To get a better error messsage, file an issue at https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#217
source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION IDENT DEPENDS COLLECTION BEGIN_METADATA
##
## Ends in an error in state: 200.
## Ends in an error in state: 211.
##
## typ -> option(collection_marked) . typ_base option(optional_marked) [ INCLUDES FIELD END_CODE DEPENDS DECLARATION DATA CONTEXT CONDITION ALT ]
## typ -> collection_marked . typ [ INCLUDES FIELD END_CODE DEPENDS DECLARATION DATA CONTEXT CONDITION ALT ]
##
## The known suffix of the stack is as follows:
## option(collection_marked)
## collection_marked
##
Unexpected token
To get a better error messsage, file an issue at https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#198
source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION IDENT DEPENDS TEXT YEAR
##
## Ends in an error in state: 207.
##
## typ -> option(collection_marked) typ_base . option(optional_marked) [ INCLUDES FIELD END_CODE DEPENDS DECLARATION DATA CONTEXT CONDITION ALT ]
##
## The known suffix of the stack is as follows:
## option(collection_marked) typ_base
##
Unexpected token
To get a better error messsage, file an issue at https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#205
source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION IDENT DEPENDS YEAR
##
## Ends in an error in state: 215.
@ -437,8 +387,7 @@ source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION
## struct_field_base
##
Unexpected token
To get a better error messsage, file an issue at https://github.com/CatalaLang/catala/issues with this parser error token: ERROR#212
Unexpected token, struct field declaration is over at this point
source_file_or_master: BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION YEAR
##
@ -560,16 +509,16 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON ASSERTION CARDINAL THE
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 42, spurious reduction of production primitive_expression -> CARDINAL
## In state 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## 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 185, spurious reduction of production assertion_base -> expression
## In state 186, spurious reduction of production assertion -> option(condition_consequence) assertion_base
## In state 187, spurious reduction of production application_field_item -> ASSERTION assertion
## In state 42, spurious reduction of production primitive_expression -> CARDINAL
## In state 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## 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 185, spurious reduction of production assertion_base -> expression
## In state 186, spurious reduction of production assertion -> option(condition_consequence) assertion_base
## In state 187, spurious reduction of production application_field_item -> ASSERTION assertion
##
Unexpected token after an application field item
@ -733,8 +682,8 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON ASSERTION FIXED IDENT
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 57, spurious reduction of production separated_nonempty_list(DOT,ident) -> ident
## In state 56, spurious reduction of production qident -> option(qident_prefix) separated_nonempty_list(DOT,ident)
## In state 57, spurious reduction of production separated_nonempty_list(DOT,ident) -> ident
## In state 56, spurious reduction of production qident -> option(qident_prefix) separated_nonempty_list(DOT,ident)
##
Unexpected token
@ -843,12 +792,12 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON ASSERTION IF NOW RULE
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## 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 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## 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
##
Unexpected token
@ -880,12 +829,12 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON ASSERTION IF NOW THEN
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## 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 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## 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
##
Unexpected token
@ -942,12 +891,12 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON ASSERTION LPAREN NOW T
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## 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 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## 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
##
Unmatched parenthesis that should have ended before this
@ -978,12 +927,12 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON ASSERTION MATCH NOW WI
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## In state 96, spurious reduction of production compare_expression -> sum_expression
## In state 106, spurious reduction of production logical_expression -> logical_unop compare_expression
## In state 142, spurious reduction of production match_arm -> constructor_binding COLON logical_expression
## In state 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## In state 96, spurious reduction of production compare_expression -> sum_expression
## In state 106, spurious reduction of production logical_expression -> logical_unop compare_expression
## In state 142, spurious reduction of production match_arm -> constructor_binding COLON logical_expression
##
Unexpected token
@ -1185,7 +1134,7 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON ASSERTION NOW INCREASI
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 50, spurious reduction of production base_expression -> primitive_expression
## In state 50, spurious reduction of production base_expression -> primitive_expression
##
Unexpected token
@ -1385,14 +1334,14 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON ASSERTION UNDER_CONDIT
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 42, spurious reduction of production primitive_expression -> CARDINAL
## In state 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## 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 150, spurious reduction of production condition -> UNDER_CONDITION expression
## In state 42, spurious reduction of production primitive_expression -> CARDINAL
## In state 50, spurious reduction of production base_expression -> primitive_expression
## In state 91, spurious reduction of production mult_expression -> base_expression
## In state 86, spurious reduction of production sum_expression -> mult_expression
## 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 150, spurious reduction of production condition -> UNDER_CONDITION expression
##
Unexpected token after a condition
@ -1423,8 +1372,8 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON ASSERTION VARIES IDENT
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 57, spurious reduction of production separated_nonempty_list(DOT,ident) -> ident
## In state 56, spurious reduction of production qident -> option(qident_prefix) separated_nonempty_list(DOT,ident)
## In state 57, spurious reduction of production separated_nonempty_list(DOT,ident) -> ident
## In state 56, spurious reduction of production qident -> option(qident_prefix) separated_nonempty_list(DOT,ident)
##
Unexpected token
@ -1443,7 +1392,7 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON ASSERTION VARIES IDENT
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 50, spurious reduction of production base_expression -> primitive_expression
## In state 50, spurious reduction of production base_expression -> primitive_expression
##
Unexpected token
@ -1614,8 +1563,8 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON DEFINITION IDENT WITH_
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 57, spurious reduction of production separated_nonempty_list(DOT,ident) -> ident
## In state 56, spurious reduction of production qident -> option(qident_prefix) separated_nonempty_list(DOT,ident)
## In state 57, spurious reduction of production separated_nonempty_list(DOT,ident) -> ident
## In state 56, spurious reduction of production qident -> option(qident_prefix) separated_nonempty_list(DOT,ident)
##
Only the identifier you wish to define should follow the definition introducing token
@ -1737,8 +1686,8 @@ source_file_or_master: BEGIN_CODE FIELD CONSTRUCTOR COLON RULE IDENT WITH_V
## This implies that, although the LR(1) items shown above provide an
## accurate view of the past (what has been recognized so far), they
## may provide an INCOMPLETE view of the future (what was expected next).
## In state 57, spurious reduction of production separated_nonempty_list(DOT,ident) -> ident
## In state 56, spurious reduction of production qident -> option(qident_prefix) separated_nonempty_list(DOT,ident)
## In state 57, spurious reduction of production separated_nonempty_list(DOT,ident) -> ident
## In state 56, spurious reduction of production qident -> option(qident_prefix) separated_nonempty_list(DOT,ident)
##
Unexpected token

View File

@ -72,12 +72,15 @@ optional_marked:
| OPTIONAL { $sloc }
typ:
| collection = option(collection_marked) t = typ_base optional = option(optional_marked) {
(Data {
typ_data_collection = collection;
typ_data_optional = optional;
typ_data_base = t;
}, $sloc)
| t = typ_base {
let t, loc = t in
(Primitive t, loc)
}
| collection_marked t = typ {
(Optional t, $sloc)
}
| optional_marked t = typ {
(Collection t, $sloc)
}
qident_prefix:
@ -359,7 +362,8 @@ condition_pos:
struct_field_base:
| DATA i= ident CONTENT t = typ {
(i, t)
let t, pos = t in
(i, (Data t, pos))
}
| pos = condition_pos i = ident {
(i, (Condition, pos))
@ -378,7 +382,7 @@ struct_field:
| None -> (Base typ, typ_pos)
| Some (return_typ, return_pos) -> (Func {
arg_typ = (typ, typ_pos);
return_typ = (return_typ, return_pos);
return_typ = (Data return_typ, return_pos);
}, $sloc) ;
}, $sloc)
}
@ -389,10 +393,10 @@ field_decl_item:
field_decl_context_item_typ =
let (typ, typ_pos) = t in
match func_typ with
| None -> (Base typ, typ_pos)
| None -> (Base (Data typ), typ_pos)
| Some (return_typ, return_pos) -> (Func {
arg_typ = (typ, typ_pos);
return_typ = (return_typ, return_pos);
arg_typ = (Data typ, typ_pos);
return_typ = (Data return_typ, return_pos);
}, $sloc);
}, $sloc) }
@ -420,7 +424,7 @@ field_decl_includes:
}
enum_decl_line_payload:
| CONTENT t = typ { let (t, t_pos) = t in (Base t, t_pos) }
| CONTENT t = typ { let (t, t_pos) = t in (Base (Data t), t_pos) }
enum_decl_line:
| ALT c = constructor t = option(enum_decl_line_payload) { ({

View File

@ -363,19 +363,12 @@ 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#219\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#212\n"
| 214 -> "Unexpected token, struct field declaration is over at this point\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#213\n"
| 207 ->
"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#205\n"
| 200 ->
| 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#198\n"