1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-28 00:59:31 +00:00
anselme/parser/expression/primary/text.lua

25 lines
683 B
Lua

local string = require("parser.expression.primary.string")
local ast = require("ast")
local TextInterpolation, Translatable = ast.TextInterpolation, ast.Translatable
return string {
type = "text",
start_pattern = "|%s?",
stop_char = "|",
allow_implicit_stop = true,
interpolation = TextInterpolation,
parse = function(self, source, str, limit_pattern)
local start_source = source:clone()
local interpolation, rem = string.parse(self, source, str, limit_pattern)
-- restore | when chaining with a choice operator
if rem:match("^>") then
rem = "|" .. rem
source:increment(-1)
end
return Translatable:new(interpolation):set_source(start_source), rem
end
}