mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 17:19:31 +00:00
Allow no expression in return
This commit is contained in:
parent
53c1c764ba
commit
f574e6a775
5 changed files with 25 additions and 6 deletions
21
parser/expression/primary/prefix/prefix_maybe_nil_right.lua
Normal file
21
parser/expression/primary/prefix/prefix_maybe_nil_right.lua
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
local prefix = require("parser.expression.primary.prefix.prefix")
|
||||
local escape = require("common").escape
|
||||
local expression_to_ast = require("parser.expression.to_ast")
|
||||
|
||||
local ast = require("ast")
|
||||
local Nil = ast.Nil
|
||||
|
||||
return prefix {
|
||||
parse = function(self, source, str, limit_pattern)
|
||||
local source_start = source:clone()
|
||||
local escaped = escape(self.operator)
|
||||
|
||||
local sright = source:consume(str:match("^("..escaped..")(.*)$"))
|
||||
local s, right, rem = pcall(expression_to_ast, source, sright, limit_pattern, self.priority)
|
||||
if not s then
|
||||
return self:build_ast(Nil:new()):set_source(source_start), sright
|
||||
else
|
||||
return self:build_ast(right):set_source(source_start), rem
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
local prefix = require("parser.expression.primary.prefix.prefix")
|
||||
local prefix_maybe_nil_right = require("parser.expression.primary.prefix.prefix_maybe_nil_right")
|
||||
|
||||
local ast = require("ast")
|
||||
local Return = ast.Return
|
||||
|
||||
local operator_priority = require("common").operator_priority
|
||||
|
||||
return prefix {
|
||||
return prefix_maybe_nil_right {
|
||||
operator = "@",
|
||||
priority = operator_priority["@_"],
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue