Skip to content

Commit

Permalink
Allow aliases to be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Jan 23, 2025
1 parent cdf9e0c commit a35aa87
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/llex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
luaX_syntaxerror(ls, "expected '=' after $alias <name>");
}
++i; /* skip '=' */
while (true) {
while (i->line == (i - 1)->line || (i - 1)->token == '\\') {
if (i->token == TK_EOS)
break;
if (i->token == '\\' && (i + 1)->line != i->line) {
Expand All @@ -308,8 +308,6 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
}
macro.sub.emplace_back(*i);
++i;
if (i->line != (i - 1)->line)
break;
}
i = ls->tokens.erase(directive_begin, i); /* erase directive */
continue;
Expand Down Expand Up @@ -347,8 +345,9 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source,
i = ls->tokens.insert(i, t);
}
}
else
else {
i = ls->tokens.insert(i, e->second.sub.begin(), e->second.sub.end());
}
continue;
}
}
Expand Down
30 changes: 30 additions & 0 deletions testes/pluto/basic.pluto
Original file line number Diff line number Diff line change
Expand Up @@ -3437,6 +3437,36 @@ do
return add(1, 2)
]]() == 3)

assert(load[[
$alias please =
if true please do
return "hello"
end
]]() == "hello")

assert(load[[
$alias in_the_case_that = \
if
in_the_case_that true then
return "hello"
end
]]() == "hello")

assert(select("#", load[[
$alias add(a, b) =
return add(1, 2)
]]()) == 0)

assert(load[[
$alias add(a, b) = \
a + b
return a + b
]])
end

print "Testing try/catch."
Expand Down

0 comments on commit a35aa87

Please sign in to comment.