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

Changed a few things

- Bumped to 0.15.0
- Add boot script
- Change variable definition syntax, using a = to distinguish more cleary between identifier and value
- Variables initial values are evaluated on first use instead of at parsing time
- Error on variable redefinition. Means you should make sure to load saves after your scripts.
- Improve string parsing, support for escape codes
- Remove support for number literals with empty decimal part (42. for 42.0) as there's no distinction in Anselme and it conflicts with .function call suffix
- Changed priority of : pair operator
- Add type type, and type annotations to variables and function parameters
- Change Lua function system to use regular Anselme functions
  - Defining a function from Lua is now way simpler and require providing a full Anselme function signature
- Change Anselme function system
  - Dynamic dispatch, based on arity, type annotation and parameter names. Will select the most specific function at runtime.
  - Define way to overload most operators
  - Allow custom type to text formatters
  - Allow assignment to custom functions
  - Index operator ( renamed to ()
  - Functions with parameters each have their own private namespace (scoping ersatz)
  - Internal: "custom"-mode operators now have their own expression AST type instead of cluttering the function system
- Remove static type checker as it is barely useful with new function system. May or may not rewrite one in the future.
- Improve error messages here and there
- Internal: cleaning
This commit is contained in:
Étienne Fildadut 2021-06-03 15:29:25 +02:00
parent 4b139019c9
commit 64bc85741a
86 changed files with 2096 additions and 1012 deletions

View file

@ -1,5 +1,5 @@
local eval
local truthy, merge_state, to_lua, eval_text, escape
local truthy, merge_state, to_lua, eval_text, escape, get_variable
local tags = {
--- push new tags on top of the stack, from Anselme values
@ -135,9 +135,11 @@ local function run_line(state, line)
end
end
elseif line.type == "checkpoint" then
local reached, reachede = get_variable(state, line.namespace.."🏁")
if not reached then return nil, reachede end
state.variables[line.namespace.."🏁"] = {
type = "number",
value = state.variables[line.namespace.."🏁"].value + 1
value = reached.value + 1
}
state.variables[line.parent_function.namespace.."🔖"] = {
type = "string",
@ -179,17 +181,23 @@ run_block = function(state, block, resume_from_there, i, j)
-- (and we want this to be done after executing the checkpoint block anyway)
if block.parent_line and block.parent_line.type == "checkpoint" then
local parent_line = block.parent_line
local reached, reachede = get_variable(state, parent_line.namespace.."🏁")
if not reached then return nil, reachede end
local seen, seene = get_variable(state, parent_line.namespace.."👁️")
if not seen then return nil, seene end
local checkpoint, checkpointe = get_variable(state, parent_line.parent_function.namespace.."🔖")
if not checkpoint then return nil, checkpointe end
state.variables[parent_line.namespace.."👁️"] = {
type = "number",
value = state.variables[parent_line.namespace.."👁️"].value + 1
value = seen.value + 1
}
state.variables[parent_line.namespace.."🏁"] = {
type = "number",
value = state.variables[parent_line.namespace.."🏁"].value + 1
value = reached.value + 1
}
-- don't update checkpoint if an already more precise checkpoint is set
-- (since we will go up the whole checkpoint hierarchy when resuming from a nested checkpoint)
local current_checkpoint = state.variables[parent_line.parent_function.namespace.."🔖"].value
local current_checkpoint = checkpoint.value
if not current_checkpoint:match("^"..escape(parent_line.name)) then
state.variables[parent_line.parent_function.namespace.."🔖"] = {
type = "string",
@ -272,7 +280,7 @@ local interpreter = {
package.loaded[...] = interpreter
eval = require((...):gsub("interpreter$", "expression"))
local common = require((...):gsub("interpreter$", "common"))
truthy, merge_state, to_lua, eval_text = common.truthy, common.merge_state, common.to_lua, common.eval_text
truthy, merge_state, to_lua, eval_text, get_variable = common.truthy, common.merge_state, common.to_lua, common.eval_text, common.get_variable
escape = require((...):gsub("interpreter%.interpreter$", "parser.common")).escape
return interpreter