[WIP] Propagate variable types if within same variable scope #152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes
As noted in #150, in the domain parser, sometimes (like in derived predicates), we do not propagate typing annotations from its definition to its condition.
Fixes
Work in progress, fixes #150
Types of changes
What types of changes does your code introduce?
Put an
xin the boxes that applyChecklist
Put an
xin the boxes that apply.Further comments
I added tests to verify that variable types are handled correctly for action definitions, and it appears that this is the case.
This is because, whenever the LR parser encounters the
action_parameterstag, it reinitializes the varname-to-Variablemapping:pddl/pddl/parser/domain.py
Line 147 in c381a08
To me it seems this is not easily doable in the case of
derived_predicates:pddl/pddl/parser/domain.py
Lines 139 to 143 in c381a08
derived_predicate_definstead ofatomic_formula_skeletonmight help!pddl/pddl/parser/grammar.lark
Line 26 in c381a08
With a recursive parser, it would have been handled more easily: simply reset the mapping whenever we start to parse a derived predicate. However, as seen in here, we have already parsed both the derived predicate definition and its formula definition. More generally, the difficulty lies in the fact that our parser is a bottom-up parser.
A solution would be to re-parse the data structures (e.g., the AST of the formula) and replace variables without types with the same variable but with the right types. It would not be a "one-pass" computation, though.