Skip to content

Commit

Permalink
Merge branch 'matlab2numpy' into mh_python
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoqing committed Feb 9, 2022
2 parents 271a32c + a556eb1 commit 4b4dbcc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ We hope to merge this utility back to `miss_hit` after it is stable.

## Usage

Try it online [here](https://translate.mat2py.org/).

```python
# must install
python3 -m pip install mh-python
Expand Down
10 changes: 9 additions & 1 deletion mh_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,15 @@ def reference_visitor(self, node: Reference, n_parent, relation):
self[node] = f"{self.pop(node.n_ident)}{bra}{args}{ket}"

def identifier_visitor(self, node: Identifier, n_parent, relation):
self[node] = node.t_ident.value
value = node.t_ident.value

# Python and Matlab keywords set are different. Luckily, Matlab forbids identifier start with `_`.
prefix = '_' if value in (
'not', 'is', 'and', 'or', 'in', 'del', # python keyword can not be overwritten
'all', 'any', # python build-in names do not suggest overwriting
'I', 'M', 'C', # mat2py keywords
) else ''
self[node] = f'{prefix}{value}'

def number_literal_visitor(self, node: Number_Literal, n_parent, relation):
self[node] = node.t_value.value.replace("i", "j")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name="mh_python",
version="0.0.5",
version="0.0.6",
author="Chaoqing Wang",
author_email="[email protected]",
description="Matlab to Python/Numpy translator",
Expand Down

0 comments on commit 4b4dbcc

Please sign in to comment.