mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Change format_priority to a method
This commit is contained in:
parent
d42b900388
commit
07cb44256c
23 changed files with 115 additions and 58 deletions
|
|
@ -35,7 +35,6 @@ ArgumentTuple = ast.abstract.Node {
|
||||||
assert(not self.assignment)
|
assert(not self.assignment)
|
||||||
self.arity = self.arity + 1
|
self.arity = self.arity + 1
|
||||||
self.assignment = val
|
self.assignment = val
|
||||||
self.format_priority = operator_priority["_=_"]
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_format = function(self, state, priority, ...)
|
_format = function(self, state, priority, ...)
|
||||||
|
|
@ -56,6 +55,13 @@ ArgumentTuple = ast.abstract.Node {
|
||||||
end
|
end
|
||||||
return s
|
return s
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
if self.assignment then
|
||||||
|
return operator_priority["_=_"]
|
||||||
|
else
|
||||||
|
return math.huge
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
for i=1, self.arity do
|
for i=1, self.arity do
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ local Assignment = ast.abstract.Node {
|
||||||
|
|
||||||
identifier = nil,
|
identifier = nil,
|
||||||
expression = nil,
|
expression = nil,
|
||||||
format_priority = operator_priority["_=_"],
|
|
||||||
|
|
||||||
init = function(self, identifier, expression)
|
init = function(self, identifier, expression)
|
||||||
self.identifier = identifier
|
self.identifier = identifier
|
||||||
|
|
@ -18,6 +17,9 @@ local Assignment = ast.abstract.Node {
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
return self.identifier:format(...).." = "..self.expression:format_right(...)
|
return self.identifier:format(...).." = "..self.expression:format_right(...)
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return operator_priority["_=_"]
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.identifier, ...)
|
fn(self.identifier, ...)
|
||||||
|
|
|
||||||
|
|
@ -19,26 +19,10 @@ Call = ast.abstract.Node {
|
||||||
|
|
||||||
func = nil,
|
func = nil,
|
||||||
arguments = nil, -- ArgumentTuple
|
arguments = nil, -- ArgumentTuple
|
||||||
format_priority = infix["_!"], -- often overwritten in :init
|
|
||||||
|
|
||||||
init = function(self, func, arguments)
|
init = function(self, func, arguments)
|
||||||
self.func = func
|
self.func = func
|
||||||
self.arguments = arguments
|
self.arguments = arguments
|
||||||
|
|
||||||
-- get priority: operators
|
|
||||||
if Identifier:is(self.func) then
|
|
||||||
local name, arity = self.func.name, self.arguments.arity
|
|
||||||
if infix[name] and arity == 2 then
|
|
||||||
self.format_priority = infix[name]
|
|
||||||
elseif prefix[name] and arity == 1 then
|
|
||||||
self.format_priority = prefix[name]
|
|
||||||
elseif suffix[name] and arity == 1 then
|
|
||||||
self.format_priority = suffix[name]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if self.arguments.assignment then
|
|
||||||
self.format_priority = operator_priority["_=_"]
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
|
|
@ -66,6 +50,22 @@ Call = ast.abstract.Node {
|
||||||
return self.func:format(...)..self.arguments:format(...) -- no need for format_right, we already handle the assignment priority here
|
return self.func:format(...)..self.arguments:format(...) -- no need for format_right, we already handle the assignment priority here
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
if Identifier:is(self.func) then
|
||||||
|
local name, arity = self.func.name, self.arguments.arity
|
||||||
|
if infix[name] and arity == 2 then
|
||||||
|
return infix[name]
|
||||||
|
elseif prefix[name] and arity == 1 then
|
||||||
|
return prefix[name]
|
||||||
|
elseif suffix[name] and arity == 1 then
|
||||||
|
return suffix[name]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if self.arguments.assignment then
|
||||||
|
return operator_priority["_=_"]
|
||||||
|
end
|
||||||
|
return operator_priority["_!"]
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.func, ...)
|
fn(self.func, ...)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ Choice = ast.abstract.Runtime {
|
||||||
|
|
||||||
text = nil,
|
text = nil,
|
||||||
func = nil,
|
func = nil,
|
||||||
format_priority = operator_priority["_|>_"],
|
|
||||||
|
|
||||||
init = function(self, text, func)
|
init = function(self, text, func)
|
||||||
self.text = text
|
self.text = text
|
||||||
|
|
@ -24,6 +23,9 @@ Choice = ast.abstract.Runtime {
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
return ("%s |> %s"):format(self.text:format(...), self.func:format_right(...))
|
return ("%s |> %s"):format(self.text:format(...), self.func:format_right(...))
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return operator_priority["_|>_"]
|
||||||
|
end,
|
||||||
|
|
||||||
build_event_data = function(self, state, event_buffer)
|
build_event_data = function(self, state, event_buffer)
|
||||||
local l = {
|
local l = {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ local Definition = ast.abstract.Node {
|
||||||
|
|
||||||
symbol = nil,
|
symbol = nil,
|
||||||
expression = nil,
|
expression = nil,
|
||||||
format_priority = operator_priority["_=_"],
|
|
||||||
|
|
||||||
init = function(self, symbol, expression)
|
init = function(self, symbol, expression)
|
||||||
self.symbol = symbol
|
self.symbol = symbol
|
||||||
|
|
@ -18,6 +17,9 @@ local Definition = ast.abstract.Node {
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
return self.symbol:format(...).." = "..self.expression:format_right(...)
|
return self.symbol:format(...).." = "..self.expression:format_right(...)
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return operator_priority["_=_"]
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.symbol, ...)
|
fn(self.symbol, ...)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ local VariableMetadata = ast.abstract.Runtime {
|
||||||
|
|
||||||
symbol = nil,
|
symbol = nil,
|
||||||
branched = nil,
|
branched = nil,
|
||||||
format_priority = operator_priority["_=_"],
|
|
||||||
|
|
||||||
init = function(self, state, symbol, value)
|
init = function(self, state, symbol, value)
|
||||||
self.symbol = symbol
|
self.symbol = symbol
|
||||||
|
|
@ -45,6 +44,10 @@ local VariableMetadata = ast.abstract.Runtime {
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
return ("%s=%s"):format(self.symbol:format(...), self.branched:format(...))
|
return ("%s=%s"):format(self.symbol:format(...), self.branched:format(...))
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return operator_priority["_=_"]
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.symbol, ...)
|
fn(self.symbol, ...)
|
||||||
fn(self.branched, ...)
|
fn(self.branched, ...)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ Function = Overloadable {
|
||||||
|
|
||||||
parameters = nil, -- ParameterTuple
|
parameters = nil, -- ParameterTuple
|
||||||
expression = nil,
|
expression = nil,
|
||||||
format_priority = operator_priority["$_"],
|
|
||||||
|
|
||||||
exports = nil, -- { [sym] = exp, ... }, exctracted from expression during :prepare
|
exports = nil, -- { [sym] = exp, ... }, exctracted from expression during :prepare
|
||||||
|
|
||||||
|
|
@ -29,6 +28,9 @@ Function = Overloadable {
|
||||||
return "$"..self.parameters:format(...).." "..self.expression:format_right(...)
|
return "$"..self.parameters:format(...).." "..self.expression:format_right(...)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return operator_priority["$_"]
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.parameters, ...)
|
fn(self.parameters, ...)
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,6 @@ FunctionParameter = ast.abstract.Node {
|
||||||
self.identifier = identifier
|
self.identifier = identifier
|
||||||
self.default = default
|
self.default = default
|
||||||
self.type_check = type_check
|
self.type_check = type_check
|
||||||
if default then
|
|
||||||
self.format_priority = operator_priority["_=_"]
|
|
||||||
elseif type_check then -- type_check has higher prio than assignment in any case
|
|
||||||
self.format_priority = operator_priority["_::_"]
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_format = function(self, state, prio, ...)
|
_format = function(self, state, prio, ...)
|
||||||
|
|
@ -30,6 +25,15 @@ FunctionParameter = ast.abstract.Node {
|
||||||
end
|
end
|
||||||
return s
|
return s
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
if self.default then
|
||||||
|
return operator_priority["_=_"]
|
||||||
|
elseif self.type_check then -- type_check has higher prio than assignment in any case
|
||||||
|
return operator_priority["_::_"]
|
||||||
|
else
|
||||||
|
return math.huge
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.identifier, ...)
|
fn(self.identifier, ...)
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ local List
|
||||||
List = ast.abstract.Runtime {
|
List = ast.abstract.Runtime {
|
||||||
type = "list",
|
type = "list",
|
||||||
|
|
||||||
format_priority = operator_priority["*_"],
|
|
||||||
|
|
||||||
-- note: yeah technically this isn't mutable, only .branched is
|
-- note: yeah technically this isn't mutable, only .branched is
|
||||||
|
|
||||||
-- note: this a Branched of Tuple, and we *will* forcefully mutate the tuples, so make sure to not disseminate any reference to them outside the List
|
-- note: this a Branched of Tuple, and we *will* forcefully mutate the tuples, so make sure to not disseminate any reference to them outside the List
|
||||||
|
|
@ -23,6 +21,9 @@ List = ast.abstract.Runtime {
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
return "*"..self.branched:format_right(...)
|
return "*"..self.branched:format_right(...)
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return operator_priority["*_"]
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.branched, ...)
|
fn(self.branched, ...)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ LuaFunction = ast.abstract.Runtime(Overloadable) {
|
||||||
|
|
||||||
parameters = nil, -- ParameterTuple
|
parameters = nil, -- ParameterTuple
|
||||||
func = nil, -- lua function
|
func = nil, -- lua function
|
||||||
format_priority = operator_priority["$_"],
|
|
||||||
|
|
||||||
init = function(self, parameters, func)
|
init = function(self, parameters, func)
|
||||||
self.parameters = parameters
|
self.parameters = parameters
|
||||||
|
|
@ -28,6 +27,9 @@ LuaFunction = ast.abstract.Runtime(Overloadable) {
|
||||||
return "$"..self.parameters:format(...).." <lua function>"
|
return "$"..self.parameters:format(...).." <lua function>"
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return operator_priority["$_"]
|
||||||
|
end,
|
||||||
|
|
||||||
compatible_with_arguments = function(self, state, args)
|
compatible_with_arguments = function(self, state, args)
|
||||||
return args:match_parameter_tuple(state, self.parameters)
|
return args:match_parameter_tuple(state, self.parameters)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ return ast.abstract.Runtime {
|
||||||
|
|
||||||
name = nil,
|
name = nil,
|
||||||
value = nil,
|
value = nil,
|
||||||
format_priority = operator_priority["_:_"],
|
|
||||||
|
|
||||||
init = function(self, name, value)
|
init = function(self, name, value)
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
@ -22,4 +21,7 @@ return ast.abstract.Runtime {
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
return ("%s:%s"):format(self.name:format(...), self.value:format(...))
|
return ("%s:%s"):format(self.name:format(...), self.value:format(...))
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return operator_priority["_:_"]
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ ParameterTuple = ast.abstract.Node {
|
||||||
insert_assignment = function(self, val) -- only for construction
|
insert_assignment = function(self, val) -- only for construction
|
||||||
self:insert(val)
|
self:insert(val)
|
||||||
self.assignment = true
|
self.assignment = true
|
||||||
self.format_priority = operator_priority["_=_"]
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_format = function(self, state, prio, ...)
|
_format = function(self, state, prio, ...)
|
||||||
|
|
@ -43,6 +42,12 @@ ParameterTuple = ast.abstract.Node {
|
||||||
end
|
end
|
||||||
return s
|
return s
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
if self.assignment then
|
||||||
|
return operator_priority["_=_"]
|
||||||
|
end
|
||||||
|
return math.huge
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
for _, e in ipairs(self.list) do
|
for _, e in ipairs(self.list) do
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ PartialScope = ast.abstract.Node {
|
||||||
self.expression = expression
|
self.expression = expression
|
||||||
self.definitions = {}
|
self.definitions = {}
|
||||||
self._identifiers = {}
|
self._identifiers = {}
|
||||||
self.format_priority = self.expression.format_priority
|
|
||||||
end,
|
end,
|
||||||
define = function(self, symbol, value) -- for construction only
|
define = function(self, symbol, value) -- for construction only
|
||||||
assert(not self.definitions[symbol], ("%s already defined in partial layer"):format(symbol))
|
assert(not self.definitions[symbol], ("%s already defined in partial layer"):format(symbol))
|
||||||
|
|
@ -36,6 +35,9 @@ PartialScope = ast.abstract.Node {
|
||||||
return self.expression:format(state, priority, indentation, ...)
|
return self.expression:format(state, priority, indentation, ...)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return self.expression:format_priority()
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.expression, ...)
|
fn(self.expression, ...)
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,14 @@ Quote = ast.abstract.Node {
|
||||||
|
|
||||||
init = function(self, expression)
|
init = function(self, expression)
|
||||||
self.expression = expression
|
self.expression = expression
|
||||||
self.format_priority = expression.format_priority
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
return self.expression:format(...) -- Quote is generated transparently by operators
|
return self.expression:format(...) -- Quote is generated transparently by operators
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return self.expression:format_priority()
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.expression, ...)
|
fn(self.expression, ...)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ Return = ast.abstract.Node {
|
||||||
type = "return",
|
type = "return",
|
||||||
|
|
||||||
expression = nil,
|
expression = nil,
|
||||||
format_priority = operator_priority["@_"],
|
|
||||||
|
|
||||||
init = function(self, expression)
|
init = function(self, expression)
|
||||||
self.expression = expression
|
self.expression = expression
|
||||||
|
|
@ -16,6 +15,9 @@ Return = ast.abstract.Node {
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
return ("@%s"):format(self.expression:format_right(...))
|
return ("@%s"):format(self.expression:format_right(...))
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return operator_priority["@_"]
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.expression, ...)
|
fn(self.expression, ...)
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,14 @@ local ReturnBoundary = ast.abstract.Node {
|
||||||
|
|
||||||
init = function(self, expression)
|
init = function(self, expression)
|
||||||
self.expression = expression
|
self.expression = expression
|
||||||
self.format_priority = self.expression.format_priority
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
return self.expression:format(...)
|
return self.expression:format(...)
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return self.expression:format_priority()
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.expression, ...)
|
fn(self.expression, ...)
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,14 @@ local StringInterpolation = ast.abstract.Node {
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_format = function(self, ...)
|
_format = function(self, state, prio, ...)
|
||||||
local l = {}
|
local l = {}
|
||||||
for _, e in ipairs(self.list) do
|
for _, e in ipairs(self.list) do
|
||||||
if String:is(e) then
|
if String:is(e) then
|
||||||
local t = e.string:gsub("\\", "\\\\"):gsub("\n", "\\n"):gsub("\t", "\\t"):gsub("\"", "\\\"")
|
local t = e.string:gsub("\\", "\\\\"):gsub("\n", "\\n"):gsub("\t", "\\t"):gsub("\"", "\\\"")
|
||||||
table.insert(l, t)
|
table.insert(l, t)
|
||||||
else
|
else
|
||||||
table.insert(l, ("{%s}"):format(e:format(...)))
|
table.insert(l, ("{%s}"):format(e:format(state, 0, ...)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ("\"%s\""):format(table.concat(l))
|
return ("\"%s\""):format(table.concat(l))
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,6 @@ Symbol = ast.abstract.Node {
|
||||||
self.alias = modifiers.alias
|
self.alias = modifiers.alias
|
||||||
self.confined_to_branch = modifiers.confined_to_branch
|
self.confined_to_branch = modifiers.confined_to_branch
|
||||||
self.exported = modifiers.exported
|
self.exported = modifiers.exported
|
||||||
if self.type_check then
|
|
||||||
self.format_priority = operator_priority["_::_"]
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_eval = function(self, state)
|
_eval = function(self, state)
|
||||||
|
|
@ -66,6 +63,12 @@ Symbol = ast.abstract.Node {
|
||||||
end
|
end
|
||||||
return s
|
return s
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
if self.type_check then
|
||||||
|
return operator_priority["_::_"]
|
||||||
|
end
|
||||||
|
return math.huge
|
||||||
|
end,
|
||||||
|
|
||||||
to_lua = function(self, state)
|
to_lua = function(self, state)
|
||||||
return self.string
|
return self.string
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ local Table
|
||||||
Table = ast.abstract.Runtime {
|
Table = ast.abstract.Runtime {
|
||||||
type = "table",
|
type = "table",
|
||||||
|
|
||||||
format_priority = operator_priority["*_"],
|
|
||||||
|
|
||||||
-- note: technically this isn't mutable, only .branched is
|
-- note: technically this isn't mutable, only .branched is
|
||||||
|
|
||||||
-- note: this a Branched of Struct, and we *will* forcefully mutate the tuples, so make sure to not disseminate any reference to them outside the Table
|
-- note: this a Branched of Struct, and we *will* forcefully mutate the tuples, so make sure to not disseminate any reference to them outside the Table
|
||||||
|
|
@ -23,6 +21,9 @@ Table = ast.abstract.Runtime {
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
return "*"..self.branched:format_right(...)
|
return "*"..self.branched:format_right(...)
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
return operator_priority["*_"]
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.branched, ...)
|
fn(self.branched, ...)
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,14 @@ local TextInterpolation = ast.abstract.Node {
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_format = function(self, ...)
|
_format = function(self, state, prio, ...)
|
||||||
local l = {}
|
local l = {}
|
||||||
for _, e in ipairs(self.list) do
|
for _, e in ipairs(self.list) do
|
||||||
if String:is(e) then
|
if String:is(e) then
|
||||||
local t = e.string:gsub("\\", "\\\\"):gsub("\n", "\\n"):gsub("\t", "\\t"):gsub("\"", "\\\"")
|
local t = e.string:gsub("\\", "\\\\"):gsub("\n", "\\n"):gsub("\t", "\\t"):gsub("\"", "\\\"")
|
||||||
table.insert(l, t)
|
table.insert(l, t)
|
||||||
else
|
else
|
||||||
table.insert(l, ("{%s}"):format(e:format(...)))
|
table.insert(l, ("{%s}"):format(e:format(state, 0, ...)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ("| %s |"):format(table.concat(l))
|
return ("| %s |"):format(table.concat(l))
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ local translation_manager
|
||||||
|
|
||||||
local Translatable = ast.abstract.Node {
|
local Translatable = ast.abstract.Node {
|
||||||
type = "translatable",
|
type = "translatable",
|
||||||
format_priority = operator_priority["%_"],
|
|
||||||
|
|
||||||
expression = nil,
|
expression = nil,
|
||||||
|
|
||||||
|
|
@ -15,9 +14,6 @@ local Translatable = ast.abstract.Node {
|
||||||
self.expression = expression
|
self.expression = expression
|
||||||
self.context = ast.Struct:new()
|
self.context = ast.Struct:new()
|
||||||
self.context:set(String:new("source"), String:new(self.expression.source))
|
self.context:set(String:new("source"), String:new(self.expression.source))
|
||||||
if TextInterpolation:is(self.expression) then
|
|
||||||
self.format_priority = expression.format_priority
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
|
|
@ -27,6 +23,13 @@ local Translatable = ast.abstract.Node {
|
||||||
return "%"..self.expression:format_right(...)
|
return "%"..self.expression:format_right(...)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
_format_priority = function(self)
|
||||||
|
if TextInterpolation:is(self.expression) then
|
||||||
|
return self.expression:format_priority()
|
||||||
|
else
|
||||||
|
return operator_priority["%_"]
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
fn(self.expression, ...)
|
fn(self.expression, ...)
|
||||||
|
|
|
||||||
|
|
@ -257,9 +257,9 @@ Node = class {
|
||||||
indentation_level = indentation_level or 0
|
indentation_level = indentation_level or 0
|
||||||
parent_priority = parent_priority or 0
|
parent_priority = parent_priority or 0
|
||||||
|
|
||||||
local s = self:_format(state, self.format_priority, indentation_level)
|
local s = self:_format(state, self:format_priority(), indentation_level)
|
||||||
|
|
||||||
if self.format_priority < parent_priority then
|
if self:format_priority() < parent_priority then
|
||||||
s = ("(%s)"):format(s)
|
s = ("(%s)"):format(s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -273,9 +273,9 @@ Node = class {
|
||||||
indentation_level = indentation_level or 0
|
indentation_level = indentation_level or 0
|
||||||
parent_priority = parent_priority or 0
|
parent_priority = parent_priority or 0
|
||||||
|
|
||||||
local s = self:_format(state, self.format_priority, indentation_level)
|
local s = self:_format(state, self:format_priority(), indentation_level)
|
||||||
|
|
||||||
if self.format_priority <= parent_priority then
|
if self:format_priority() <= parent_priority then
|
||||||
s = ("(%s)"):format(s)
|
s = ("(%s)"):format(s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -288,9 +288,20 @@ Node = class {
|
||||||
_format = function(self, state, self_priority, identation)
|
_format = function(self, state, self_priority, identation)
|
||||||
error("format not implemented for "..self.type)
|
error("format not implemented for "..self.type)
|
||||||
end,
|
end,
|
||||||
-- priority of the node that will be used in :format to add eventually needed parentheses.
|
-- compute the priority of the node that will be used in :format to add eventually needed parentheses.
|
||||||
-- should not be modified after object construction!
|
-- should alwaus return the same value after object construction (will be cached anyway)
|
||||||
format_priority = math.huge, -- by default, assumes primary node, i.e. never wrap in parentheses
|
-- redefine _format_priority, not this function
|
||||||
|
format_priority = function(self)
|
||||||
|
if not self._format_priority_cache then
|
||||||
|
self._format_priority_cache = self:_format_priority()
|
||||||
|
end
|
||||||
|
return self._format_priority_cache
|
||||||
|
end,
|
||||||
|
-- redefine this to compute the priority, see :format_priority
|
||||||
|
_format_priority = function(self)
|
||||||
|
return math.huge -- by default, assumes primary node, i.e. never wrap in parentheses
|
||||||
|
end,
|
||||||
|
_format_priority_cache = nil, -- cached priority
|
||||||
|
|
||||||
-- return Lua value
|
-- return Lua value
|
||||||
-- this should probably be only called on a Node that is already evaluated
|
-- this should probably be only called on a Node that is already evaluated
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
• (c::($(x) <lua function>), s::($(x) <lua function>)) = v: expected 3 arguments, received 2
|
• (c::($(x) <lua function>), s::($(x) <lua function>)) = v: expected 3 arguments, received 2
|
||||||
• (c::($(x) <lua function>), s::($(x) <lua function>)): type check failure for parameter c in function (c::($(x) <lua function>), s::($(x) <lua function>))[0m
|
• (c::($(x) <lua function>), s::($(x) <lua function>)): type check failure for parameter c in function (c::($(x) <lua function>), s::($(x) <lua function>))[0m
|
||||||
↳ from [4mtest/tests/function separate variable from variants.ans:10:4[0m in call: [2mf . "a"[0m[0m
|
↳ from [4mtest/tests/function separate variable from variants.ans:10:4[0m in call: [2mf . "a"[0m[0m
|
||||||
↳ from [4mtest/tests/function separate variable from variants.ans:10:1[0m in text interpolation: [2m| {(f . "a")} = 2 |[0m[0m
|
↳ from [4mtest/tests/function separate variable from variants.ans:10:1[0m in text interpolation: [2m| {f . "a"} = 2 |[0m[0m
|
||||||
↳ from [4mtest/tests/function separate variable from variants.ans:10:1[0m in translatable: [2m| {(f . "a")} = 2 |[0m[0m
|
↳ from [4mtest/tests/function separate variable from variants.ans:10:1[0m in translatable: [2m| {f . "a"} = 2 |[0m[0m
|
||||||
↳ from [4m?[0m in block: [2m:f = ($() _)…[0m
|
↳ from [4m?[0m in block: [2m:f = ($() _)…[0m
|
||||||
--# saved #--
|
--# saved #--
|
||||||
{}
|
{}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue