diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-01-29 16:16:45 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-01-29 16:17:33 -0800 |
| commit | bc41cc3a244bf47679d1c47d17006a2aa7356bc8 (patch) | |
| tree | 102ec25b54f795d7a24648faa129f4dbccef3619 /nomsu_compiler.lua | |
| parent | febe7e82e06e1071c312f449b1ced319ef9a6932 (diff) | |
Switched to have colors/utf8 be optional, fixed an issue with currently
running files leaking when errors occurred (causing spurious circular
import errors), and improved tutorial.
Diffstat (limited to 'nomsu_compiler.lua')
| -rw-r--r-- | nomsu_compiler.lua | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua index 0cedd50..c9a15db 100644 --- a/nomsu_compiler.lua +++ b/nomsu_compiler.lua @@ -9,6 +9,7 @@ do local _obj_0 = require("code_obj") LuaCode, Source = _obj_0.LuaCode, _obj_0.Source end +require("text") local SyntaxTree = require("syntax_tree") local Files = require("files") local pretty_error = require("pretty_errors") @@ -20,6 +21,17 @@ fail_at = function(source, msg) source = source.source elseif type(source) == 'string' then source = Source:from_string(source) + else + assert(source.short_src and source.currentline) + file = Files.read(source.short_src) + assert(file, "Could not find " .. tostring(source.short_src)) + local lines = file:lines() + local start = 1 + for i = 1, source.currentline - 1 do + start = start + #lines[i] + end + local stop = start + #lines[source.currentline] + source = Source(source.short_src, start, stop) end if source and not file then file = Files.read(source.filename) |
