Added more bindings and error tracebacks.

This commit is contained in:
2026-01-14 00:29:34 +00:00
parent 80ac2b7b37
commit 5a3c126100
6 changed files with 464 additions and 99 deletions

View File

@@ -3,7 +3,7 @@ require("parse")
-- TODO: This should really be a separate API and module
-- please break it out
-- Interpret some text
function interpret(content)
function interpret(content,uri,chain)
-- LOCALS
-- The pattern for words inbetween expressions
local expressionWordPattern = "(.*)"
@@ -26,8 +26,17 @@ function interpret(content)
consumeText,
consumeNumber
local baseExpression = Expression()
local consumer = Consumer(content)
local function expression(...)
return Expression(...):locate(
string.format(
"%i:%i",
consumer.row,
consumer.col
),uri)
end
local baseExpression = expression()
-- FUNCTIONS
-- Consume an expression, with its sub expressions
@@ -37,7 +46,7 @@ function interpret(content)
return function(words,_)
current:insert(words,consumer:consume({
[match] = function(words,_)
return Expression({"text",Expression({words})})
return expression({"text",Expression({words})})
end
}))
end
@@ -51,7 +60,7 @@ function interpret(content)
error("Incomplete string literal")
end,
[match] = function(words,_)
return Expression({"text",Expression({words})})
return expression({"text",Expression({words})})
end
}))
end
@@ -62,7 +71,7 @@ function interpret(content)
return function(words,_)
current:insert(words,consumer:consume({
["[\n\r]"] = function()
error("Incomplete URI literal")
current:error("Incomplete URI literal")
end,
[match] = function(path)
return read(path)
@@ -77,7 +86,7 @@ function interpret(content)
end
function consumeBlock()
local expressions = {}
local current = Expression()
local current = expression()
local loop = true
while loop do
local expr = consumer:consume({
@@ -94,7 +103,7 @@ function interpret(content)
error("Extravenous semicolon.")
end
table.insert(expressions,current)
current = Expression()
current = expression()
end,
[blockClosePattern] = function(words,_)
current:insert(words)
@@ -105,10 +114,10 @@ function interpret(content)
if #current.items ~= 0 then
table.insert(expressions,current)
end
return Expression(expressions)
return expression(expressions)
end
function consumeExpression()
local current = Expression()
local current = expression()
-- Loop, adding new expressions and words,
-- until closing that is
local loop = true
@@ -116,7 +125,7 @@ function interpret(content)
local remaining = consumer:remaining()
local expr = consumer:consume({
[uriOpenPattern] = URIMeal(current,uriClosePattern),
[expressionOpenPattern] = expressionMeal(remaining),
[expressionOpenPattern] = expressionMeal(current),
[multiLineStringOpenPattern] =
multiLineStringMeal(
current,multiLineStringClosePattern),