diff --git a/smop/lexer.py b/smop/lexer.py index 81585901..5dfe357a 100644 --- a/smop/lexer.py +++ b/smop/lexer.py @@ -315,7 +315,7 @@ def t_SPACES(t): pass def t_error(t): - raise_exception(SyntaxError, ('Unexpected "%s"' % t.value), t.lexer) + raise_exception(SyntaxError, ('Unexpected "%s" (lexer)' % t.value), t.lexer) lexer = lex.lex(reflags=re.MULTILINE) lexer.brackets = 0 # count open square brackets diff --git a/smop/main.py b/smop/main.py index 125e8890..0fa27b4b 100644 --- a/smop/main.py +++ b/smop/main.py @@ -57,6 +57,7 @@ def main(): if options.glob_pattern: options.filelist = fnmatch.filter(options.filelist, options.glob_pattern) + nerrors = 0 for i, options.filename in enumerate(options.filelist): try: if options.verbose: @@ -91,10 +92,15 @@ def main(): fp.write(s) else: fp.write(s) - + except KeyboardInterrupt: + break except: - print 40*"=" + nerrors += 1 traceback.print_exc(file=sys.stdout) + if options.strict: + break + finally: + print "Errors:", nerrors if __name__ == "__main__": main() diff --git a/smop/options.py b/smop/options.py index 7a0ed991..8e8d9d2f 100644 --- a/smop/options.py +++ b/smop/options.py @@ -76,10 +76,10 @@ # Option -l can be specified several times.""") -# parser.add_argument("-s", "--strict", -# action="store_true", -# help="""stop after first syntax error (by -# default compiles other .m files)""") +parser.add_argument("-s", "--strict", + action="store_true", +help="""stop after first syntax error (by +default compiles other .m files)""") parser.add_argument("-V", '--version', action='version', diff --git a/smop/parse.py b/smop/parse.py index a7795d0c..fea2a568 100644 --- a/smop/parse.py +++ b/smop/parse.py @@ -22,15 +22,6 @@ # D def a=... or [a,b,c]=... # U update a(b)=... or [a(b) c(d)]=... - -class error(Exception): - pass - - -class syntax_error(error): - pass - - precedence = ( ("right", "COMMA"), ("right", "DOTDIVEQ", "DOTMULEQ", "EQ", "EXPEQ", "MULEQ", "MINUSEQ", @@ -225,6 +216,7 @@ def p_elseif_stmt(p): elseif_stmt : | ELSE stmt_list_opt | ELSEIF expr sep stmt_list_opt elseif_stmt + | ELSEIF LPAREN expr RPAREN stmt_list_opt elseif_stmt """ if len(p) == 1: p[0] = node.stmt_list() @@ -232,6 +224,8 @@ def p_elseif_stmt(p): p[0] = p[2] elif len(p) == 6: p[0] = node.if_stmt(cond_expr=p[2], then_stmt=p[4], else_stmt=p[5]) + elif len(p) == 7: + p[0] = node.if_stmt(cond_expr=p[3], then_stmt=p[5], else_stmt=p[6]) else: assert 0 @@ -596,7 +590,12 @@ def p_if_stmt(p): if_stmt : IF expr sep stmt_list_opt elseif_stmt END_STMT | IF LPAREN expr RPAREN stmt_list_opt elseif_stmt END_STMT """ - p[0] = node.if_stmt(cond_expr=p[2], then_stmt=p[4], else_stmt=p[5]) + if len(p) == 7: + p[0] = node.if_stmt(cond_expr=p[2], then_stmt=p[4], else_stmt=p[5]) + elif len(p) == 8: + p[0] = node.if_stmt(cond_expr=p[3], then_stmt=p[5], else_stmt=p[6]) + else: + assert 0 @exceptions @@ -831,7 +830,7 @@ def p_error(p): parser.errok() return raise_exception(SyntaxError, - ('Unexpected "%s"' % p.value), + ('Unexpected "%s" (parser)' % p.value), new_lexer) parser = yacc.yacc(start="top")