Repository navigation
[M extension] variable category generalization #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,12 +340,7 @@ type rule = { | |
|
|
||
| (**{3 Input variables}*) | ||
|
|
||
| (** Unused for now, except for typechecking: [Income] should be a real number | ||
| corresponding to an amount of money *) | ||
| type input_variable_subtype = Context | Family | Penality | Income | ||
|
|
||
| type input_variable_attribute = string | ||
| (** Attributes are unused for now *) | ||
| type variable_attribute = string Pos.marked * literal Pos.marked | ||
|
|
||
| (** Here are all the types a value can have. Date types don't seem to be used at | ||
| all though. *) | ||
|
|
@@ -359,27 +354,19 @@ type value_typ = | |
|
|
||
| type input_variable = { | ||
| input_name : variable_name Pos.marked; | ||
| input_subtyp : input_variable_subtype Pos.marked; | ||
| input_attributes : | ||
| (input_variable_attribute Pos.marked * literal Pos.marked) list; | ||
| input_given_back : bool; | ||
| (** An input variable given back ("restituee") means that it's also an | ||
| output *) | ||
| input_category : string Pos.marked list; | ||
| input_attributes : variable_attribute list; | ||
| input_alias : variable_name Pos.marked; (** Unused for now *) | ||
| input_description : string Pos.marked; | ||
| input_typ : value_typ Pos.marked option; | ||
| } | ||
|
|
||
| (** A [GivenBack] variable is an output of the program *) | ||
| type computed_typ = Base | GivenBack | ||
|
|
||
| type computed_variable = { | ||
| comp_name : variable_name Pos.marked; | ||
| comp_table : int Pos.marked option; | ||
| (** size of the table, [None] for non-table variables *) | ||
| comp_attributes : | ||
| (input_variable_attribute Pos.marked * literal Pos.marked) list; | ||
| comp_subtyp : computed_typ Pos.marked list; | ||
| comp_attributes : variable_attribute list; | ||
| comp_category : string Pos.marked list; | ||
| comp_typ : value_typ Pos.marked option; | ||
| comp_description : string Pos.marked; | ||
| } | ||
|
|
@@ -390,6 +377,31 @@ type variable_decl = | |
| (** The literal is the constant value *) | ||
| | InputVar of input_variable Pos.marked | ||
|
|
||
| type var_type = Input | Computed | ||
|
|
||
| type var_category_decl = { | ||
| var_type : var_type; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand the meaning of this struct. Does this correspond in the syntax to a declaration of a new variable category, or a new variable ? If this was the declaration of a new variable category I would just have expected a string here (
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see the declaration is of the sort
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the expected attributes are simply listed while the actual category is the set of declared keywords before. It reads as "variables declared with keywords that includes this set are expected to have exactly these attributes." |
||
| var_category : string Pos.marked list; | ||
| var_attributes : string Pos.marked list; | ||
| } | ||
|
|
||
| (* standard categories *) | ||
| let input_category = "saisie" | ||
|
|
||
| let computed_category = "calculee" | ||
|
|
||
| let base_category = "base" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cant' these be put in a
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only to minimize occurrences of hardcoded strings in various places of the code. Because the compiler still needs to identify them for lack of generality. This ought to disappear once every specificities like this are declared away in the user code instead of in the compiler. |
||
|
|
||
| let givenback_category = "restituee" | ||
|
|
||
| let family_category = "famille" | ||
|
|
||
| let income_category = "revenu" | ||
|
|
||
| let context_category = "contexte" | ||
|
|
||
| let penality_category = "penalite" | ||
|
|
||
| (**{2 Verification clauses}*) | ||
|
|
||
| (** These clauses are expression refering to the variables of the program. They | ||
|
|
@@ -437,7 +449,7 @@ type source_file_item = | |
| | Error of error_ (** Declares an error *) | ||
| | Output of variable_name Pos.marked (** Declares an output variable *) | ||
| | Function (** Declares a function, unused *) | ||
|
|
||
| | VarCatDecl of var_category_decl Pos.marked | ||
| (* TODO: parse something here *) | ||
|
|
||
| type source_file = source_file_item Pos.marked list | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you should maybe put an error message in case someone enters an attribute not in the list of strings you accept above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the issue here would be that none of the expected categories appears, not that there is an unexpected one. I definitely would add a clean error message here, but this file in its current state ought to fall into oblivion as it's mostly adhoc, hardcoded, necessary mess that works only because tailored for the current M codebase.