Merge pull request #75 from R1kM/master

Disambiguation syntax for fields and constructors. Fixes #74
This commit is contained in:
Denis Merigoux 2021-01-27 15:28:39 +01:00 committed by GitHub
commit a0a37aceca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 622 additions and 477 deletions

View File

@ -134,7 +134,8 @@ type enum_decl = {
nude = true;
}]
type match_case_pattern = constructor Pos.marked list * ident Pos.marked option
type match_case_pattern =
(constructor Pos.marked option * constructor Pos.marked) list * ident Pos.marked option
[@@deriving
visitors
{
@ -258,12 +259,13 @@ and expression =
| FunCall of expression Pos.marked * expression Pos.marked
| Builtin of builtin_expression
| Literal of literal
| EnumInject of constructor Pos.marked * expression Pos.marked option
| EnumInject of
constructor Pos.marked option * constructor Pos.marked * expression Pos.marked option
| EnumProject of expression Pos.marked * constructor Pos.marked
| StructLit of constructor Pos.marked * (ident Pos.marked * expression Pos.marked) list
| ArrayLit of expression Pos.marked list
| Ident of ident
| Dotted of expression Pos.marked * ident Pos.marked
| Dotted of expression Pos.marked * constructor Pos.marked option * ident Pos.marked
(** Dotted is for both struct field projection and sub-scope variables *)
[@@deriving
visitors

View File

@ -55,9 +55,10 @@ let translate_unop (op : Ast.unop) : Dcalc.Ast.unop =
module LiftStructFieldMap = Bindlib.Lift (Scopelang.Ast.StructFieldMap)
module LiftEnumConstructorMap = Bindlib.Lift (Scopelang.Ast.EnumConstructorMap)
let disambiguate_constructor (ctxt : Name_resolution.context) (constructor : string Pos.marked list)
(pos : Pos.t) : Scopelang.Ast.EnumName.t * Scopelang.Ast.EnumConstructor.t =
let constructor =
let disambiguate_constructor (ctxt : Name_resolution.context)
(constructor : (string Pos.marked option * string Pos.marked) list) (pos : Pos.t) :
Scopelang.Ast.EnumName.t * Scopelang.Ast.EnumConstructor.t =
let enum, constructor =
match constructor with
| [ c ] -> c
| _ ->
@ -71,17 +72,36 @@ let disambiguate_constructor (ctxt : Name_resolution.context) (constructor : str
"The name of this constructor has not been defined before, maybe it is a typo?"
(Pos.get_position constructor)
in
if Scopelang.Ast.EnumMap.cardinal possible_c_uids > 1 then
Errors.raise_spanned_error
(Format.asprintf
"This constuctor name is ambiguous, it can belong to %a. Desambiguate it by prefixing it \
with the enum name."
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt " or ")
(fun fmt (s_name, _) -> Format.fprintf fmt "%a" Scopelang.Ast.EnumName.format_t s_name))
(Scopelang.Ast.EnumMap.bindings possible_c_uids))
(Pos.get_position constructor);
Scopelang.Ast.EnumMap.choose possible_c_uids
match enum with
| None ->
if Scopelang.Ast.EnumMap.cardinal possible_c_uids > 1 then
Errors.raise_spanned_error
(Format.asprintf
"This constructor name is ambiguous, it can belong to %a. Disambiguate it by \
prefixing it with the enum name."
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt " or ")
(fun fmt (s_name, _) ->
Format.fprintf fmt "%a" Scopelang.Ast.EnumName.format_t s_name))
(Scopelang.Ast.EnumMap.bindings possible_c_uids))
(Pos.get_position constructor);
Scopelang.Ast.EnumMap.choose possible_c_uids
| Some enum -> (
try
(* The path is fully qualified *)
let e_uid = Desugared.Ast.IdentMap.find (Pos.unmark enum) ctxt.enum_idmap in
try
let c_uid = Scopelang.Ast.EnumMap.find e_uid possible_c_uids in
(e_uid, c_uid)
with Not_found ->
Errors.raise_spanned_error
(Format.asprintf "Enum %s does not contain case %s" (Pos.unmark enum)
(Pos.unmark constructor))
pos
with Not_found ->
Errors.raise_spanned_error
(Format.asprintf "Enum %s has not been defined before" (Pos.unmark enum))
(Pos.get_position enum) )
(** Usage: [translate_expr scope ctxt expr]
@ -205,7 +225,7 @@ let rec translate_expr (scope : Scopelang.Ast.ScopeName.t) (ctxt : Name_resoluti
| Some uid ->
Scopelang.Ast.make_var (uid, pos) (* the whole box thing is to accomodate for this case *)
)
| Dotted (e, x) -> (
| Dotted (e, c, x) -> (
match Pos.unmark e with
| Ident y when Name_resolution.is_subscope_uid scope ctxt y ->
(* In this case, y.x is a subscope variable *)
@ -220,7 +240,7 @@ let rec translate_expr (scope : Scopelang.Ast.ScopeName.t) (ctxt : Name_resoluti
( Scopelang.Ast.ELocation
(SubScopeVar (subscope_real_uid, (subscope_uid, pos), (subscope_var_uid, pos))),
pos )
| _ ->
| _ -> (
(* In this case e.x is the struct field x access of expression e *)
let e = translate_expr scope ctxt e in
let x_possible_structs =
@ -229,20 +249,40 @@ let rec translate_expr (scope : Scopelang.Ast.ScopeName.t) (ctxt : Name_resoluti
Errors.raise_spanned_error "This identifier should refer to a struct field"
(Pos.get_position x)
in
if Scopelang.Ast.StructMap.cardinal x_possible_structs > 1 then
Errors.raise_spanned_error
(Format.asprintf
"This struct field name is ambiguous, it can belong to %a. Desambiguate it by \
prefixing it with the struct name."
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt " or ")
(fun fmt (s_name, _) ->
Format.fprintf fmt "%a" Scopelang.Ast.StructName.format_t s_name))
(Scopelang.Ast.StructMap.bindings x_possible_structs))
(Pos.get_position x)
else
let s_uid, f_uid = Scopelang.Ast.StructMap.choose x_possible_structs in
Bindlib.box_apply (fun e -> (Scopelang.Ast.EStructAccess (e, f_uid, s_uid), pos)) e )
match c with
| None ->
(* No constructor name was specified *)
if Scopelang.Ast.StructMap.cardinal x_possible_structs > 1 then
Errors.raise_spanned_error
(Format.asprintf
"This struct field name is ambiguous, it can belong to %a. Disambiguate it by \
prefixing it with the struct name."
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt " or ")
(fun fmt (s_name, _) ->
Format.fprintf fmt "%a" Scopelang.Ast.StructName.format_t s_name))
(Scopelang.Ast.StructMap.bindings x_possible_structs))
(Pos.get_position x)
else
let s_uid, f_uid = Scopelang.Ast.StructMap.choose x_possible_structs in
Bindlib.box_apply (fun e -> (Scopelang.Ast.EStructAccess (e, f_uid, s_uid), pos)) e
| Some c_name -> (
try
let c_uid = Desugared.Ast.IdentMap.find (Pos.unmark c_name) ctxt.struct_idmap in
try
let f_uid = Scopelang.Ast.StructMap.find c_uid x_possible_structs in
Bindlib.box_apply
(fun e -> (Scopelang.Ast.EStructAccess (e, f_uid, c_uid), pos))
e
with Not_found ->
Errors.raise_spanned_error
(Format.asprintf "Struct %s does not contain field %s" (Pos.unmark c_name)
(Pos.unmark x))
pos
with Not_found ->
Errors.raise_spanned_error
(Format.asprintf "Struct %s has not been defined before" (Pos.unmark c_name))
(Pos.get_position c_name) ) ) )
| FunCall (f, arg) ->
Bindlib.box_apply2
(fun f arg -> (Scopelang.Ast.EApp (f, [ arg ]), pos))
@ -282,7 +322,7 @@ let rec translate_expr (scope : Scopelang.Ast.ScopeName.t) (ctxt : Name_resoluti
Bindlib.box_apply
(fun s_fields -> (Scopelang.Ast.EStruct (s_uid, s_fields), pos))
(LiftStructFieldMap.lift_box s_fields)
| EnumInject (constructor, payload) ->
| EnumInject (enum, constructor, payload) -> (
let possible_c_uids =
try Desugared.Ast.IdentMap.find (Pos.unmark constructor) ctxt.constructor_idmap
with Not_found ->
@ -290,30 +330,63 @@ let rec translate_expr (scope : Scopelang.Ast.ScopeName.t) (ctxt : Name_resoluti
"The name of this constructor has not been defined before, maybe it is a typo?"
(Pos.get_position constructor)
in
if Scopelang.Ast.EnumMap.cardinal possible_c_uids > 1 then
Errors.raise_spanned_error
(Format.asprintf
"This constuctor name is ambiguous, it can belong to %a. Desambiguate it by prefixing \
it with the enum name."
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt " or ")
(fun fmt (s_name, _) ->
Format.fprintf fmt "%a" Scopelang.Ast.EnumName.format_t s_name))
(Scopelang.Ast.EnumMap.bindings possible_c_uids))
(Pos.get_position constructor)
else
let e_uid, c_uid = Scopelang.Ast.EnumMap.choose possible_c_uids in
let payload = Option.map (translate_expr scope ctxt) payload in
Bindlib.box_apply
(fun payload ->
( Scopelang.Ast.EEnumInj
( ( match payload with
| Some e' -> e'
| None -> (Scopelang.Ast.ELit Dcalc.Ast.LUnit, Pos.get_position constructor) ),
c_uid,
e_uid ),
pos ))
(Bindlib.box_opt payload)
match enum with
| None ->
if
(* No constructor name was specified *)
Scopelang.Ast.EnumMap.cardinal possible_c_uids > 1
then
Errors.raise_spanned_error
(Format.asprintf
"This constructor name is ambiguous, it can belong to %a. Desambiguate it by \
prefixing it with the enum name."
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt " or ")
(fun fmt (s_name, _) ->
Format.fprintf fmt "%a" Scopelang.Ast.EnumName.format_t s_name))
(Scopelang.Ast.EnumMap.bindings possible_c_uids))
(Pos.get_position constructor)
else
let e_uid, c_uid = Scopelang.Ast.EnumMap.choose possible_c_uids in
let payload = Option.map (translate_expr scope ctxt) payload in
Bindlib.box_apply
(fun payload ->
( Scopelang.Ast.EEnumInj
( ( match payload with
| Some e' -> e'
| None -> (Scopelang.Ast.ELit Dcalc.Ast.LUnit, Pos.get_position constructor)
),
c_uid,
e_uid ),
pos ))
(Bindlib.box_opt payload)
| Some enum -> (
try
(* The path has been fully qualified *)
let e_uid = Desugared.Ast.IdentMap.find (Pos.unmark enum) ctxt.enum_idmap in
try
let c_uid = Scopelang.Ast.EnumMap.find e_uid possible_c_uids in
let payload = Option.map (translate_expr scope ctxt) payload in
Bindlib.box_apply
(fun payload ->
( Scopelang.Ast.EEnumInj
( ( match payload with
| Some e' -> e'
| None -> (Scopelang.Ast.ELit Dcalc.Ast.LUnit, Pos.get_position constructor)
),
c_uid,
e_uid ),
pos ))
(Bindlib.box_opt payload)
with Not_found ->
Errors.raise_spanned_error
(Format.asprintf "Enum %s does not contain case %s" (Pos.unmark enum)
(Pos.unmark constructor))
pos
with Not_found ->
Errors.raise_spanned_error
(Format.asprintf "Enum %s has not been defined before" (Pos.unmark enum))
(Pos.get_position enum) ) )
| MatchWith (e1, (cases, _cases_pos)) ->
let e1 = translate_expr scope ctxt e1 in
let cases_d, e_uid = disambiguate_match_and_build_expression scope ctxt cases in

File diff suppressed because it is too large Load Diff

View File

@ -19,11 +19,6 @@
%{
open Ast
open Utils
type struct_or_enum_inject_content =
| StructContent of (ident Pos.marked * expression Pos.marked) list
| EnumContent of expression Pos.marked option
%}
%token EOF
@ -112,8 +107,8 @@ small_expression:
| e = small_expression ARROW c = constructor {
(EnumProject (e, c), Pos.from_lpos $sloc)
}
| e = small_expression DOT i = ident {
(Dotted (e, i), Pos.from_lpos $sloc)
| e = small_expression DOT c = option(terminated(constructor,DOT)) i = ident {
(Dotted (e, c, i), Pos.from_lpos $sloc)
}
struct_content_field:
@ -124,18 +119,18 @@ struct_content_field:
enum_inject_content:
| CONTENT e = small_expression { e }
struct_or_enum_inject_content:
| e = option(enum_inject_content) { EnumContent e }
| LBRACKET ALT fields = separated_nonempty_list(ALT, struct_content_field) RBRACKET {
StructContent fields
}
struct_inject_content:
| LBRACKET ALT fields = separated_nonempty_list(ALT, struct_content_field) RBRACKET { fields }
struct_or_enum_inject:
| c = constructor data = struct_or_enum_inject_content {
match data with
| EnumContent data -> (EnumInject (c, data), Pos.from_lpos $sloc)
| StructContent fields -> (StructLit (c, fields), Pos.from_lpos $sloc)
| enum = constructor c = option(preceded(DOT, constructor)) data = option(enum_inject_content) {
(* The fully qualified enum is actually the optional part, but it leads to shift/reduce conflicts.
We flip it here *)
match c with
| None -> (EnumInject(None, enum, data), Pos.from_lpos $sloc)
| Some c -> (EnumInject(Some enum, c, data), Pos.from_lpos $sloc)
}
| c = constructor fields = struct_inject_content { (StructLit(c, fields), Pos.from_lpos $sloc) }
primitive_expression:
| e = small_expression { e }
@ -319,16 +314,23 @@ logical_expression:
(Binop (binop, e1, e2), Pos.from_lpos $sloc)
}
maybe_qualified_constructor:
| c_or_path = constructor c = option(preceded(DOT, constructor)) {
match c with
| None -> (None, c_or_path)
| Some c -> (Some c_or_path, c)
}
optional_binding:
| { ([], None)}
| OF i = ident {([], Some i)}
| OF c = constructor cs_and_i = constructor_binding {
| OF c = maybe_qualified_constructor cs_and_i = constructor_binding {
let (cs, i) = cs_and_i in
(c::cs, i)
}
constructor_binding:
| c = constructor cs_and_i = optional_binding {
| c = maybe_qualified_constructor cs_and_i = optional_binding {
let (cs, i) = cs_and_i in
(c::cs, i)
}

View File

@ -13,11 +13,11 @@ let message s =
"expected another inclusion of a Catala file, since this file is a master file which can \
only contain inclusions of other Catala files\n"
| 8 -> "expected some text, another heading or a law article\n"
| 369 -> "expected a heading, an article title or some text\n"
| 354 -> "expected an article title, another heading or some text\n"
| 359 -> "expected a code block, a metadata block, more law text or a heading\n"
| 365 -> "expected a code block, a metadata block, more law text or a heading\n"
| 360 -> "expected a declaration or a scope use\n"
| 377 -> "expected a heading, an article title or some text\n"
| 362 -> "expected an article title, another heading or some text\n"
| 367 -> "expected a code block, a metadata block, more law text or a heading\n"
| 373 -> "expected a code block, a metadata block, more law text or a heading\n"
| 368 -> "expected a declaration or a scope use\n"
| 22 -> "expected the name of the scope you want to use\n"
| 24 -> "expected a scope use precondition or a colon\n"
| 25 -> "expected an expression which will act as the condition\n"
@ -28,21 +28,21 @@ let message s =
| 31 -> "expected the third component of the date literal\n"
| 32 -> "expected a delimiter to finish the date literal\n"
| 70 -> "expected an operator to compose the expression on the left with\n"
| 110 -> "expected an enum constructor to test if the expression on the left\n"
| 109 -> "expected an operator to compose the expression on the left with\n"
| 142 -> "expected an expression on the right side of the sum or minus operator\n"
| 184 -> "expected an expression on the right side of the logical operator\n"
| 118 -> "expected an expression for the argument of this function call\n"
| 176 -> "expected an expression on the right side of the comparison operator\n"
| 151 -> "expected an expression on the right side of the multiplication or division operator\n"
| 144 -> "expected an operator to compose the expression on the left\n"
| 129 -> "expected an expression standing for the set you want to test for membership\n"
| 123 -> "expected an enum constructor to test if the expression on the left\n"
| 122 -> "expected an operator to compose the expression on the left with\n"
| 149 -> "expected an expression on the right side of the sum or minus operator\n"
| 191 -> "expected an expression on the right side of the logical operator\n"
| 125 -> "expected an expression for the argument of this function call\n"
| 183 -> "expected an expression on the right side of the comparison operator\n"
| 158 -> "expected an expression on the right side of the multiplication or division operator\n"
| 151 -> "expected an operator to compose the expression on the left\n"
| 136 -> "expected an expression standing for the set you want to test for membership\n"
| 71 -> "expected an identifier standing for a struct field or a subscope name\n"
| 236 -> "expected a colon after the scope use precondition\n"
| 73 -> "expected a constructor, to get the payload of this enum case\n"
| 244 -> "expected a colon after the scope use precondition\n"
| 76 -> "expected a constructor, to get the payload of this enum case\n"
| 35 -> "expected the \"for\" keyword to spell the aggregation\n"
| 178 -> "expected an expression to take the negation of\n"
| 107 -> "expected an expression to take the opposite of\n"
| 185 -> "expected an expression to take the negation of\n"
| 120 -> "expected an expression to take the opposite of\n"
| 51 -> "expected the type of the elements compared for the minimum\n"
| 52 -> "expected the \"initial\" keyword to introduce the minimum initial expression\n"
| 53 -> "expected the minimum initial expression\n"
@ -50,137 +50,130 @@ let message s =
| 56 -> "expected the \"initial\" keyword to introduce the maximum initial expression\n"
| 57 -> "expected the maximum initial expression\n"
| 59 -> "expected an expression to match with\n"
| 76 -> "expected a pattern matching case\n"
| 77 -> "expected the name of the constructor for the enum case in the pattern matching\n"
| 112 ->
| 79 -> "expected a pattern matching case\n"
| 80 -> "expected the name of the constructor for the enum case in the pattern matching\n"
| 85 ->
"expected a binding for the constructor payload, or a colon and the matching case expression\n"
| 113 -> "expected an identifier for this enum case binding\n"
| 80 -> "expected a colon and then the expression for this matching case\n"
| 115 -> "expected a colon or a binding for the enum constructor payload\n"
| 81 -> "expected an expression for this pattern matching case\n"
| 78 ->
"expected another match case or the rest of the expression since the previous match case is \
complete\n"
| 75 -> "expected the \"with patter\" keyword to complete the pattern matching expression\n"
| 121 -> "expected the \"for\" keyword to introduce the identifier for the map predicate\n"
| 122 -> "expected the identifier for the map predicate\n"
| 123 -> "expected the \"in\" keyword to introduce the collection argument to map\n"
| 124 -> "expected the collection argument to map\n"
| 125 -> "expected the \"of\" keyword to introduce the map predicate\n"
| 126 -> "expected an expression for the map predicate\n"
| 78 -> "expected the \"with patter\" keyword to complete the pattern matching expression\n"
| 128 -> "expected the \"for\" keyword to introduce the identifier for the map predicate\n"
| 129 -> "expected the identifier for the map predicate\n"
| 130 -> "expected the \"in\" keyword to introduce the collection argument to map\n"
| 131 -> "expected the collection argument to map\n"
| 132 -> "expected the \"of\" keyword to introduce the map predicate\n"
| 133 -> "expected an expression for the map predicate\n"
| 54 -> "expected a collection element\n"
| 230 -> "expected a semicolon or a right square bracket after the collection element \n"
| 231 -> "expected another element of the collection\n"
| 238 -> "expected a semicolon or a right square bracket after the collection element \n"
| 239 -> "expected another element of the collection\n"
| 58 -> "expected an expression inside the parenthesis\n"
| 224 -> "unmatched parenthesis that should have been closed by here\n"
| 89 -> "expected a unit for this literal, or a valid operator to complete the expression \n"
| 199 -> "expected an expression for the test of the conditional\n"
| 220 -> "expected an expression the for the \"then\" branch of the conditiona\n"
| 221 ->
| 232 -> "unmatched parenthesis that should have been closed by here\n"
| 102 -> "expected a unit for this literal, or a valid operator to complete the expression \n"
| 207 -> "expected an expression for the test of the conditional\n"
| 228 -> "expected an expression the for the \"then\" branch of the conditiona\n"
| 229 ->
"expected the \"else\" branch of this conditional expression as the \"then\" branch is \
complete\n"
| 222 -> "expected an expression for the \"else\" branch of this conditional construction\n"
| 219 -> "expected the \"then\" keyword as the conditional expression is complete\n"
| 200 ->
| 230 -> "expected an expression for the \"else\" branch of this conditional construction\n"
| 227 -> "expected the \"then\" keyword as the conditional expression is complete\n"
| 208 ->
"expected the \"all\" keyword to mean the \"for all\" construction of the universal test\n"
| 205 -> "expected an identifier for the bound variable of the universal test\n"
| 206 -> "expected the \"in\" keyword for the rest of the universal test\n"
| 207 -> "expected the expression designating the set on which to perform the universal test\n"
| 208 -> "expected the \"we have\" keyword for this universal test\n"
| 204 -> "expected an expression for the universal test\n"
| 213 -> "expected an identifier that will designate the existential witness for the test\n"
| 214 -> "expected the \"in\" keyword to continue this existential test\n"
| 215 -> "expected an expression that designates the set subject to the existential test\n"
| 216 -> "expected a keyword to form the \"such that\" expression for the existential test\n"
| 217 -> "expected a keyword to complete the \"such that\" construction\n"
| 211 -> "expected an expression for the existential test\n"
| 84 -> "this is the start of an arg-maximum or arg-minimum expression\n"
| 85 -> "expected the type of the elements compared to get the minimum\n"
| 86 -> "expected the \"initial\" keyword introducing the initial expression for the minimum\n"
| 87 -> "expected the initial expression for the minimum\n"
| 193 -> "expected the type of the elements compared to get the maximum\n"
| 194 -> "expected the \"initial\" keyword introducing the initial expression for the maximum\n"
| 195 -> "expected the initial expression for the maximum\n"
| 98 ->
| 213 -> "expected an identifier for the bound variable of the universal test\n"
| 214 -> "expected the \"in\" keyword for the rest of the universal test\n"
| 215 -> "expected the expression designating the set on which to perform the universal test\n"
| 216 -> "expected the \"we have\" keyword for this universal test\n"
| 212 -> "expected an expression for the universal test\n"
| 221 -> "expected an identifier that will designate the existential witness for the test\n"
| 222 -> "expected the \"in\" keyword to continue this existential test\n"
| 223 -> "expected an expression that designates the set subject to the existential test\n"
| 224 -> "expected a keyword to form the \"such that\" expression for the existential test\n"
| 225 -> "expected a keyword to complete the \"such that\" construction\n"
| 219 -> "expected an expression for the existential test\n"
| 97 -> "this is the start of an arg-maximum or arg-minimum expression\n"
| 98 -> "expected the type of the elements compared to get the minimum\n"
| 99 -> "expected the \"initial\" keyword introducing the initial expression for the minimum\n"
| 100 -> "expected the initial expression for the minimum\n"
| 201 -> "expected the type of the elements compared to get the maximum\n"
| 202 -> "expected the \"initial\" keyword introducing the initial expression for the maximum\n"
| 203 -> "expected the initial expression for the maximum\n"
| 111 ->
"expected a payload for the enum case constructor, or the rest of the expression (with an \
operator ?)\n"
| 99 -> "expected structure fields introduced by --\n"
| 100 -> "expected the name of the structure field\n"
| 104 -> "expected a colon\n"
| 105 -> "expected the expression for this struct field\n"
| 101 -> "expected another structure field or the closing bracket\n"
| 102 -> "expected the name of the structure field\n"
| 188 -> "expected an expression for the content of this enum case\n"
| 189 ->
| 112 -> "expected structure fields introduced by --\n"
| 113 -> "expected the name of the structure field\n"
| 117 -> "expected a colon\n"
| 118 -> "expected the expression for this struct field\n"
| 114 -> "expected another structure field or the closing bracket\n"
| 115 -> "expected the name of the structure field\n"
| 197 -> "expected an expression for the content of this enum case\n"
| 198 ->
"the expression for the content of the enum case is already well-formed, expected an \
operator to form a bigger expression\n"
| 106 -> "expected the keyword following cardinal to compute the number of elements in a set\n"
| 237 -> "expected a scope use item: a rule, definition or assertion\n"
| 273 -> "expected the name of the variable subject to the rule\n"
| 250 ->
| 119 -> "expected the keyword following cardinal to compute the number of elements in a set\n"
| 245 -> "expected a scope use item: a rule, definition or assertion\n"
| 281 -> "expected the name of the variable subject to the rule\n"
| 258 ->
"expected a condition or a consequence for this rule, or the rest of the variable qualified \
name\n"
| 280 -> "expected a condition or a consequence for this rule\n"
| 275 -> "expected filled or not filled for a rule consequence\n"
| 281 -> "expected the name of the parameter for this dependent variable \n"
| 274 -> "expected the expression of the rule\n"
| 278 -> "expected the filled keyword the this rule \n"
| 251 -> "expected a struct field or a sub-scope context item after the dot\n"
| 238 -> "expected the name of the label\n"
| 268 -> "expected a rule or a definition after the label declaration\n"
| 269 -> "expected the label to which the exception is referring back\n"
| 272 -> "expected a rule or a definition after the exception declaration\n"
| 285 -> "expected the name of the variable you want to define\n"
| 286 -> "expected the defined as keyword to introduce the definition of this variable\n"
| 288 -> "expected an expression for the consequence of this definition under condition\n"
| 287 ->
| 288 -> "expected a condition or a consequence for this rule\n"
| 283 -> "expected filled or not filled for a rule consequence\n"
| 289 -> "expected the name of the parameter for this dependent variable \n"
| 282 -> "expected the expression of the rule\n"
| 286 -> "expected the filled keyword the this rule \n"
| 259 -> "expected a struct field or a sub-scope context item after the dot\n"
| 246 -> "expected the name of the label\n"
| 276 -> "expected a rule or a definition after the label declaration\n"
| 277 -> "expected the label to which the exception is referring back\n"
| 280 -> "expected a rule or a definition after the exception declaration\n"
| 293 -> "expected the name of the variable you want to define\n"
| 294 -> "expected the defined as keyword to introduce the definition of this variable\n"
| 296 -> "expected an expression for the consequence of this definition under condition\n"
| 295 ->
"expected a expression for defining this function, introduced by the defined as keyword\n"
| 289 -> "expected an expression for the definition\n"
| 240 -> "expected an expression that shoud be asserted during execution\n"
| 241 -> "expecting the name of the varying variable\n"
| 244 -> "the variable varies with an expression that was expected here\n"
| 245 -> "expected an indication about the variation sense of the variable, or a new scope item\n"
| 243 -> "expected an indication about what this variable varies with\n"
| 253 -> "expected an expression for this condition\n"
| 263 -> "expected a consequence for this definition under condition\n"
| 259 -> "expected an expression for this definition under condition\n"
| 255 -> "expected the name of the variable that should be fixed\n"
| 256 -> "expected the legislative text by which the value of the variable is fixed\n"
| 257 -> "expected the legislative text by which the value of the variable is fixed\n"
| 266 -> "expected a new scope use item \n"
| 296 -> "expected the kind of the declaration (struct, scope or enum)\n"
| 297 -> "expected the struct name\n"
| 298 -> "expected a colon\n"
| 299 -> "expected struct data or condition\n"
| 300 -> "expected the name of this struct data \n"
| 301 -> "expected the type of this struct data, introduced by the content keyword\n"
| 302 -> "expected the type of this struct data\n"
| 316 -> "expected the name of this struct condition\n"
| 309 -> "expected a new struct data, or another declaration or scope use\n"
| 310 -> "expected the type of the parameter of this struct data function\n"
| 297 -> "expected an expression for the definition\n"
| 248 -> "expected an expression that shoud be asserted during execution\n"
| 249 -> "expecting the name of the varying variable\n"
| 252 -> "the variable varies with an expression that was expected here\n"
| 253 -> "expected an indication about the variation sense of the variable, or a new scope item\n"
| 251 -> "expected an indication about what this variable varies with\n"
| 261 -> "expected an expression for this condition\n"
| 271 -> "expected a consequence for this definition under condition\n"
| 267 -> "expected an expression for this definition under condition\n"
| 263 -> "expected the name of the variable that should be fixed\n"
| 264 -> "expected the legislative text by which the value of the variable is fixed\n"
| 265 -> "expected the legislative text by which the value of the variable is fixed\n"
| 274 -> "expected a new scope use item \n"
| 304 -> "expected the kind of the declaration (struct, scope or enum)\n"
| 305 -> "expected the struct name\n"
| 306 -> "expected a colon\n"
| 307 -> "expected struct data or condition\n"
| 308 -> "expected the name of this struct data \n"
| 309 -> "expected the type of this struct data, introduced by the content keyword\n"
| 310 -> "expected the type of this struct data\n"
| 324 -> "expected the name of this struct condition\n"
| 317 -> "expected a new struct data, or another declaration or scope use\n"
| 318 -> "expected the type of the parameter of this struct data function\n"
| 322 -> "expected a new struct data, or another declaration or scope use\n"
| 314 -> "expected a new struct data, or another declaration or scope use\n"
| 306 -> "expected a new struct data, or another declaration or scope use\n"
| 319 -> "expected the name of the scope you are declaring\n"
| 320 -> "expected a colon followed by the list of context items of this scope\n"
| 321 -> "expected a context item introduced by \"context\"\n"
| 322 -> "expected the name of this new context item\n"
| 323 -> "expected the kind of this context item: is it a condition, a sub-scope or a data?\n"
| 324 -> "expected the name of the subscope for this context item\n"
| 331 -> "expected another scope context item or the end of the scope declaration\n"
| 326 -> "expected the type of this context item\n"
| 327 -> "expected the next context item or a dependency declaration for this item\n"
| 329 -> "expected the next context item or a dependency declaration for this item\n"
| 334 -> "expected the name of your enum\n"
| 335 -> "expected a colon\n"
| 336 -> "expected an enum case\n"
| 337 -> "expected the name of an enum case \n"
| 338 -> "expected a payload for your enum case, or another case or declaration \n"
| 339 -> "expected a content type\n"
| 344 -> "expected another enum case, or a new declaration or scope use\n"
| 327 -> "expected the name of the scope you are declaring\n"
| 328 -> "expected a colon followed by the list of context items of this scope\n"
| 329 -> "expected a context item introduced by \"context\"\n"
| 330 -> "expected the name of this new context item\n"
| 331 -> "expected the kind of this context item: is it a condition, a sub-scope or a data?\n"
| 332 -> "expected the name of the subscope for this context item\n"
| 339 -> "expected another scope context item or the end of the scope declaration\n"
| 334 -> "expected the type of this context item\n"
| 335 -> "expected the next context item or a dependency declaration for this item\n"
| 337 -> "expected the next context item or a dependency declaration for this item\n"
| 342 -> "expected the name of your enum\n"
| 343 -> "expected a colon\n"
| 344 -> "expected an enum case\n"
| 345 -> "expected the name of an enum case \n"
| 346 -> "expected a payload for your enum case, or another case or declaration \n"
| 347 -> "expected a content type\n"
| 352 -> "expected another enum case, or a new declaration or scope use\n"
| 18 -> "expected a declaration or a scope use\n"
| 19 -> "expected some text or the beginning of a code section\n"
| 20 -> "expected a declaration or a scope use\n"
| 21 -> "should not happen\n"
| 350 -> "expected a metadata-closing tag\n"
| 351 -> "expected a metadata-closing tag\n"
| 358 -> "expected a metadata-closing tag\n"
| 359 -> "expected a metadata-closing tag\n"
| _ -> raise Not_found

View File

@ -0,0 +1,15 @@
@Article@
/*
new enum E:
-- Case1
new enum F:
-- Case1
new scope A:
param e content E
scope A:
def e := Case1
*/

View File

@ -0,0 +1,7 @@
[ERROR] This constructor name is ambiguous, it can belong to E or F. Desambiguate it by prefixing it with the enum name.
[ERROR]
[ERROR] --> test_enum/bad/ambiguous_cases.catala
[ERROR] |
[ERROR] 14 | def e := Case1
[ERROR] | ^^^^^
[ERROR] + Article

View File

@ -0,0 +1,22 @@
@Article@
/*
new enum E:
-- Case1
new enum F:
-- Case1 content int
-- Case2
new scope A:
param e content E
param f content F
param x content int
scope A:
def e := E.Case1
def f := F.Case1 content 2
def x := match f with
-- F.Case1 of i : i
-- Case2 : 3
*/

View File

@ -0,0 +1,4 @@
[RESULT] Computation successful! Results:
[RESULT] e = Case1 ()
[RESULT] f = Case1 2
[RESULT] x = 2

View File

@ -0,0 +1,18 @@
@Article@
/*
new struct Foo:
data f content int
new struct Bar:
data f content int
new scope A:
param x content Foo
param y content int
scope A:
def x := Foo { -- f: 1 }
def y := x.f
*/

View File

@ -0,0 +1,15 @@
@Article@
/*
new struct Foo:
data f content int
new scope A:
param x content Foo
param y content int
scope A:
def x := Foo { -- f: 1 }
def y := x.Fo.f
*/

View File

@ -0,0 +1,7 @@
[ERROR] This struct field name is ambiguous, it can belong to Foo or Bar. Disambiguate it by prefixing it with the struct name.
[ERROR]
[ERROR] --> test_struct/bad/ambiguous_fields.catala
[ERROR] |
[ERROR] 16 | def y := x.f
[ERROR] | ^
[ERROR] + Article

View File

@ -0,0 +1,7 @@
[ERROR] Struct Fo has not been defined before
[ERROR]
[ERROR] --> test_struct/bad/nonexisting_struct.catala
[ERROR] |
[ERROR] 13 | def y := x.Fo.f
[ERROR] | ^^
[ERROR] + Article

View File

@ -0,0 +1,7 @@
[ERROR] Struct Foo does not contain field g
[ERROR]
[ERROR] --> test_struct/bad/wrong_qualified_field.catala
[ERROR] |
[ERROR] 17 | def y := x.Foo.g
[ERROR] | ^^^^^^^
[ERROR] + Article

View File

@ -0,0 +1,19 @@
@Article@
/*
new struct Foo:
data f content int
new struct Bar:
data f content int
data g content int
new scope A:
param x content Foo
param y content int
scope A:
def x := Foo { -- f: 1 }
def y := x.Foo.g
*/

View File

@ -0,0 +1,3 @@
[RESULT] Computation successful! Results:
[RESULT] x = Foo {"f": 1}
[RESULT] y = 1

View File

@ -0,0 +1,18 @@
@Article@
/*
new struct Foo:
data f content int
new struct Bar:
data f content int
new scope A:
param x content Foo
param y content int
scope A:
def x := Foo { -- f: 1 }
def y := x.Foo.f
*/