Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5e0417e
refactor: Rename 'identity' to the standard 'identifier'
Tobiky Mar 10, 2025
2fea2b3
docs: Minimal visitor pattern example
Tobiky Mar 10, 2025
9e56d75
chore: Add __pycache__ to ignore
Tobiky Mar 10, 2025
5266b7c
refactor: Rename 'identity' to 'identifier' in tests
Tobiky Mar 12, 2025
7d367e7
refactor: Rename 'identity' to 'identifier' in highlighting query
Tobiky Mar 12, 2025
e2fecdc
fix: Identifier field is 'id' not 'name'
Tobiky Mar 17, 2025
9e4c830
docs: Improve output by decoding bytes type in visitor example
Tobiky Mar 17, 2025
e02583a
docs: Use relative path instead of changing directory
Tobiky Mar 17, 2025
e8087e1
docs: Example of fast visitor pattern using tree sitter cursor
Tobiky Mar 18, 2025
afe0a62
docs: Include return of iterable values in skip visit function of exa…
Tobiky Mar 21, 2025
71c6251
docs: Comment on necessary naming patterns of visitor functions in ex…
Tobiky Mar 21, 2025
2eef7e0
docs: Decode node text in return value of visitor example
Tobiky Mar 21, 2025
edce9b9
docs: Replace generator function with multiple type return in visitor…
Tobiky Mar 25, 2025
2a5224a
docs: Provide return type hints for functions in visitor example
Tobiky Mar 25, 2025
0a1e422
feat: Started implementing visitor
tagyieh Apr 2, 2025
7df4419
fix: Corrected visiting of CIAS and CIA
tagyieh Apr 3, 2025
4d96fcb
feat: Implemented more visitor patterns.
tagyieh Apr 29, 2025
304121a
feat: Implemented visitor for preconditions.
tagyieh May 1, 2025
0a7eb4a
feat: Implemented visitor patter for reaches expression.
tagyieh May 1, 2025
4ee8987
feat: Visitor for associations.
tagyieh May 3, 2025
0870946
feat: Visitor for include.
tagyieh May 3, 2025
84dc4ec
feat: Visitor for detectors.
tagyieh May 3, 2025
5f25042
fix: Corrected code to match original compiler output
tagyieh May 4, 2025
d9cc3bc
feat: TreeSitter visitors finished.
tagyieh May 5, 2025
080f98e
feat: Implemented analyzer.
tagyieh May 8, 2025
896db1d
chore: generate grammar
Tobiky May 13, 2025
f23e0d3
test: update attack step to use identifier instead of identity nodes
Tobiky May 13, 2025
4d00d9b
fix: reduce requirements to highlight relevant nodes as tags
Tobiky May 13, 2025
7fc7200
fix: made step type into node to highlight E type
Tobiky May 16, 2025
d79c108
feat: swap to dictionary look-up of bstr for attak-step-type bindings
Tobiky May 16, 2025
456e6b1
refactor: swap decode with byte-strings in visit_attack_step
Tobiky May 16, 2025
307521c
refactor: swap decode with byte-strings in visit_detector_context
Tobiky May 16, 2025
7e56670
refactor: swap decode with byte-strings in visit_asset_declaration
Tobiky May 16, 2025
dec1d47
refactor: swap strip() with slices in visit_meta
Tobiky May 16, 2025
83e8d82
fix: skip not having enough parameter space
Tobiky May 16, 2025
0457dfd
refactor: swap strip() with slices in visit_meta
Tobiky May 16, 2025
e39ec00
feat: swap to dictionary look-up of bstr for cia bindings
Tobiky May 16, 2025
03f267c
refactor: swap decode with byte-strings in _visit_intermediary_ttc_expr
Tobiky May 16, 2025
7bac477
refactor: Remove decode() for float() casts
Tobiky May 16, 2025
7bdb4a0
feat: swap to dictionary look-up of bstr for ttc binop operation type…
Tobiky May 16, 2025
32e5841
refactor: swap decode with byte-strings in visit_ttc_distribution
Tobiky May 16, 2025
0ac693d
refactor: swap decode with byte-strings in visit_reaching
Tobiky May 16, 2025
3d02223
feat: swap to dictionary look-up of bstr for asset expression binop b…
Tobiky May 16, 2025
fad8f26
refactor: swap decode with byte-strings in visit_associations_declara…
Tobiky May 16, 2025
e871f97
chore: Bump grammar version to 0.2.0
Tobiky May 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _obj/
dist/
*.egg-info
*.whl
__pycache__/

# C artifacts
*.a
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions examples/visitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Visitor Pattern Example
This example showcases how a visitor pattern can be built to use the MAL parser.

# Running
1. Install [tree-sitter-cli](https://github.com/tree-sitter/tree-sitter/tree/master/cli)
2. Build the language in the project root folder using `tree-sitter build`
4. Navigate to `./examples/visitor/`
1. Create a virtual environment `python -m venv venv`
2. Activate the environment (e.g. `source ./venv/bin/activate`)
3. Install dependencies `pip install -r requirements.txt`
6. Build the python dependency using `pip install -e ../..` (Path should direct to project root)
7. (Optional) swap between fast or simple visitor patterns by editing `main.py` imports
8. Execute the main file `python main.py`
115 changes: 115 additions & 0 deletions examples/visitor/distributions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
class DistributionsException(Exception):
def __init__(self, error_message):
self._error_message = error_message
super().__init__(self._error_message)

class Distributions:
def validate(distribution_name: str, params: list) -> None:
match distribution_name:
case 'Bernoulli':
Bernoulli.validate(params)
case 'Binomial':
Binomial.validate(params)
case 'Exponential':
Exponential.validate(params)
case 'Gamma':
Gamma.validate(params)
case 'LogNormal':
LogNormal.validate(params)
case 'Pareto':
Pareto.validate(params)
case 'TruncatedNormal':
TruncatedNormal.validate(params)
case 'Uniform':
Uniform.validate(params)
case 'Enabled' | 'Disabled' | 'Zero' | 'Infinity' | 'EasyAndCertain' | \
'EasyAndUncertain' | 'HardAndCertain' | 'HardAndUncertain' | \
'VeryHardAndCertain' | 'VeryHardAndUncertain':
Combination.validate(params)
case _:
err_msg = f"Distribution {distribution_name} is not supported"
raise(DistributionsException(err_msg))

class Bernoulli:
def validate(params: list) -> None:
if (not params or len(params)!=1):
err_msg = "Expected exactly one parameter (probability), for Bernoulli distribution"
raise(DistributionsException(err_msg))
if not 0<=params[0]<=1:
err_msg = f"{params[0]} is not in valid range '0 <= probability <= 1', for Bernoulli distribution"
raise(DistributionsException(err_msg))

class Binomial:
def validate(params: list) -> None:
if (not params or len(params)!=2):
err_msg = "Expected exactly two parameters (trials, probability), for Binomial distribution"
raise(DistributionsException(err_msg))
if not 0<=params[1]<=1:
err_msg = f"{params[1]} is not in valid range '0 <= probability <= 1', for Binomial distribution"
raise(DistributionsException(err_msg))

class Exponential:
def validate(params: list) -> None:
if (not params or len(params)!=1):
err_msg = "Expected exactly one parameter (lambda), for Exponential distribution"
raise(DistributionsException(err_msg))
if params[0]<=0:
err_msg = f"{params[0]} is not in valid range 'lambda > 0', for Exponential distribution"
raise(DistributionsException(err_msg))

class Gamma:
def validate(params: list) -> None:
if (not params or len(params)!=2):
err_msg = "Expected exactly two parameters (shape, scale), for Gamma distribution"
raise(DistributionsException(err_msg))
if params[0]<=0:
err_msg = f"{params[0]} is not in valid range 'shape > 0', for Gamma distribution"
raise(DistributionsException(err_msg))
if params[1]<=0:
err_msg = f"{params[1]} is not in valid range 'scale > 0', for Gamma distribution"
raise(DistributionsException(err_msg))

class LogNormal:
def validate(params: list) -> None:
if (not params or len(params)!=2):
err_msg = "Expected exactly two parameters (mean, standardDeviation), for LogNormal distribution"
raise(DistributionsException(err_msg))
if params[1]<=0:
err_msg = f"{params[1]} is not in valid range 'standardDeviation > 0', for LogNormal distribution"
raise(DistributionsException(err_msg))

class Pareto:
def validate(params: list) -> None:
if (not params or len(params)!=2):
err_msg = "Expected exactly two parameters (min, shape), for Pareto distribution"
raise(DistributionsException(err_msg))
if params[0]<=0:
err_msg = f"{params[0]} is not in valid range 'min > 0', for Pareto distribution"
raise(DistributionsException(err_msg))
if params[1]<=0:
err_msg = f"{params[1]} is not in valid range 'shape > 0', for Pareto distribution"
raise(DistributionsException(err_msg))

class TruncatedNormal:
def validate(params: list) -> None:
if (not params or len(params)!=2):
err_msg = "Expected exactly two parameters (mean, standardDeviation), for TruncatedNormal distribution"
raise(DistributionsException(err_msg))
if params[1]<=0:
err_msg = f"{params[1]} is not in valid range 'standardDeviation > 0', for TruncatedNormal distribution"
raise(DistributionsException(err_msg))

class Uniform:
def validate(params: list) -> None:
if (not params or len(params)!=2):
err_msg = "Expected exactly two parameters (min, max), for Uniform distribution"
raise(DistributionsException(err_msg))
if params[0] > params[1]:
err_msg = f"({params[0]}, {params[1]}) does not meet requirement 'min <= max', for Uniform distribution"
raise(DistributionsException(err_msg))

class Combination:
def validate(params: list) -> None:
if (params and len(params)!=0):
err_msg = "Expected exactly zero parameters, for combination distributions"
raise(DistributionsException(err_msg))
Loading