Skip to content

Commit

Permalink
add support for 'Constant' ast node type
Browse files Browse the repository at this point in the history
  • Loading branch information
yinwang0 committed Apr 23, 2022
1 parent 8670ec2 commit d9deca0
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main/java/org/yinwang/pysonar/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,26 @@ else if (s.length() >= 2 && s.startsWith("\"") && s.endsWith("\""))
return new Yield(value, file, start, end, line, col);
}

$.msg("\n[Please Report]: unexpected ast node: " + type);
// Python3's new node type 'Constant'
// Just convert to other types and call convert again
if (type.equals("Constant")) {
Object value = map.get("value");

if (map.containsKey("num_type")) {
map.put("pysonar_node_type", "Num");
map.put("n", map.get("value"));
}
else if (value instanceof String) {
map.put("pysonar_node_type", "Str");
map.put("s", value);
}
else if (value instanceof Boolean) {
map.put("pysonar_node_type", "NameConstant");
}
return convert(map);
}

$.msg("\n[Please report issue]: Unexpected ast node type: " + type + "\nnode: " + o + "\nfile: " + file);
return new Unsupported(file, start, end, line, col);
}

Expand Down

0 comments on commit d9deca0

Please sign in to comment.