Skip to content

Commit

Permalink
regress 12/1011
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlei committed Nov 23, 2016
1 parent 203d5f1 commit 65ddc1f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion smop/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions smop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
8 changes: 4 additions & 4 deletions smop/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 10 additions & 11 deletions smop/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -225,13 +216,16 @@ 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()
elif len(p) == 3:
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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 65ddc1f

Please sign in to comment.