mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-29 09:39:31 +00:00
Add parse_file and run_file to Lua API
This commit is contained in:
parent
bd93dc43dc
commit
8ff082625a
2 changed files with 22 additions and 2 deletions
|
|
@ -73,11 +73,19 @@ local anselme = {
|
|||
-- Usage:
|
||||
-- ```lua
|
||||
-- local ast = anselme.parse("1 + 2", "test")
|
||||
-- ast:eval()
|
||||
-- ast:eval(state)
|
||||
-- ```
|
||||
parse = function(code, source)
|
||||
return parser(code, source)
|
||||
end,
|
||||
--- Same as `:parse`, but read the code from a file.
|
||||
-- `source` will be set as the file path.
|
||||
parse_file = function(path)
|
||||
local f = assert(io.open(path, "r"))
|
||||
local block = parser(f:read("a"), path)
|
||||
f:close()
|
||||
return block
|
||||
end,
|
||||
--- Return a new [State](#state).
|
||||
new = function()
|
||||
return State:new()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue