Skip to content

Commit

Permalink
Count of good py files is now 962
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlei committed Aug 27, 2016
1 parent 2b59992 commit 5a6e20c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
11 changes: 8 additions & 3 deletions smop/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ def _backend(self,level=0):
def _backend(self,level=0):
if (self.args and
isinstance(self.args[-1],node.ident) and
self.args and
self.args[-1].name == "varargin"):
self.args[-1].name = "*varargin"
s = """
@function
def %s(%s):
nargin = sys._getframe(1).f_locals["nargin"]
varargin = cellarray(varargin)
varargin = sys._getframe(1).f_locals["varargin"]
""" % (self.ident._backend(),
self.args._backend())

Expand All @@ -251,7 +251,12 @@ def _backend(self,level=0):

@extend(node.ident)
def _backend(self,level=0):
return (self.name if self.name not in reserved else self.name+'_') + ("=" + self.init._backend() if self.init is not None else '')
if self.name in reserved:
self.name += "_"
if self.init:
return "%s=%s" % (self.name,
self.init._backend())
return self.name

@extend(node.if_stmt)
def _backend(self,level=0):
Expand Down
27 changes: 16 additions & 11 deletions smop/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class syntax_error(error):
pass

precedence = (
("left", "COMMA"),
("right","DOTDIVEQ","DOTMULEQ","EQ","EXPEQ",
"MULEQ","MINUSEQ","DIVEQ","PLUSEQ","OREQ","ANDEQ"),
("nonassoc","HANDLE"),
("left", "COMMA"),
("left", "COLON"),
("left", "ANDAND", "OROR"),
("left", "EQEQ", "NE", "GE", "LE", "GT", "LT"),
Expand Down Expand Up @@ -100,22 +100,17 @@ def p_arg1(p):
@exceptions
def p_arg_list(p):
"""
arg_list : ident
| arg_list COMMA ident
arg_list : ident_init_opt
| arg_list COMMA ident_init_opt
"""
if len(p) == 2:
p[1].__class__ = node.param
p[0] = node.expr_list([p[1]])
elif len(p) == 4:
p[0] = p[1]
p[3].__class__ = node.param
p[0].append(p[3])
else:
assert 0
assert isinstance(p[0],node.expr_list)
for ident in p[0]:
ident.props="A"


@exceptions
def p_args(p):
Expand Down Expand Up @@ -456,7 +451,17 @@ def p_expr_ident(p):
lineno=p.lineno(1),
lexpos=p.lexpos(1),
column=p.lexpos(1) - p.lexer.lexdata.rfind("\n",0,p.lexpos(1)))

@exceptions
def p_ident_init_opt(p):
"""
ident_init_opt : ident
| ident EQ expr
"""
p[0] = p[1]
if len(p) == 2:
p[0].init = node.ident(name="None") if p[0].name != "varargin" else ""
else:
p[0].init = p[3]

@exceptions
def p_expr_list(p):
Expand Down Expand Up @@ -547,8 +552,8 @@ def p_for_stmt(p):

@exceptions
def p_func_stmt(p):
"""func_stmt : FUNCTION ident args_opt SEMI
| FUNCTION ret EQ ident args_opt SEMI
"""func_stmt : FUNCTION ident lambda_args SEMI
| FUNCTION ret EQ ident lambda_args SEMI
"""
# stmt_list of func_stmt is set below
# marked with XYZZY
Expand Down

0 comments on commit 5a6e20c

Please sign in to comment.