Skip to content
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

MATLAB switch statement support #634

Merged
merged 88 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
90fe557
Fixed a tyypo
Nov 1, 2023
206e0bd
Renamed file
Nov 2, 2023
7e430e5
Tests can now use multiple CAST objects
Nov 2, 2023
77fc4c7
Added a string coparison to the assignment tests
Nov 2, 2023
6095d71
Cast debug with multiple input files
Nov 2, 2023
9d24257
Added a method for pruning keys from cast debug output
Nov 3, 2023
53fe756
early switch statment handler
Nov 3, 2023
3502db1
Fixed node_helper args
Nov 3, 2023
9ef903a
cast_out debug with multiple key removal
Nov 3, 2023
88d63eb
switch 'if' expression done
Nov 4, 2023
ce687b8
Added key filtering and correct reporting of None values
Nov 5, 2023
ce2337f
Added an 'otherwise' clause to the MATLAB switch statement test
Nov 5, 2023
c8f45f5
Populated Operator fields, fixed comments
Nov 5, 2023
4b23e90
Cleaned up code formatting, comments
Nov 6, 2023
dc0d015
Cleaned up comments
Nov 6, 2023
91d1a02
Removed debug print statements and placeholder Docstrings
Nov 6, 2023
313d6a2
Deleted an unused debug tree field
Nov 6, 2023
6ed1906
Fixed an indentation error
Nov 7, 2023
5511e15
Added test cases for multi-element conditional blocks
Nov 7, 2023
41f89b5
cleaned up conditional node handler
Nov 7, 2023
40bb9f2
Cleaned up comments
Nov 7, 2023
8cf81fa
Fixed a list handling bug
Nov 7, 2023
4c1c549
Added a test case ifor if-elseif conditional
Nov 7, 2023
810d9bb
Cleaned up comments
Nov 7, 2023
d374217
Added a guard for None values
Nov 7, 2023
bc8a32d
switch statement literal nodes
Nov 7, 2023
bd0be4d
fixed conditional orelse logic, added switch statement
Nov 7, 2023
0d2f2bf
else clause node bugfix
Nov 7, 2023
a83ac8a
Fixed a bug in a test case
Nov 7, 2023
68b66d8
Removed an outdated method, fixed comments
Nov 7, 2023
ed22d6d
Added a test for switch statements
Nov 7, 2023
6936daa
Added helper methods
Nov 7, 2023
5f16fc3
Added a node_helper method to recursively search a CAST node
Nov 8, 2023
1bfe67e
Added multi-value switch statement case clauses
Nov 8, 2023
590bf95
Added CI test case for switch case clauses with multiple values
Nov 8, 2023
b625c05
Fixed a tyypo
Nov 1, 2023
7c3784d
Renamed file
Nov 2, 2023
bbfc5c4
Tests can now use multiple CAST objects
Nov 2, 2023
a902d86
Added a string coparison to the assignment tests
Nov 2, 2023
2476607
Cast debug with multiple input files
Nov 2, 2023
2ffe426
Added a method for pruning keys from cast debug output
Nov 3, 2023
78746a2
early switch statment handler
Nov 3, 2023
8276621
Fixed node_helper args
Nov 3, 2023
0b4d128
cast_out debug with multiple key removal
Nov 3, 2023
7496d7b
switch 'if' expression done
Nov 4, 2023
bf735cd
Added key filtering and correct reporting of None values
Nov 5, 2023
3a8d93d
Added an 'otherwise' clause to the MATLAB switch statement test
Nov 5, 2023
e024bcb
Populated Operator fields, fixed comments
Nov 5, 2023
137abcc
Cleaned up code formatting, comments
Nov 6, 2023
477d231
Cleaned up comments
Nov 6, 2023
bd4906a
Removed debug print statements and placeholder Docstrings
Nov 6, 2023
b3f443b
Deleted an unused debug tree field
Nov 6, 2023
7acbf48
Fixed an indentation error
Nov 7, 2023
1c32a95
Added test cases for multi-element conditional blocks
Nov 7, 2023
80165e9
cleaned up conditional node handler
Nov 7, 2023
07b67b4
Cleaned up comments
Nov 7, 2023
a0cee58
Fixed a list handling bug
Nov 7, 2023
93dd114
Added a test case ifor if-elseif conditional
Nov 7, 2023
53b79ae
Cleaned up comments
Nov 7, 2023
c70fc38
Added a guard for None values
Nov 7, 2023
4498638
switch statement literal nodes
Nov 7, 2023
6df4d2b
fixed conditional orelse logic, added switch statement
Nov 7, 2023
720353e
else clause node bugfix
Nov 7, 2023
8fa103c
Fixed a bug in a test case
Nov 7, 2023
40d394f
Removed an outdated method, fixed comments
Nov 7, 2023
37872cd
Added a test for switch statements
Nov 7, 2023
75b5b5a
Added helper methods
Nov 7, 2023
f95213b
Added a node_helper method to recursively search a CAST node
Nov 8, 2023
d0b281e
Added multi-value switch statement case clauses
Nov 8, 2023
3075e14
Added CI test case for switch case clauses with multiple values
Nov 8, 2023
4db4de0
Merge branch 'jastier/dev' of github.com:ml4ai/skema into jastier/dev
Nov 8, 2023
0f9c3c7
Fixed a typo in a test case
Nov 8, 2023
09df370
cleaned up comments
Nov 8, 2023
2d19073
placeholder
Nov 8, 2023
f1f607b
changed variable names for consistency
Nov 8, 2023
8c2c5c8
Renamed test file
Nov 9, 2023
80717a4
Renamed file
Nov 9, 2023
e7bdf96
Added equality tests to the conditional logic test cases
Nov 9, 2023
1f2ed08
organized CI tests
Nov 9, 2023
48f5c9e
Added test cases for literal assignment
Nov 9, 2023
6a0cac0
Merge branch 'main' into jastier/dev
jastier Nov 13, 2023
9acaf66
Added a missing source_refs node
Nov 13, 2023
409d10d
Added a missing source_refs node
Nov 13, 2023
5f64486
Added missing source_refs node
Nov 13, 2023
76e5877
Merge branch 'main' into jastier/dev
jastier Nov 13, 2023
96b0243
Added CI tests for missing source_refs nodes
Nov 13, 2023
b849421
Merge branch 'jastier/dev' of github.com:ml4ai/skema into jastier/dev
Nov 13, 2023
3be1595
Added testing for null source_refs nodes
Nov 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 45 additions & 15 deletions skema/program_analysis/CAST/matlab/cast_out
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,55 @@
import json
import sys
from skema.program_analysis.CAST.matlab.matlab_to_cast import MatlabToCast
from typing import List

# Show a CAST object as pretty printed JSON with keys filtered for clarity.

# Keys to remove from the output
#KEY_FILTER = ["source_refs", "default_value", "interpreter"]
KEY_FILTER = ["source_refs"]

def remove_keys(json_obj, target_keys: List):
""" remove all instances of the target keys from the json object"""

def remove_key(json_obj, target_key):
""" remove all instances of the target key from the json object"""
if isinstance(json_obj, dict):
for target_key in target_keys:
if target_key in json_obj.keys():
json_obj.pop(target_key)
for key in json_obj.keys():
remove_key(json_obj[key], target_keys)
elif isinstance(json_obj, list):
for item in json_obj:
remove_key(item, target_keys)
return(json_obj)

print(f"Removed keys: {target_keys}")
return remove_key(json_obj, target_keys)


def show_cast(filename):
""" Run a file of any type through the Tree-sitter MATLAB parser"""
parser = MatlabToCast(filename)
print("\nINPUT FILE:")
print(parser.filename)
print("\nSOURCE:")
print(parser.source)
print('\nCAST:')
cast_list = parser.out_cast
for cast in cast_list:
json_obj = cast.to_json_object()
# declutter JSON by filtering keys
json_obj = remove_keys(json_obj, KEY_FILTER)
# pretty print JSON to string
output = json.dumps(json_obj, sort_keys=True, indent=2)
print(output)

""" Run a file of any type through the Tree-sitter MATLAB parser"""

if __name__ == "__main__":
if len(sys.argv) > 1:
for i in range(1, len(sys.argv)):
parser = MatlabToCast(sys.argv[i])
print("\n\nINPUT:")
print(parser.filename)
print("\nSOURCE:")
print(parser.source)
print('\nCAST:')
cast_list = parser.out_cast
for cast_index in range(0, len(cast_list)):
jd = json.dumps(
cast_list[cast_index].to_json_object(),
sort_keys=True,
indent=2,
)
print(jd)
show_cast(sys.argv[i])
else:
print("Please enter one filename to parse")
Loading
Loading