mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
reorganize update and assign parsing
This commit is contained in:
parent
6c0ec441d5
commit
7f3f17a8e4
@ -175,6 +175,22 @@ local function check_assignable(str, pos, value)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local flatten_explist = flatten_or_mark"explist"
|
||||||
|
local function format_assign(lhs_exps, assign)
|
||||||
|
if not assign then
|
||||||
|
return flatten_explist(lhs_exps)
|
||||||
|
end
|
||||||
|
|
||||||
|
local t = ntype(assign)
|
||||||
|
if t == "assign" then
|
||||||
|
return {"assign", lhs_exps, unpack(assign, 2)}
|
||||||
|
elseif t == "update" then
|
||||||
|
return {"update", lhs_exps[1], unpack(assign, 2)}
|
||||||
|
end
|
||||||
|
|
||||||
|
error "unknown assign expression"
|
||||||
|
end
|
||||||
|
|
||||||
local function sym(chars)
|
local function sym(chars)
|
||||||
return Space * chars
|
return Space * chars
|
||||||
end
|
end
|
||||||
@ -335,9 +351,9 @@ local build_grammar = wrap_env(function()
|
|||||||
Line = (CheckIndent * Statement + Space * #Stop),
|
Line = (CheckIndent * Statement + Space * #Stop),
|
||||||
|
|
||||||
Statement = (
|
Statement = (
|
||||||
Import + While + With + For + ForEach + Switch + Return + ClassDecl + Local +
|
Import + While + With + For + ForEach + Switch + Return + ClassDecl +
|
||||||
Export + BreakLoop + Assign + Update +
|
Local + Export + BreakLoop +
|
||||||
Ct(ExpList) / flatten_or_mark"explist"
|
Ct(ExpList) * (Update + Assign)^-1 / format_assign
|
||||||
) * Space * ((
|
) * Space * ((
|
||||||
-- statement decorators
|
-- statement decorators
|
||||||
key"if" * Exp * (key"else" * Exp)^-1 * Space / mark"if" +
|
key"if" * Exp * (key"else" * Exp)^-1 * Space / mark"if" +
|
||||||
@ -392,8 +408,8 @@ local build_grammar = wrap_env(function()
|
|||||||
CompFor = key"for" * Ct(NameList) * key"in" * (sym"*" * Exp / mark"unpack" + Exp) / mark"for",
|
CompFor = key"for" * Ct(NameList) * key"in" * (sym"*" * Exp / mark"unpack" + Exp) / mark"for",
|
||||||
CompClause = CompFor + key"when" * Exp / mark"when",
|
CompClause = CompFor + key"when" * Exp / mark"when",
|
||||||
|
|
||||||
Assign = Ct(AssignableList) * sym"=" * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark"assign",
|
Assign = sym"=" * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark"assign",
|
||||||
Update = Assignable * ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=")/trim) * Exp / mark"update",
|
Update = ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=") / trim) * Exp / mark"update",
|
||||||
|
|
||||||
-- we can ignore precedence for now
|
-- we can ignore precedence for now
|
||||||
OtherOps = op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<" + op">",
|
OtherOps = op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<" + op">",
|
||||||
|
Loading…
Reference in New Issue
Block a user