Closed LukeLavan closed 2 years ago
Looks like the global variable part of this PR was addressed in this commit by making _validate_comparison_node
a member function, allowing access to use _parse_attributes
. Negative numbers still aren't accounted for, so I updated my branch accordingly and I will leave this PR up. Note however that the permalinks point to the old version of this function - if desired I can update these links as well.
looks like https://github.com/Grimrukh/soulstruct/commit/7b464b7457ff177023cbe30dcb1338fc70c93038 fixes this by passing the comparator to self._parse_nodes
which contains logic to evaluate a negative number
negative numbers
When performing simple comparisons like so:
compilation yields the following error:
This error occurs because the right value (
node.comparators[0]
) currently needs to be anast.Num
. However, negative numbers are parsed as anast.UnaryOp
because of the way Python handles numerical literals:I circumvent this by using the
ast.literal_eval
function and packing that back into anast.Constant
. Doing so allows the compilation to succeed, and decompiling the product shows that this is handled successfully:As a sidenote, the use of
ast.Num
is deprecated:and so is using the
.n
attribute ofast.Constant
s:so my changes also make the appropriate refactors.
global variables
Also disallowed for the right side of simple comparisons were
ast.Attribute
s, which could be global variables, either imported or declared in the file:both result in:
Using my changes, both compile successfully. This works as proved by the result of decompilation:
results in
and results in
as expected, the decompiled results are equivalent.
This is accomplished by passing in the EVSParser's
self.globals
along with the comparison node to the_validate_comparison_node
function. Let me know if this isn't desirable behavior or if there's some better way to do this!