mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
[stdlib] add tag(text, tags)
This commit is contained in:
parent
f2945d4478
commit
69da1ff223
4 changed files with 22 additions and 12 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
local class = require("anselme.lib.class")
|
local class = require("anselme.lib.class")
|
||||||
local ast = require("anselme.ast")
|
local ast = require("anselme.ast")
|
||||||
local Event, Runtime = ast.abstract.Event, ast.abstract.Runtime
|
local Event, Runtime = ast.abstract.Event, ast.abstract.Runtime
|
||||||
local ArgumentTuple
|
local ArgumentTuple, Struct
|
||||||
|
|
||||||
local to_anselme = require("anselme.common.to_anselme")
|
local to_anselme = require("anselme.common.to_anselme")
|
||||||
|
|
||||||
|
|
@ -29,7 +29,8 @@ TextEventData = class {
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
local Text = Runtime(Event) {
|
local Text
|
||||||
|
Text = Runtime(Event) {
|
||||||
type = "text",
|
type = "text",
|
||||||
|
|
||||||
list = nil, -- { { String, tag Struct }, ... }
|
list = nil, -- { { String, tag Struct }, ... }
|
||||||
|
|
@ -41,6 +42,17 @@ local Text = Runtime(Event) {
|
||||||
table.insert(self.list, { str, tags })
|
table.insert(self.list, { str, tags })
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
with_tags = function(self, tags)
|
||||||
|
local r = Text:new()
|
||||||
|
for _, e in ipairs(self.list) do
|
||||||
|
local t = Struct:new()
|
||||||
|
t:include(e[2])
|
||||||
|
t:include(tags)
|
||||||
|
self:insert(e[1], t)
|
||||||
|
end
|
||||||
|
return r
|
||||||
|
end,
|
||||||
|
|
||||||
traverse = function(self, fn, ...)
|
traverse = function(self, fn, ...)
|
||||||
for _, e in ipairs(self.list) do
|
for _, e in ipairs(self.list) do
|
||||||
fn(e[1], ...)
|
fn(e[1], ...)
|
||||||
|
|
@ -73,6 +85,6 @@ local Text = Runtime(Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
package.loaded[...] = Text
|
package.loaded[...] = Text
|
||||||
ArgumentTuple = ast.ArgumentTuple
|
ArgumentTuple, Struct = ast.ArgumentTuple, ast.Struct
|
||||||
|
|
||||||
return Text
|
return Text
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ local Translatable = ast.abstract.Node {
|
||||||
self.context = Struct:new()
|
self.context = Struct:new()
|
||||||
self.context:set(String:new("source"), String:new(self.expression.source))
|
self.context:set(String:new("source"), String:new(self.expression.source))
|
||||||
self.context:set(String:new("file"), String:new(self.expression.source:match("^([^%:]*)")))
|
self.context:set(String:new("file"), String:new(self.expression.source:match("^([^%:]*)")))
|
||||||
-- TODO: add parent script/function to context
|
-- TODO: add parent script/function name to context - should be more stable than source position
|
||||||
end,
|
end,
|
||||||
|
|
||||||
_format = function(self, ...)
|
_format = function(self, ...)
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@ return {
|
||||||
return Nil:new()
|
return Nil:new()
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"tag", "(txt::is text, tags::is struct)",
|
||||||
|
function(state, text, tags)
|
||||||
|
return text:with_tags(tags)
|
||||||
|
end
|
||||||
|
},
|
||||||
|
|
||||||
-- choice
|
-- choice
|
||||||
{
|
{
|
||||||
|
|
|
||||||
8
ideas.md
8
ideas.md
|
|
@ -9,14 +9,6 @@ Documentation:
|
||||||
* tutorial
|
* tutorial
|
||||||
* standard library
|
* standard library
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Standard library.
|
|
||||||
|
|
||||||
* Text and string manipulation would make sense, but that would require a full UTF-8/Unicode support library like https://github.com/starwing/luautf8. -> might favor bad practices for translation
|
|
||||||
- retag/add tags
|
|
||||||
* And in general, clean up everything.
|
|
||||||
|
|
||||||
# Can be done later
|
# Can be done later
|
||||||
|
|
||||||
Translation.
|
Translation.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue