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 Apr 13, 2022
2 parents 4b4dbcc + d38c906 commit fc50db2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions mh_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from collections import OrderedDict
from io import StringIO
from pathlib import Path
import keyword

from miss_hit_core import command_line, pathutil, work_package, cfg_tree
from miss_hit_core.errors import Error, Message_Handler
Expand Down Expand Up @@ -123,6 +124,14 @@ def dynamic_selection_visitor(self, node: Dynamic_Selection, n_parent, relation)
def selection_visitor(self, node: Selection, n_parent, relation):
self[node] = f"{self.pop(node.n_prefix)}.{self.pop(node.n_field)}"

def while_statement_visitor(
self, node: While_Statement, n_parent, relation
):
self[node] = (
f"while {self.pop(node.n_guard)}:\n"
f"{self.indent(self.pop(node.n_body))}\n"
)

def general_for_statement_visitor(
self, node: General_For_Statement, n_parent, relation
):
Expand Down Expand Up @@ -214,8 +223,8 @@ def identifier_visitor(self, node: Identifier, n_parent, relation):

# 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
*keyword.kwlist, # python keyword can not be overwritten
'all', 'any', "slice", "eval", # python build-in names do not suggest overwriting
'I', 'M', 'C', # mat2py keywords
) else ''
self[node] = f'{prefix}{value}'
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.6",
version="0.0.7",
author="Chaoqing Wang",
author_email="[email protected]",
description="Matlab to Python/Numpy translator",
Expand Down

0 comments on commit fc50db2

Please sign in to comment.