diff options
Diffstat (limited to 'script-beta/src/parser/parse.lua')
-rw-r--r-- | script-beta/src/parser/parse.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/script-beta/src/parser/parse.lua b/script-beta/src/parser/parse.lua new file mode 100644 index 00000000..bbc01b10 --- /dev/null +++ b/script-beta/src/parser/parse.lua @@ -0,0 +1,45 @@ +local ast = require 'parser.ast' + +return function (self, lua, mode, version) + local errs = {} + local diags = {} + local state = { + version = version, + lua = lua, + emmy = {}, + root = {}, + errs = errs, + diags = diags, + pushError = function (err) + if err.finish < err.start then + err.finish = err.start + end + local last = errs[#errs] + if last then + if last.start <= err.start and last.finish >= err.finish then + return + end + end + err.level = err.level or 'error' + errs[#errs+1] = err + return err + end, + pushDiag = function (code, info) + if not diags[code] then + diags[code] = {} + end + diags[code][#diags[code]+1] = info + end + } + ast.init(state) + local suc, res, err = xpcall(self.grammar, debug.traceback, self, lua, mode) + ast.close() + if not suc then + return nil, res + end + if not res then + state.pushError(err) + end + state.ast = res + return state +end |