From 5a6e20ce57a689bb2ea0648b938db65a8b6947a0 Mon Sep 17 00:00:00 2001 From: Victor Lei Date: Sat, 27 Aug 2016 19:31:52 +0300 Subject: [PATCH] Count of good py files is now 962 --- smop/backend.py | 11 ++++++++--- smop/parse.py | 27 ++++++++++++++++----------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/smop/backend.py b/smop/backend.py index 0f62b94d..c2517d07 100644 --- a/smop/backend.py +++ b/smop/backend.py @@ -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()) @@ -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): diff --git a/smop/parse.py b/smop/parse.py index e4605d94..a139553e 100644 --- a/smop/parse.py +++ b/smop/parse.py @@ -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"), @@ -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): @@ -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): @@ -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