mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Add stdlib frFR translation
This commit is contained in:
parent
67c952bc21
commit
85d17e9519
6 changed files with 159 additions and 13 deletions
|
|
@ -11,6 +11,7 @@ local uuid = require("anselme.common").uuid
|
|||
local parser = require("anselme.parser")
|
||||
local binser = require("anselme.lib.binser")
|
||||
local assert0 = require("anselme.common").assert0
|
||||
local operator_priority = require("anselme.common").operator_priority
|
||||
local anselme
|
||||
local Identifier, Return, Node
|
||||
|
||||
|
|
@ -40,8 +41,29 @@ State = class {
|
|||
|
||||
--- Load standard library.
|
||||
-- You will probably want to call this on every State right after creation.
|
||||
load_stdlib = function(self)
|
||||
require("anselme.stdlib")(self)
|
||||
load_stdlib = function(self, language)
|
||||
local stdlib = require("anselme.stdlib")
|
||||
if language then
|
||||
self.scope:push_export()
|
||||
self.scope:push()
|
||||
stdlib(self)
|
||||
self.scope:pop()
|
||||
local exported = self.scope:capture()
|
||||
self.scope:pop()
|
||||
|
||||
for name, var in exported.variables:iter(self) do
|
||||
if operator_priority[name.name] then
|
||||
self.scope:define(var:get_symbol(), var:get(self))
|
||||
end
|
||||
end
|
||||
|
||||
self.scope:push_partial(Identifier:new("stdlib"))
|
||||
self.scope:define(Identifier:new("stdlib"):to_symbol(), exported)
|
||||
parser(require("anselme.stdlib.language."..language), "stdlib/language/"..language..".ans"):eval(self)
|
||||
self.scope:pop()
|
||||
else
|
||||
stdlib(self)
|
||||
end
|
||||
end,
|
||||
|
||||
---## Branching and merging
|
||||
|
|
|
|||
43
anselme/stdlib/environment.lua
Normal file
43
anselme/stdlib/environment.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
local ast = require("anselme.ast")
|
||||
local Nil, Boolean, Definition = ast.Nil, ast.Boolean, ast.Definition
|
||||
local assert0 = require("anselme.common").assert0
|
||||
|
||||
return {
|
||||
{
|
||||
"defined", "(c::is environment, s::is string, search parent::is boolean=false)",
|
||||
function(state, env, s, l)
|
||||
if l:truthy() then
|
||||
return Boolean:new(env:defined(state, s:to_identifier()))
|
||||
else
|
||||
return Boolean:new(env:defined_in_current(state, s:to_identifier()))
|
||||
end
|
||||
end
|
||||
},
|
||||
|
||||
{
|
||||
"_._", "(c::is environment, s::is string)",
|
||||
function(state, env, s)
|
||||
local identifier = s:to_identifier()
|
||||
assert0(env:defined(state, identifier), ("no variable %q defined in environment"):format(s.string))
|
||||
return env:get(state, identifier)
|
||||
end
|
||||
},
|
||||
{
|
||||
"_._", "(c::is environment, s::is string) = v",
|
||||
function(state, env, s, v)
|
||||
local identifier = s:to_identifier()
|
||||
assert0(env:defined(state, identifier), ("no variable %q defined in environment"):format(s.string))
|
||||
env:set(state, identifier, v)
|
||||
return Nil:new()
|
||||
end
|
||||
},
|
||||
{
|
||||
"_._", "(c::is environment, s::is symbol) = v",
|
||||
function(state, env, s, v)
|
||||
state.scope:push(env)
|
||||
local r = Definition:new(s, v):eval(state)
|
||||
state.scope:pop()
|
||||
return r
|
||||
end
|
||||
},
|
||||
}
|
||||
|
|
@ -4,15 +4,13 @@ local assert0 = require("anselme.common").assert0
|
|||
|
||||
return {
|
||||
{
|
||||
"defined", "(c::is function, s::is string)",
|
||||
function(state, c, s)
|
||||
return Boolean:new(c.scope:defined_in_current(state, s:to_identifier()))
|
||||
end
|
||||
},
|
||||
{
|
||||
"has upvalue", "(c::is function, s::is string)",
|
||||
function(state, c, s)
|
||||
"defined", "(c::is function, s::is string, search parent::is boolean=false)",
|
||||
function(state, c, s, l)
|
||||
if l:truthy() then
|
||||
return Boolean:new(c.scope:defined(state, s:to_identifier()))
|
||||
else
|
||||
return Boolean:new(c.scope:defined_in_current(state, s:to_symbol()))
|
||||
end
|
||||
end
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ local parser = require("anselme.parser")
|
|||
|
||||
local function define_lua(state, list)
|
||||
for _, fn in ipairs(list) do
|
||||
state.scope:define_lua(fn[1], fn[2], fn[3], true)
|
||||
state.scope:define_lua("@"..fn[1], fn[2], fn[3], true)
|
||||
end
|
||||
end
|
||||
local function load(state, l)
|
||||
|
|
@ -32,6 +32,7 @@ return function(main_state)
|
|||
"structures",
|
||||
"wrap",
|
||||
"attached block",
|
||||
"environment",
|
||||
"function",
|
||||
"resume",
|
||||
"persist",
|
||||
|
|
|
|||
80
anselme/stdlib/language/frFR.lua
Normal file
80
anselme/stdlib/language/frFR.lua
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
return [[
|
||||
:@bloc attaché = stdlib.attached block
|
||||
|
||||
:@afficher = stdlib.print
|
||||
:@hash = stdlib.hash
|
||||
:@erreur = stdlib.error
|
||||
|
||||
:@type = stdlib.type
|
||||
|
||||
:@vrai = stdlib.true
|
||||
:@faux = stdlib.false
|
||||
|
||||
:@défini = stdlib.defined
|
||||
:@surcharge = stdlib.overload
|
||||
|
||||
:@si = stdlib.if
|
||||
:@sinon = stdlib.else
|
||||
:@sinon si = stdlib.else if
|
||||
:@tant que = stdlib.while
|
||||
:@pour = stdlib.for
|
||||
:@itérer = stdlib.iter
|
||||
:@intervalle = stdlib.range
|
||||
|
||||
:@casser = stdlib.break
|
||||
:@continuer = stdlib.continue
|
||||
:@renvoyer = stdlib.return
|
||||
|
||||
:@longueur = stdlib.len
|
||||
:@contient = stdlib.has
|
||||
:@trouver = stdlib.find
|
||||
:@insérer = stdlib.insert
|
||||
:@retirer = stdlib.remove
|
||||
|
||||
:@vers struct = stdlib.to struct
|
||||
:@vers tuple = stdlib.to tuple
|
||||
:@vers châine = stdlib.to string
|
||||
|
||||
:@depuis = stdlib.from
|
||||
:@cible de reprise = stdlib.resume target
|
||||
:@en reprise = stdlib.resuming
|
||||
|
||||
:@script = stdlib.script
|
||||
:@suivant = stdlib.next
|
||||
:@cycle = stdlib.cycle
|
||||
:@aléatoire = stdlib.random
|
||||
|
||||
:@nom = stdlib.name
|
||||
:@valeur = stdlib.value
|
||||
|
||||
:@pi = stdlib.pi
|
||||
:@supérieur = stdlib.ceil
|
||||
:@inférieur = stdlib.floor
|
||||
:@arrondi = stdlib.round
|
||||
:@aléatoire = stdlib.rand
|
||||
|
||||
:@égal = stdlib.equal
|
||||
:@est = stdlib.is
|
||||
:@est une ancre = stdlib.is anchor
|
||||
:@est un booléen = stdlib.is boolean
|
||||
:@est appelable = stdlib.is callable
|
||||
:@est une fonction = stdlib.is function
|
||||
:@est une liste = stdlib.is list
|
||||
:@est un dictionnaire = stdlib.is map
|
||||
:@est nul = stdlib.is nil
|
||||
:@est un nombre = stdlib.is number
|
||||
:@est une surcharge = stdlib.is overload
|
||||
:@est une paire = stdlib.is pair
|
||||
:@est un intervalle = stdlib.is range
|
||||
:@est une séquence = stdlib.is sequence
|
||||
:@est une chaîne = stdlib.is string
|
||||
:@est une struct = stdlib.is struct
|
||||
:@est un symbole = stdlib.is symbol
|
||||
:@est une table = stdlib.is table
|
||||
:@est un texte = stdlib.is text
|
||||
:@est un tuple = stdlib.is tuple
|
||||
:@est un environnement = stdlib.is environment
|
||||
|
||||
:@fusionner branche = stdlib.merge branch
|
||||
:@persister = stdlib.persist
|
||||
]]
|
||||
|
|
@ -20,7 +20,9 @@ return [[
|
|||
:@is struct = is("struct")
|
||||
:@is table = is("table")
|
||||
|
||||
:@is environment = is("environment")
|
||||
|
||||
:@is function = is("function")
|
||||
:@is overload = is("overload")
|
||||
:@is callable = $(x) x!type == "overload" | x!type == "function" | x!type == "lua function" | x!type == "quote"
|
||||
:@is callable = $(x) x!type == "overload" | x!type == "function" | x!type == "quote"
|
||||
]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue