Merge branch 'master' into visitors_and_positions

This commit is contained in:
Denis Merigoux 2021-01-21 21:10:22 +01:00
commit d486494177
18 changed files with 408 additions and 135 deletions

View File

@ -295,22 +295,42 @@ and expression =
name = "expression_iter";
}]
type exception_to = NotAnException | UnlabeledException | ExceptionToLabel of ident Pos.marked
[@@deriving
visitors
{ variety = "map"; ancestors = [ "ident_map"; "Pos.marked_map" ]; name = "exception_to_map" },
visitors
{
variety = "iter";
ancestors = [ "ident_iter"; "Pos.marked_iter" ];
name = "exception_to_iter";
}]
type rule = {
rule_label : ident Pos.marked option;
rule_exception_to : ident Pos.marked option;
rule_exception_to : exception_to;
rule_parameter : ident Pos.marked option;
rule_condition : expression Pos.marked option;
rule_name : qident Pos.marked;
rule_consequence : (bool[@opaque]) Pos.marked;
}
[@@deriving
visitors { variety = "map"; ancestors = [ "expression_map"; "qident_map" ]; name = "rule_map" },
visitors
{
variety = "map";
ancestors = [ "expression_map"; "qident_map"; "exception_to_map" ];
name = "rule_map";
},
visitors
{ variety = "iter"; ancestors = [ "expression_iter"; "qident_iter" ]; name = "rule_iter" }]
{
variety = "iter";
ancestors = [ "expression_iter"; "qident_iter"; "exception_to_iter" ];
name = "rule_iter";
}]
type definition = {
definition_label : ident Pos.marked option;
definition_exception_to : ident Pos.marked option;
definition_exception_to : exception_to;
definition_name : qident Pos.marked;
definition_parameter : ident Pos.marked option;
definition_condition : expression Pos.marked option;
@ -318,11 +338,15 @@ type definition = {
}
[@@deriving
visitors
{ variety = "map"; ancestors = [ "expression_map"; "qident_map" ]; name = "definition_map" },
{
variety = "map";
ancestors = [ "expression_map"; "qident_map"; "exception_to_map" ];
name = "definition_map";
},
visitors
{
variety = "iter";
ancestors = [ "expression_iter"; "qident_iter" ];
ancestors = [ "expression_iter"; "qident_iter"; "exception_to_iter" ];
name = "definition_iter";
}]

View File

@ -747,29 +747,33 @@ let process_default (ctxt : Name_resolution.context) (scope : Scopelang.Ast.Scop
exception_to_rule;
}
let get_def_key (def : Ast.definition) (scope_uid : Scopelang.Ast.ScopeName.t)
(ctxt : Name_resolution.context) : Desugared.Ast.ScopeDef.t =
let scope_ctxt = Scopelang.Ast.ScopeMap.find scope_uid ctxt.scopes in
match Pos.unmark def.definition_name with
| [ x ] ->
let x_uid = Name_resolution.get_var_uid scope_uid ctxt x in
Desugared.Ast.ScopeDef.Var x_uid
| [ y; x ] ->
let subscope_uid : Scopelang.Ast.SubScopeName.t =
Name_resolution.get_subscope_uid scope_uid ctxt y
in
let subscope_real_uid : Scopelang.Ast.ScopeName.t =
Scopelang.Ast.SubScopeMap.find subscope_uid scope_ctxt.sub_scopes
in
let x_uid = Name_resolution.get_var_uid subscope_real_uid ctxt x in
Desugared.Ast.ScopeDef.SubScopeVar (subscope_uid, x_uid)
| _ ->
Errors.raise_spanned_error "Structs are not handled yet"
(Pos.get_position def.definition_expr)
(** Wrapper around {!val: process_default} that performs some name disambiguation *)
let process_def (precond : Scopelang.Ast.expr Pos.marked Bindlib.box option)
(scope_uid : Scopelang.Ast.ScopeName.t) (ctxt : Name_resolution.context)
(prgm : Desugared.Ast.program) (def : Ast.definition) : Desugared.Ast.program =
let scope : Desugared.Ast.scope = Scopelang.Ast.ScopeMap.find scope_uid prgm.program_scopes in
let scope_ctxt = Scopelang.Ast.ScopeMap.find scope_uid ctxt.scopes in
let default_pos = Pos.get_position def.definition_expr in
let def_key =
match Pos.unmark def.definition_name with
| [ x ] ->
let x_uid = Name_resolution.get_var_uid scope_uid ctxt x in
Desugared.Ast.ScopeDef.Var x_uid
| [ y; x ] ->
let subscope_uid : Scopelang.Ast.SubScopeName.t =
Name_resolution.get_subscope_uid scope_uid ctxt y
in
let subscope_real_uid : Scopelang.Ast.ScopeName.t =
Scopelang.Ast.SubScopeMap.find subscope_uid scope_ctxt.sub_scopes
in
let x_uid = Name_resolution.get_var_uid subscope_real_uid ctxt x in
Desugared.Ast.ScopeDef.SubScopeVar (subscope_uid, x_uid)
| _ -> Errors.raise_spanned_error "Structs are not handled yet" default_pos
in
let def_key = get_def_key def scope_uid ctxt in
(* We add to the name resolution context the name of the parameter variable *)
let param_uid, new_ctxt =
match def.definition_parameter with
@ -804,10 +808,31 @@ let process_def (precond : Scopelang.Ast.expr Pos.marked Bindlib.box option)
def.definition_name
| Some label -> label )
in
let is_exception (def : Ast.definition) =
match def.Ast.definition_exception_to with NotAnException -> false | _ -> true
in
(* If we had previously defined a rulename for this default definition during the elaboration of
default exceptions, this trumps the newly generated name. *)
let rule_name =
if is_exception def then rule_name
else
match Desugared.Ast.ScopeDefMap.find_opt def_key scope_ctxt.default_rulemap with
| None -> rule_name
| Some x -> x
in
let parent_rule =
match def.Ast.definition_exception_to with
| None -> None
| Some label ->
| NotAnException -> None
| UnlabeledException ->
Some
( try
Pos.same_pos_as
(Desugared.Ast.ScopeDefMap.find def_key scope_ctxt.default_rulemap)
def.Ast.definition_name
with Not_found ->
Errors.raise_spanned_error "No definition associated to this exception"
(Pos.get_position def.Ast.definition_name) )
| ExceptionToLabel label ->
Some
( try
Pos.same_pos_as
@ -835,21 +860,23 @@ let process_def (precond : Scopelang.Ast.expr Pos.marked Bindlib.box option)
program_scopes = Scopelang.Ast.ScopeMap.add scope_uid scope_updated prgm.program_scopes;
}
(** Translates a {!type: Surface.Ast.rule} into the corresponding {!type: Surface.Ast.definition} *)
let rule_to_def (rule : Ast.rule) : Ast.definition =
let consequence_expr = Ast.Literal (Ast.LBool (Pos.unmark rule.rule_consequence)) in
{
Ast.definition_label = rule.rule_label;
Ast.definition_exception_to = rule.rule_exception_to;
Ast.definition_name = rule.rule_name;
Ast.definition_parameter = rule.rule_parameter;
Ast.definition_condition = rule.rule_condition;
Ast.definition_expr = (consequence_expr, Pos.get_position rule.rule_consequence);
}
(** Translates a {!type: Surface.Ast.rule} from the surface language *)
let process_rule (precond : Scopelang.Ast.expr Pos.marked Bindlib.box option)
(scope : Scopelang.Ast.ScopeName.t) (ctxt : Name_resolution.context)
(prgm : Desugared.Ast.program) (rule : Ast.rule) : Desugared.Ast.program =
let consequence_expr = Ast.Literal (Ast.LBool (Pos.unmark rule.rule_consequence)) in
let def =
{
Ast.definition_label = rule.rule_label;
Ast.definition_exception_to = rule.rule_exception_to;
Ast.definition_name = rule.rule_name;
Ast.definition_parameter = rule.rule_parameter;
Ast.definition_condition = rule.rule_condition;
Ast.definition_expr = (consequence_expr, Pos.get_position rule.rule_consequence);
}
in
let def = rule_to_def rule in
process_def precond scope ctxt prgm def
(** Translates assertions *)
@ -893,6 +920,83 @@ let process_scope_use_item (precond : Ast.expression Pos.marked option)
(** {1 Translating top-level items} *)
(* Collects the scope definition in the set if it is an unlabeled exception *)
let gather_unnamed_exceptions (scope : Scopelang.Ast.ScopeName.t) (ctxt : Name_resolution.context)
(defset : Desugared.Ast.ScopeDefSet.t) (item : Ast.scope_use_item Pos.marked) :
Desugared.Ast.ScopeDefSet.t =
match Pos.unmark item with
| Ast.Rule rule -> (
match rule.Ast.rule_exception_to with
| UnlabeledException ->
let def = rule_to_def rule in
let scope_def = get_def_key def scope ctxt in
Desugared.Ast.ScopeDefSet.add scope_def defset
| _ -> defset )
| Ast.Definition def -> (
match def.Ast.definition_exception_to with
| UnlabeledException ->
let scope_def = get_def_key def scope ctxt in
Desugared.Ast.ScopeDefSet.add scope_def defset
| _ -> defset )
| _ -> defset
let generate_default_rulenames (scope : Scopelang.Ast.ScopeName.t) (ctxt : Name_resolution.context)
(defset : Desugared.Ast.ScopeDefSet.t)
(rulemap : Desugared.Ast.RuleName.t Desugared.Ast.ScopeDefMap.t)
(item : Ast.scope_use_item Pos.marked) : Desugared.Ast.RuleName.t Desugared.Ast.ScopeDefMap.t =
let is_exception (def : Ast.definition) =
match def.Ast.definition_exception_to with NotAnException -> false | _ -> true
in
match Pos.unmark item with
| Ast.Rule rule ->
let def = rule_to_def rule in
let scope_def = get_def_key def scope ctxt in
if Desugared.Ast.ScopeDefSet.mem scope_def defset && not (is_exception def) then
(* This is a non-exception definition corresponding to an unnamed exception *)
match def.Ast.definition_label with
| Some label ->
Errors.raise_spanned_error
"This definition has a label, but an unlabeled exception refers to it"
(Pos.get_position label)
| None -> (
match Desugared.Ast.ScopeDefMap.find_opt scope_def rulemap with
| Some _ ->
(* There is already a default definition for this, we raise an error *)
Errors.raise_spanned_error
"An unlabeled exception refers to several definitions, including this one. \
Disambiguate by using labels."
(Pos.get_position def.Ast.definition_name)
| None ->
let fresh_name =
Desugared.Ast.RuleName.fresh (Pos.same_pos_as "dummy" def.Ast.definition_name)
in
Desugared.Ast.ScopeDefMap.add scope_def fresh_name rulemap )
else rulemap
| Ast.Definition def ->
let scope_def = get_def_key def scope ctxt in
if Desugared.Ast.ScopeDefSet.mem scope_def defset && not (is_exception def) then
(* This is a non-exception definition corresponding to an unnamed exception *)
match def.Ast.definition_label with
| Some label ->
Errors.raise_spanned_error
"This definition has a label, but an unlabeled exception refers to it"
(Pos.get_position label)
| None -> (
match Desugared.Ast.ScopeDefMap.find_opt scope_def rulemap with
| Some _ ->
(* There is already a default definition for this, we raise an error *)
Errors.raise_spanned_error
"An unlabeled exception refers to several definitions, including this one. \
Disambiguate by using labels."
(Pos.get_position def.Ast.definition_name)
| None ->
let fresh_name =
Desugared.Ast.RuleName.fresh (Pos.same_pos_as "dummy" def.Ast.definition_name)
in
Desugared.Ast.ScopeDefMap.add scope_def fresh_name rulemap )
else rulemap
| _ -> rulemap
(** Translates a surface scope use, which is a bunch of definitions *)
let process_scope_use (ctxt : Name_resolution.context) (prgm : Desugared.Ast.program)
(use : Ast.scope_use) : Desugared.Ast.program =
@ -906,6 +1010,24 @@ let process_scope_use (ctxt : Name_resolution.context) (prgm : Desugared.Ast.pro
(* should not happen *)
in
let precond = use.scope_use_condition in
let defset =
List.fold_left
(gather_unnamed_exceptions scope_uid ctxt)
Desugared.Ast.ScopeDefSet.empty use.scope_use_items
in
let scope_ctxt = Scopelang.Ast.ScopeMap.find scope_uid ctxt.scopes in
let new_scope_ctxt =
{
scope_ctxt with
default_rulemap =
List.fold_left
(generate_default_rulenames scope_uid ctxt defset)
scope_ctxt.default_rulemap use.scope_use_items;
}
in
let ctxt =
{ ctxt with scopes = Scopelang.Ast.ScopeMap.add scope_uid new_scope_ctxt ctxt.scopes }
in
List.fold_left (process_scope_use_item precond scope_uid ctxt) prgm use.scope_use_items
(** Main function of this module *)

View File

@ -27,6 +27,8 @@ type typ = Scopelang.Ast.typ
type scope_context = {
var_idmap : Scopelang.Ast.ScopeVar.t Desugared.Ast.IdentMap.t; (** Scope variables *)
label_idmap : Desugared.Ast.RuleName.t Desugared.Ast.IdentMap.t;
default_rulemap : Desugared.Ast.RuleName.t Desugared.Ast.ScopeDefMap.t;
(** What is the default rule to refer to for unnamed exceptions, if any *)
sub_scopes_idmap : Scopelang.Ast.SubScopeName.t Desugared.Ast.IdentMap.t;
(** Sub-scopes variables *)
sub_scopes : Scopelang.Ast.ScopeName.t Scopelang.Ast.SubScopeMap.t;
@ -283,6 +285,7 @@ let process_scope_decl (ctxt : context) (decl : Ast.scope_decl) : context =
{
var_idmap = Desugared.Ast.IdentMap.empty;
label_idmap = Desugared.Ast.IdentMap.empty;
default_rulemap = Desugared.Ast.ScopeDefMap.empty;
sub_scopes_idmap = Desugared.Ast.IdentMap.empty;
sub_scopes = Scopelang.Ast.SubScopeMap.empty;
}

View File

@ -1,6 +1,6 @@
source_file_or_master: BEGIN_METADATA BEGIN_CODE END_CODE LAW_TEXT END_CODE
##
## Ends in an error in state: 350.
## Ends in an error in state: 351.
##
## metadata_block -> BEGIN_CODE option(law_text) code END_CODE option(law_text) . END_METADATA [ LAW_TEXT LAW_INCLUDE LAW_HEADING LAW_ARTICLE EOF BEGIN_METADATA ]
##
@ -12,7 +12,7 @@ expected a metadata-closing tag
source_file_or_master: BEGIN_METADATA BEGIN_CODE END_CODE YEAR
##
## Ends in an error in state: 349.
## Ends in an error in state: 350.
##
## metadata_block -> BEGIN_CODE option(law_text) code END_CODE . option(law_text) END_METADATA [ LAW_TEXT LAW_INCLUDE LAW_HEADING LAW_ARTICLE EOF BEGIN_METADATA ]
##
@ -72,7 +72,7 @@ expected a declaration or a scope use
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON ALT CONSTRUCTOR CONTENT TEXT YEAR
##
## Ends in an error in state: 343.
## Ends in an error in state: 344.
##
## 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 ]
@ -85,7 +85,7 @@ expected another enum case, or a new declaration or scope use
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON ALT CONSTRUCTOR CONTENT YEAR
##
## Ends in an error in state: 338.
## Ends in an error in state: 339.
##
## enum_decl_line_payload -> CONTENT . typ [ SCOPE END_CODE DECLARATION ALT ]
##
@ -97,7 +97,7 @@ expected a content type
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON ALT CONSTRUCTOR YEAR
##
## Ends in an error in state: 337.
## Ends in an error in state: 338.
##
## enum_decl_line -> ALT constructor . option(enum_decl_line_payload) [ SCOPE END_CODE DECLARATION ALT ]
##
@ -109,7 +109,7 @@ expected a payload for your enum case, or another case or declaration
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON ALT YEAR
##
## Ends in an error in state: 336.
## Ends in an error in state: 337.
##
## enum_decl_line -> ALT . constructor option(enum_decl_line_payload) [ SCOPE END_CODE DECLARATION ALT ]
##
@ -121,7 +121,7 @@ expected the name of an enum case
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION ENUM CONSTRUCTOR COLON YEAR
##
## Ends in an error in state: 335.
## Ends in an error in state: 336.
##
## code_item -> DECLARATION ENUM constructor COLON . nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
##
@ -133,7 +133,7 @@ expected an enum case
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION ENUM CONSTRUCTOR YEAR
##
## Ends in an error in state: 334.
## Ends in an error in state: 335.
##
## code_item -> DECLARATION ENUM constructor . COLON nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
##
@ -145,7 +145,7 @@ expected a colon
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION ENUM YEAR
##
## Ends in an error in state: 333.
## Ends in an error in state: 334.
##
## code_item -> DECLARATION ENUM . constructor COLON nonempty_list(enum_decl_line) [ SCOPE END_CODE DECLARATION ]
##
@ -157,7 +157,7 @@ expected the name of your enum
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT IDENT CONDITION YEAR
##
## Ends in an error in state: 328.
## Ends in an error in state: 329.
##
## scope_decl_item -> CONTEXT ident CONDITION . option(struct_scope_func) [ SCOPE END_CODE DECLARATION CONTEXT ]
##
@ -169,7 +169,7 @@ expected the next context item or a dependency declaration for this item
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT IDENT CONTENT TEXT YEAR
##
## Ends in an error in state: 326.
## Ends in an error in state: 327.
##
## scope_decl_item -> CONTEXT ident CONTENT typ . option(struct_scope_func) [ SCOPE END_CODE DECLARATION CONTEXT ]
##
@ -181,7 +181,7 @@ expected the next context item or a dependency declaration for this item
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT IDENT CONTENT YEAR
##
## Ends in an error in state: 325.
## Ends in an error in state: 326.
##
## scope_decl_item -> CONTEXT ident CONTENT . typ option(struct_scope_func) [ SCOPE END_CODE DECLARATION CONTEXT ]
##
@ -193,7 +193,7 @@ expected the type of this context item
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT IDENT SCOPE CONSTRUCTOR YEAR
##
## Ends in an error in state: 330.
## Ends in an error in state: 331.
##
## 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 ]
@ -206,7 +206,7 @@ expected another scope context item or the end of the scope declaration
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT IDENT SCOPE YEAR
##
## Ends in an error in state: 323.
## Ends in an error in state: 324.
##
## scope_decl_item -> CONTEXT ident SCOPE . constructor [ SCOPE END_CODE DECLARATION CONTEXT ]
##
@ -218,7 +218,7 @@ expected the name of the subscope for this context item
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT IDENT YEAR
##
## Ends in an error in state: 322.
## Ends in an error in state: 323.
##
## scope_decl_item -> CONTEXT ident . CONTENT typ option(struct_scope_func) [ SCOPE END_CODE DECLARATION CONTEXT ]
## scope_decl_item -> CONTEXT ident . SCOPE constructor [ SCOPE END_CODE DECLARATION CONTEXT ]
@ -232,7 +232,7 @@ expected the kind of this context item: is it a condition, a sub-scope or a data
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON CONTEXT YEAR
##
## Ends in an error in state: 321.
## Ends in an error in state: 322.
##
## scope_decl_item -> CONTEXT . ident CONTENT typ option(struct_scope_func) [ SCOPE END_CODE DECLARATION CONTEXT ]
## scope_decl_item -> CONTEXT . ident SCOPE constructor [ SCOPE END_CODE DECLARATION CONTEXT ]
@ -246,7 +246,7 @@ expected the name of this new context item
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR COLON YEAR
##
## Ends in an error in state: 320.
## Ends in an error in state: 321.
##
## code_item -> DECLARATION SCOPE constructor COLON . nonempty_list(scope_decl_item) [ SCOPE END_CODE DECLARATION ]
##
@ -258,7 +258,7 @@ expected a context item introduced by "context"
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION SCOPE CONSTRUCTOR YEAR
##
## Ends in an error in state: 319.
## Ends in an error in state: 320.
##
## code_item -> DECLARATION SCOPE constructor . COLON nonempty_list(scope_decl_item) [ SCOPE END_CODE DECLARATION ]
##
@ -270,7 +270,7 @@ expected a colon followed by the list of context items of this scope
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION SCOPE YEAR
##
## Ends in an error in state: 318.
## Ends in an error in state: 319.
##
## code_item -> DECLARATION SCOPE . constructor COLON nonempty_list(scope_decl_item) [ SCOPE END_CODE DECLARATION ]
##
@ -282,7 +282,7 @@ expected the name of the scope you are declaring
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION IDENT DEPENDS COLLECTION YEAR
##
## Ends in an error in state: 305.
## Ends in an error in state: 306.
##
## typ -> collection_marked . typ [ SCOPE END_CODE DEPENDS DECLARATION DATA CONTEXT CONDITION ALT ]
##
@ -295,7 +295,7 @@ expected a new struct data, or another declaration or scope use
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION IDENT DEPENDS TEXT YEAR
##
## Ends in an error in state: 313.
## Ends in an error in state: 314.
##
## list(struct_scope) -> struct_scope . list(struct_scope) [ SCOPE END_CODE DECLARATION ]
##
@ -307,7 +307,7 @@ expected a new struct data, or another declaration or scope use
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION IDENT DEPENDS YEAR
##
## Ends in an error in state: 309.
## Ends in an error in state: 310.
##
## struct_scope_func -> DEPENDS . typ [ SCOPE END_CODE DECLARATION DATA CONTEXT CONDITION ]
##
@ -319,7 +319,7 @@ expected the type of the parameter of this struct data function
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION IDENT YEAR
##
## Ends in an error in state: 308.
## Ends in an error in state: 309.
##
## struct_scope -> struct_scope_base . option(struct_scope_func) [ SCOPE END_CODE DECLARATION DATA CONDITION ]
##
@ -331,7 +331,7 @@ expected a new struct data, or another declaration or scope use
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON CONDITION YEAR
##
## Ends in an error in state: 315.
## Ends in an error in state: 316.
##
## struct_scope_base -> condition_pos . ident [ SCOPE END_CODE DEPENDS DECLARATION DATA CONDITION ]
##
@ -343,7 +343,7 @@ expected the name of this struct condition
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON DATA IDENT CONTENT YEAR
##
## Ends in an error in state: 301.
## Ends in an error in state: 302.
##
## struct_scope_base -> DATA ident CONTENT . typ [ SCOPE END_CODE DEPENDS DECLARATION DATA CONDITION ]
##
@ -355,7 +355,7 @@ expected the type of this struct data
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON DATA IDENT YEAR
##
## Ends in an error in state: 300.
## Ends in an error in state: 301.
##
## struct_scope_base -> DATA ident . CONTENT typ [ SCOPE END_CODE DEPENDS DECLARATION DATA CONDITION ]
##
@ -367,7 +367,7 @@ expected the type of this struct data, introduced by the content keyword
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON DATA YEAR
##
## Ends in an error in state: 299.
## Ends in an error in state: 300.
##
## struct_scope_base -> DATA . ident CONTENT typ [ SCOPE END_CODE DEPENDS DECLARATION DATA CONDITION ]
##
@ -379,7 +379,7 @@ expected the name of this struct data
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR COLON YEAR
##
## Ends in an error in state: 298.
## Ends in an error in state: 299.
##
## code_item -> DECLARATION STRUCT constructor COLON . list(struct_scope) [ SCOPE END_CODE DECLARATION ]
##
@ -391,7 +391,7 @@ expected struct data or condition
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION STRUCT CONSTRUCTOR YEAR
##
## Ends in an error in state: 297.
## Ends in an error in state: 298.
##
## code_item -> DECLARATION STRUCT constructor . COLON list(struct_scope) [ SCOPE END_CODE DECLARATION ]
##
@ -403,7 +403,7 @@ expected a colon
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION STRUCT YEAR
##
## Ends in an error in state: 296.
## Ends in an error in state: 297.
##
## code_item -> DECLARATION STRUCT . constructor COLON list(struct_scope) [ SCOPE END_CODE DECLARATION ]
##
@ -415,7 +415,7 @@ expected the struct name
source_file_or_master: LAW_ARTICLE BEGIN_CODE DECLARATION YEAR
##
## Ends in an error in state: 295.
## Ends in an error in state: 296.
##
## 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 ]
@ -623,7 +623,7 @@ expected an expression that shoud be asserted during execution
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON DEFINITION IDENT DEFINED_AS YEAR
##
## Ends in an error in state: 288.
## Ends in an error in state: 289.
##
## definition -> option(label) option(exception_to) DEFINITION qident option(definition_parameters) option(condition_consequence) DEFINED_AS . expression [ SCOPE RULE LABEL EXCEPTION END_CODE DEFINITION DECLARATION ASSERTION ]
##
@ -635,7 +635,7 @@ expected an expression for the definition
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON DEFINITION IDENT OF IDENT DECREASING
##
## Ends in an error in state: 286.
## Ends in an error in state: 287.
##
## definition -> option(label) option(exception_to) DEFINITION qident option(definition_parameters) . option(condition_consequence) DEFINED_AS expression [ SCOPE RULE LABEL EXCEPTION END_CODE DEFINITION DECLARATION ASSERTION ]
##
@ -647,7 +647,7 @@ expected a expression for defining this function, introduced by the defined as k
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON DEFINITION IDENT UNDER_CONDITION CARDINAL CONSEQUENCE DECREASING
##
## Ends in an error in state: 287.
## Ends in an error in state: 288.
##
## definition -> option(label) option(exception_to) DEFINITION qident option(definition_parameters) option(condition_consequence) . DEFINED_AS expression [ SCOPE RULE LABEL EXCEPTION END_CODE DEFINITION DECLARATION ASSERTION ]
##
@ -659,7 +659,7 @@ expected an expression for the consequence of this definition under condition
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON DEFINITION IDENT WITH_V
##
## Ends in an error in state: 285.
## Ends in an error in state: 286.
##
## definition -> option(label) option(exception_to) DEFINITION qident . option(definition_parameters) option(condition_consequence) DEFINED_AS expression [ SCOPE RULE LABEL EXCEPTION END_CODE DEFINITION DECLARATION ASSERTION ]
##
@ -678,7 +678,7 @@ expected the defined as keyword to introduce the definition of this variable
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON DEFINITION YEAR
##
## Ends in an error in state: 284.
## Ends in an error in state: 285.
##
## definition -> option(label) option(exception_to) DEFINITION . qident option(definition_parameters) option(condition_consequence) DEFINED_AS expression [ SCOPE RULE LABEL EXCEPTION END_CODE DEFINITION DECLARATION ASSERTION ]
##
@ -690,7 +690,7 @@ expected the name of the variable you want to define
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON EXCEPTION IDENT DEFINED_AS
##
## Ends in an error in state: 271.
## Ends in an error in state: 272.
##
## definition -> option(label) option(exception_to) . DEFINITION qident option(definition_parameters) option(condition_consequence) DEFINED_AS expression [ SCOPE RULE LABEL EXCEPTION END_CODE DEFINITION DECLARATION ASSERTION ]
## rule -> option(label) option(exception_to) . RULE rule_expr option(condition_consequence) rule_consequence [ SCOPE RULE LABEL EXCEPTION END_CODE DEFINITION DECLARATION ASSERTION ]
@ -705,7 +705,7 @@ source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON EXCEPTION
##
## Ends in an error in state: 269.
##
## exception_to -> EXCEPTION . ident [ RULE DEFINITION ]
## exception_to -> EXCEPTION . option(ident) [ RULE DEFINITION ]
##
## The known suffix of the stack is as follows:
## EXCEPTION
@ -752,7 +752,7 @@ expected a struct field or a sub-scope context item after the dot
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON RULE IDENT NOT FALSE
##
## Ends in an error in state: 277.
## Ends in an error in state: 278.
##
## rule_consequence -> option(NOT) . FILLED [ SCOPE RULE LABEL EXCEPTION END_CODE DEFINITION DECLARATION ASSERTION ]
##
@ -764,7 +764,7 @@ expected the filled keyword the this rule
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON RULE IDENT OF IDENT YEAR
##
## Ends in an error in state: 273.
## Ends in an error in state: 274.
##
## rule -> option(label) option(exception_to) RULE rule_expr . option(condition_consequence) rule_consequence [ SCOPE RULE LABEL EXCEPTION END_CODE DEFINITION DECLARATION ASSERTION ]
##
@ -776,7 +776,7 @@ expected the expression of the rule
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON RULE IDENT OF YEAR
##
## Ends in an error in state: 280.
## Ends in an error in state: 281.
##
## definition_parameters -> OF . ident [ UNDER_CONDITION NOT FILLED DEFINED_AS ]
##
@ -788,7 +788,7 @@ expected the name of the parameter for this dependent variable
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON RULE IDENT UNDER_CONDITION CARDINAL CONSEQUENCE FALSE
##
## Ends in an error in state: 274.
## Ends in an error in state: 275.
##
## rule -> option(label) option(exception_to) RULE rule_expr option(condition_consequence) . rule_consequence [ SCOPE RULE LABEL EXCEPTION END_CODE DEFINITION DECLARATION ASSERTION ]
##
@ -800,7 +800,7 @@ expected filled or not filled for a rule consequence
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON RULE IDENT WITH_V
##
## Ends in an error in state: 279.
## Ends in an error in state: 280.
##
## rule_expr -> qident . option(definition_parameters) [ UNDER_CONDITION NOT FILLED ]
##
@ -832,7 +832,7 @@ expected a condition or a consequence for this rule, or the rest of the variable
source_file_or_master: LAW_ARTICLE BEGIN_CODE SCOPE CONSTRUCTOR COLON RULE YEAR
##
## Ends in an error in state: 272.
## Ends in an error in state: 273.
##
## rule -> option(label) option(exception_to) RULE . rule_expr option(condition_consequence) rule_consequence [ SCOPE RULE LABEL EXCEPTION END_CODE DEFINITION DECLARATION ASSERTION ]
##
@ -2042,7 +2042,7 @@ expected the name of the scope you want to use
source_file_or_master: LAW_ARTICLE BEGIN_CODE YEAR
##
## Ends in an error in state: 359.
## Ends in an error in state: 360.
##
## law_article_item -> BEGIN_CODE . code END_CODE [ LAW_TEXT LAW_INCLUDE LAW_HEADING LAW_ARTICLE EOF BEGIN_METADATA BEGIN_CODE ]
##
@ -2054,7 +2054,7 @@ expected a declaration or a scope use
source_file_or_master: LAW_ARTICLE LAW_TEXT YEAR
##
## Ends in an error in state: 364.
## Ends in an error in state: 365.
##
## law_articles_items -> law_article_item . law_articles_items [ LAW_INCLUDE LAW_HEADING LAW_ARTICLE EOF BEGIN_METADATA ]
##
@ -2066,7 +2066,7 @@ expected a code block, a metadata block, more law text or a heading
source_file_or_master: LAW_ARTICLE YEAR
##
## Ends in an error in state: 358.
## Ends in an error in state: 359.
##
## source_file_article -> law_article . law_articles_items [ LAW_INCLUDE LAW_HEADING LAW_ARTICLE EOF BEGIN_METADATA ]
##
@ -2078,7 +2078,7 @@ expected a code block, a metadata block, more law text or a heading
source_file_or_master: LAW_INCLUDE YEAR
##
## Ends in an error in state: 353.
## Ends in an error in state: 354.
##
## source_file_after_text -> source_file_item . list(law_intermediate_text) source_file_after_text [ # ]
##
@ -2090,7 +2090,7 @@ expected an article title, another heading or some text
source_file_or_master: LAW_TEXT YEAR
##
## Ends in an error in state: 368.
## Ends in an error in state: 369.
##
## list(law_intermediate_text) -> law_intermediate_text . list(law_intermediate_text) [ LAW_INCLUDE LAW_HEADING LAW_ARTICLE EOF BEGIN_METADATA ]
##

View File

@ -405,9 +405,10 @@ rule:
consequence = rule_consequence {
let (name, param_applied) = name_and_param in
let cons : bool Pos.marked = consequence in
let rule_exception = match except with | None -> NotAnException | Some x -> x in
({
rule_label = label;
rule_exception_to = except;
rule_exception_to = rule_exception;
rule_parameter = param_applied;
rule_condition = cond;
rule_name = name;
@ -422,7 +423,8 @@ label:
| LABEL i = ident { i }
exception_to:
| EXCEPTION i = ident { i }
| EXCEPTION i = option(ident) {
match i with | None -> UnlabeledException | Some x -> ExceptionToLabel x }
definition:
| label = option(label)
@ -430,9 +432,10 @@ definition:
DEFINITION
name = qident param = option(definition_parameters)
cond = option(condition_consequence) DEFINED_AS e = expression {
let def_exception = match except with | None -> NotAnException | Some x -> x in
({
definition_label = label;
definition_exception_to = except;
definition_exception_to = def_exception;
definition_name = name;
definition_parameter = param;
definition_condition = cond;

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"
| 368 -> "expected a heading, an article title or some text\n"
| 353 -> "expected an article title, another heading or some text\n"
| 358 -> "expected a code block, a metadata block, more law text or a heading\n"
| 364 -> "expected a code block, a metadata block, more law text or a heading\n"
| 359 -> "expected a declaration or a scope use\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"
| 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"
@ -116,26 +116,26 @@ let message s =
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"
| 272 -> "expected the name of the variable subject to the rule\n"
| 273 -> "expected the name of the variable subject to the rule\n"
| 250 ->
"expected a condition or a consequence for this rule, or the rest of the variable qualified \
name\n"
| 279 -> "expected a condition or a consequence for this rule\n"
| 274 -> "expected filled or not filled for a rule consequence\n"
| 280 -> "expected the name of the parameter for this dependent variable \n"
| 273 -> "expected the expression of the rule\n"
| 277 -> "expected the filled keyword the this rule \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"
| 271 -> "expected a rule or a definition after the exception declaration\n"
| 284 -> "expected the name of the variable you want to define\n"
| 285 -> "expected the defined as keyword to introduce the definition of this variable\n"
| 287 -> "expected an expression for the consequence of this definition under condition\n"
| 286 ->
| 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 ->
"expected a expression for defining this function, introduced by the defined as keyword\n"
| 288 -> "expected an expression for the definition\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"
@ -148,39 +148,39 @@ let message s =
| 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"
| 295 -> "expected the kind of the declaration (struct, scope or enum)\n"
| 296 -> "expected the struct name\n"
| 297 -> "expected a colon\n"
| 298 -> "expected struct data or condition\n"
| 299 -> "expected the name of this struct data \n"
| 300 -> "expected the type of this struct data, introduced by the content keyword\n"
| 301 -> "expected the type of this struct data\n"
| 315 -> "expected the name of this struct condition\n"
| 308 -> "expected a new struct data, or another declaration or scope use\n"
| 309 -> "expected the type of the parameter of this struct data function\n"
| 313 -> "expected a new struct data, or another declaration or scope use\n"
| 305 -> "expected a new struct data, or another declaration or scope use\n"
| 318 -> "expected the name of the scope you are declaring\n"
| 319 -> "expected a colon followed by the list of context items of this scope\n"
| 320 -> "expected a context item introduced by \"context\"\n"
| 321 -> "expected the name of this new context item\n"
| 322 -> "expected the kind of this context item: is it a condition, a sub-scope or a data?\n"
| 323 -> "expected the name of the subscope for this context item\n"
| 330 -> "expected another scope context item or the end of the scope declaration\n"
| 325 -> "expected the type of this context item\n"
| 326 -> "expected the next context item or a dependency declaration for this item\n"
| 328 -> "expected the next context item or a dependency declaration for this item\n"
| 333 -> "expected the name of your enum\n"
| 334 -> "expected a colon\n"
| 335 -> "expected an enum case\n"
| 336 -> "expected the name of an enum case \n"
| 337 -> "expected a payload for your enum case, or another case or declaration \n"
| 338 -> "expected a content type\n"
| 343 -> "expected another enum case, or a new declaration or scope use\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"
| 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"
| 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"
| 349 -> "expected a metadata-closing tag\n"
| 350 -> "expected a metadata-closing tag\n"
| 351 -> "expected a metadata-closing tag\n"
| _ -> raise Not_found

View File

@ -0,0 +1,14 @@
@Test@
/*
new scope A:
param x content int
scope A:
def x := 0
def x := 1
exception
def x := 2
*/

View File

@ -0,0 +1,7 @@
[ERROR] An unlabeled exception refers to several definitions, including this one. Disambiguate by using labels.
[ERROR]
[ERROR] --> test_exception/ambiguous_unlabeled_exception.catala
[ERROR] |
[ERROR] 10 | def x := 1
[ERROR] | ^
[ERROR] + Test

View File

@ -0,0 +1,10 @@
@Test@
/*
new scope A:
param x content int
scope A:
exception
def x := 1
*/

View File

@ -0,0 +1,7 @@
[ERROR] No definition associated to this exception
[ERROR]
[ERROR] --> test_exception/missing_unlabeled_definition.catala
[ERROR] |
[ERROR] 9 | def x := 1
[ERROR] | ^
[ERROR] + Test

View File

@ -0,0 +1,20 @@
@Test@
/*
new scope A:
param x content int
param y content int
scope A:
def x := 0
exception
def x := 1
def y := 2
def y := 4
exception
def y := 3
*/

View File

@ -0,0 +1,7 @@
[ERROR] An unlabeled exception refers to several definitions, including this one. Disambiguate by using labels.
[ERROR]
[ERROR] --> test_exception/one_ambiguous_exception.catala
[ERROR] |
[ERROR] 16 | def y := 4
[ERROR] | ^
[ERROR] + Test

View File

@ -0,0 +1,18 @@
@Test@
/*
new scope A:
param x content int
param y content int
scope A:
def x := 0
exception
def x := 1
def y := 2
exception
def y := 3
*/

View File

@ -0,0 +1,3 @@
[RESULT] Computation successful! Results:
[RESULT] x = 1
[RESULT] y = 3

View File

@ -0,0 +1,12 @@
@Test@
/*
new scope A:
param x content int
scope A:
def x := 0
exception
def x := 1
*/

View File

@ -0,0 +1,2 @@
[RESULT] Computation successful! Results:
[RESULT] x = 1

View File

@ -0,0 +1,18 @@
@Test@
/*
new scope A:
param x content int
param y content int
scope A:
exception
def x := 1
exception
def y := 2
def x := 0
def y := 3
*/

View File

@ -0,0 +1,3 @@
[RESULT] Computation successful! Results:
[RESULT] x = 1
[RESULT] y = 2