Commit 3a6c0e07 authored by Thomas Huetter's avatar Thomas Huetter

fixed bugs in python asts; still not working

parent 4c05cc9d
...@@ -14,7 +14,7 @@ import json ...@@ -14,7 +14,7 @@ import json
def print_tree(json_tree, index): def print_tree(json_tree, index):
print('{' + json_tree[index]['type'], end='') print('{' + json_tree[index]['type'], end='')
if 'value' in json_tree[index]: if 'value' in json_tree[index]:
print('{' + json_tree[index]['value'].replace('\r','').replace('\n','').strip().translate(str.maketrans({"{": r"\{", print('{' + json_tree[index]['value'].replace('\r','').replace('\n','').replace('\t', '').strip().translate(str.maketrans({"{": r"\{",
"}": r"\}", "}": r"\}",
"\\": r"\\"})) "\\": r"\\"}))
+ '}', end='') + '}', end='')
...@@ -34,4 +34,4 @@ with open(args.inputfile) as f: ...@@ -34,4 +34,4 @@ with open(args.inputfile) as f:
for line in f: for line in f:
json_tree = json.loads(line) json_tree = json.loads(line)
print_tree(json_tree, 0) print_tree(json_tree, 0)
print() print()
\ No newline at end of file
#!/bin/bash #!/bin/bash
# | sort by number of nodes (equivalent to number of "{") # | sort by number of nodes (equivalent to number of "{"), remove duplicates
cat $1 | awk '{print gsub("{","{"), $0}' | sort -n | cut -d' ' -f2- > "${1%.bracket}_sorted.bracket" cat $1 | perl -F{ -lane 'print "$#F $_"' | sort -n | cut -d' ' -f2- > "${1%.bracket}_sorted.bracket"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment