mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
fix empty line consumption for else, fixes #276
This commit is contained in:
parent
f2363f53cd
commit
2f1dd92012
@ -27,10 +27,10 @@ Num = Space * (Num / function(v)
|
||||
v
|
||||
}
|
||||
end)
|
||||
local Indent, Cut, ensure, extract_line, mark, pos, flatten_or_mark, is_assignable, check_assignable, format_assign, format_single_assign, sym, symx, simple_string, wrap_func_arg, join_chain, wrap_decorator, check_lua_string, self_assign
|
||||
local Indent, Cut, ensure, extract_line, mark, pos, flatten_or_mark, is_assignable, check_assignable, format_assign, format_single_assign, sym, symx, simple_string, wrap_func_arg, join_chain, wrap_decorator, check_lua_string, self_assign, got
|
||||
do
|
||||
local _obj_0 = require("moonscript.parse.util")
|
||||
Indent, Cut, ensure, extract_line, mark, pos, flatten_or_mark, is_assignable, check_assignable, format_assign, format_single_assign, sym, symx, simple_string, wrap_func_arg, join_chain, wrap_decorator, check_lua_string, self_assign = _obj_0.Indent, _obj_0.Cut, _obj_0.ensure, _obj_0.extract_line, _obj_0.mark, _obj_0.pos, _obj_0.flatten_or_mark, _obj_0.is_assignable, _obj_0.check_assignable, _obj_0.format_assign, _obj_0.format_single_assign, _obj_0.sym, _obj_0.symx, _obj_0.simple_string, _obj_0.wrap_func_arg, _obj_0.join_chain, _obj_0.wrap_decorator, _obj_0.check_lua_string, _obj_0.self_assign
|
||||
Indent, Cut, ensure, extract_line, mark, pos, flatten_or_mark, is_assignable, check_assignable, format_assign, format_single_assign, sym, symx, simple_string, wrap_func_arg, join_chain, wrap_decorator, check_lua_string, self_assign, got = _obj_0.Indent, _obj_0.Cut, _obj_0.ensure, _obj_0.extract_line, _obj_0.mark, _obj_0.pos, _obj_0.flatten_or_mark, _obj_0.is_assignable, _obj_0.check_assignable, _obj_0.format_assign, _obj_0.format_single_assign, _obj_0.sym, _obj_0.symx, _obj_0.simple_string, _obj_0.wrap_func_arg, _obj_0.join_chain, _obj_0.wrap_decorator, _obj_0.check_lua_string, _obj_0.self_assign, _obj_0.got
|
||||
end
|
||||
local build_grammar = wrap_env(debug_grammar, function(root)
|
||||
local _indent = Stack(0)
|
||||
@ -131,8 +131,8 @@ local build_grammar = wrap_env(debug_grammar, function(root)
|
||||
SwitchCase = key("when") * Ct(ExpList) * key("then") ^ -1 * Body / mark("case"),
|
||||
SwitchElse = key("else") * Body / mark("else"),
|
||||
IfCond = Exp * Assign ^ -1 / format_single_assign,
|
||||
IfElse = (Break * CheckIndent) ^ -1 * EmptyLine ^ 0 * key("else") * Body / mark("else"),
|
||||
IfElseIf = (Break * CheckIndent) ^ -1 * EmptyLine ^ 0 * key("elseif") * pos(IfCond) * key("then") ^ -1 * Body / mark("elseif"),
|
||||
IfElse = (Break * EmptyLine ^ 0 * CheckIndent) ^ -1 * key("else") * Body / mark("else"),
|
||||
IfElseIf = (Break * EmptyLine ^ 0 * CheckIndent) ^ -1 * key("elseif") * pos(IfCond) * key("then") ^ -1 * Body / mark("elseif"),
|
||||
If = key("if") * IfCond * key("then") ^ -1 * Body * IfElseIf ^ 0 * IfElse ^ -1 / mark("if"),
|
||||
Unless = key("unless") * IfCond * key("then") ^ -1 * Body * IfElseIf ^ 0 * IfElse ^ -1 / mark("unless"),
|
||||
While = key("while") * DisableDo * ensure(Exp, PopDo) * key("do") ^ -1 * Body / mark("while"),
|
||||
|
@ -27,7 +27,8 @@ Num = Space * (Num / (v) -> {"number", v})
|
||||
:Indent, :Cut, :ensure, :extract_line, :mark, :pos, :flatten_or_mark,
|
||||
:is_assignable, :check_assignable, :format_assign, :format_single_assign,
|
||||
:sym, :symx, :simple_string, :wrap_func_arg, :join_chain,
|
||||
:wrap_decorator, :check_lua_string, :self_assign
|
||||
:wrap_decorator, :check_lua_string, :self_assign, :got
|
||||
|
||||
} = require "moonscript.parse.util"
|
||||
|
||||
|
||||
@ -150,8 +151,8 @@ build_grammar = wrap_env debug_grammar, (root) ->
|
||||
|
||||
IfCond: Exp * Assign^-1 / format_single_assign
|
||||
|
||||
IfElse: (Break * CheckIndent)^-1 * EmptyLine^0 * key"else" * Body / mark"else"
|
||||
IfElseIf: (Break * CheckIndent)^-1 * EmptyLine^0 * key"elseif" * pos(IfCond) * key"then"^-1 * Body / mark"elseif"
|
||||
IfElse: (Break * EmptyLine^0 * CheckIndent)^-1 * key"else" * Body / mark"else"
|
||||
IfElseIf: (Break * EmptyLine^0 * CheckIndent)^-1 * key"elseif" * pos(IfCond) * key"then"^-1 * Body / mark"elseif"
|
||||
|
||||
If: key"if" * IfCond * key"then"^-1 * Body * IfElseIf^0 * IfElse^-1 / mark"if"
|
||||
Unless: key"unless" * IfCond * key"then"^-1 * Body * IfElseIf^0 * IfElse^-1 / mark"unless"
|
||||
|
@ -154,3 +154,29 @@ a,c,b = "cool" if something
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
j = if 1
|
||||
if 2
|
||||
3
|
||||
else 6
|
||||
|
||||
|
||||
m = if 1
|
||||
|
||||
|
||||
|
||||
if 2
|
||||
|
||||
|
||||
3
|
||||
|
||||
|
||||
else 6
|
||||
|
||||
|
||||
|
||||
nil
|
||||
|
||||
|
||||
|
||||
|
@ -250,4 +250,21 @@ local a = 12
|
||||
local c, b
|
||||
if something then
|
||||
a, c, b = "cool"
|
||||
end
|
||||
end
|
||||
local j
|
||||
if 1 then
|
||||
if 2 then
|
||||
j = 3
|
||||
end
|
||||
else
|
||||
j = 6
|
||||
end
|
||||
local m
|
||||
if 1 then
|
||||
if 2 then
|
||||
m = 3
|
||||
end
|
||||
else
|
||||
m = 6
|
||||
end
|
||||
return nil
|
Loading…
Reference in New Issue
Block a user