aboutsummaryrefslogtreecommitdiff
path: root/parser.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-09-14 14:38:59 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-09-14 14:39:10 -0700
commit31f593fb097fcf31a07fb6e1a5d501904cabcb28 (patch)
tree357c0f73994cbe65b9c330f03a2268b59527ee12 /parser.lua
parent54e1f99e90764570666d692dd97be888f98ee2fc (diff)
Removing the remnants of the old parser system.
Diffstat (limited to 'parser.lua')
-rw-r--r--parser.lua143
1 files changed, 0 insertions, 143 deletions
diff --git a/parser.lua b/parser.lua
deleted file mode 100644
index 5eed3be..0000000
--- a/parser.lua
+++ /dev/null
@@ -1,143 +0,0 @@
-local lpeg = require('lpeg')
-local re = require('re')
-lpeg.setmaxstack(20000)
-local P, R, S, C, Cmt, Carg
-P, R, S, C, Cmt, Carg = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cmt, lpeg.Carg
-local match, sub
-do
- local _obj_0 = string
- match, sub = _obj_0.match, _obj_0.sub
-end
-local insert, remove
-do
- local _obj_0 = table
- insert, remove = _obj_0.insert, _obj_0.remove
-end
-local files = require('files')
-local NomsuCode, LuaCode, Source
-do
- local _obj_0 = require("code_obj")
- NomsuCode, LuaCode, Source = _obj_0.NomsuCode, _obj_0.LuaCode, _obj_0.Source
-end
-local AST = require("syntax_tree")
-local NOMSU_DEFS
-do
- local _with_0 = { }
- _with_0.nl = P("\r") ^ -1 * P("\n")
- _with_0.ws = S(" \t")
- _with_0.tonumber = tonumber
- _with_0.table = function()
- return { }
- end
- _with_0.unpack = unpack or table.unpack
- local string_escapes = {
- n = "\n",
- t = "\t",
- b = "\b",
- a = "\a",
- v = "\v",
- f = "\f",
- r = "\r"
- }
- local digit, hex = R('09'), R('09', 'af', 'AF')
- _with_0.escaped_char = (P("\\") * S("xX") * C(hex * hex)) / function(self)
- return string.char(tonumber(self, 16))
- end
- _with_0.escaped_char = _with_0.escaped_char + ((P("\\") * C(digit * (digit ^ -2))) / function(self)
- return string.char(tonumber(self))
- end)
- _with_0.escaped_char = _with_0.escaped_char + ((P("\\") * C(S("ntbavfr"))) / string_escapes)
- _with_0.operator_char = S("'`~!@$^&*+=|<>?/-")
- _with_0.utf8_char = (R("\194\223") * R("\128\191") + R("\224\239") * R("\128\191") * R("\128\191") + R("\240\244") * R("\128\191") * R("\128\191") * R("\128\191"))
- _with_0.ident_char = R("az", "AZ", "09") + P("_") + _with_0.utf8_char
- _with_0.userdata = Carg(1)
- _with_0.add_comment = function(src, end_pos, start_pos, comment, userdata)
- userdata.comments[start_pos] = comment
- return true
- end
- _with_0.error = function(src, end_pos, start_pos, err_msg, userdata)
- local seen_errors = userdata.errors
- if seen_errors[start_pos] then
- return true
- end
- local num_errors = 0
- for _ in pairs(seen_errors) do
- num_errors = num_errors + 1
- end
- if num_errors >= 10 then
- seen_errors[start_pos + 1] = colored.bright(colored.yellow(colored.onred("Too many errors, canceling parsing...")))
- return #src + 1
- end
- local err_pos = start_pos
- local line_no = files.get_line_number(src, err_pos)
- local prev_line = line_no == 1 and nil or files.get_line(src, line_no - 1)
- local err_line = files.get_line(src, line_no)
- local next_line = files.get_line(src, line_no + 1)
- local i = err_pos - files.get_line_starts(src)[line_no]
- local j = i + (end_pos - start_pos)
- local pointer = ("-"):rep(i) .. "^"
- err_msg = colored.bright(colored.yellow(colored.onred((err_msg or "Parse error") .. " at " .. tostring(userdata.source.filename) .. ":" .. tostring(line_no) .. ":")))
- if prev_line then
- err_msg = err_msg .. ("\n" .. colored.dim(prev_line))
- end
- if err_line then
- err_line = colored.white(err_line:sub(1, i)) .. colored.bright(colored.red(err_line:sub(i + 1, j + 1))) .. colored.dim(err_line:sub(j + 2, -1))
- err_msg = err_msg .. "\n" .. tostring(err_line) .. "\n" .. tostring(colored.red(pointer))
- end
- if next_line then
- err_msg = err_msg .. ("\n" .. colored.dim(next_line))
- end
- seen_errors[start_pos] = err_msg
- return true
- end
- NOMSU_DEFS = _with_0
-end
-setmetatable(NOMSU_DEFS, {
- __index = function(self, key)
- local make_node
- make_node = function(start, value, stop, userdata)
- if userdata.source then
- do
- local _with_0 = userdata.source
- value.source = Source(_with_0.filename, _with_0.start + start - 1, _with_0.start + stop - 1)
- end
- end
- setmetatable(value, AST[key])
- if value.__init then
- value:__init()
- end
- return value
- end
- self[key] = make_node
- return make_node
- end
-})
-local Parser = {
- version = 4,
- patterns = { }
-}
-Parser.is_operator = function(s)
- return not not (NOMSU_DEFS.operator_char ^ 1 * -1):match(s)
-end
-Parser.is_identifier = function(s)
- return not not (NOMSU_DEFS.ident_char ^ 1 * -1):match(s)
-end
-local inline_escaper = re.compile("{~ (%utf8_char / ('\"' -> '\\\"') / ('\n' -> '\\n') / ('\t' -> '\\t') / ('\b' -> '\\b') / ('\a' -> '\\a') / ('\v' -> '\\v') / ('\f' -> '\\f') / ('\r' -> '\\r') / ('\\' -> '\\\\') / ([^ -~] -> escape) / .)* ~}", {
- utf8_char = NOMSU_DEFS.utf8_char,
- escape = (function(self)
- return ("\\%03d"):format(self:byte())
- end)
-})
-Parser.inline_escape = function(s)
- return inline_escaper:match(s)
-end
-local escaper = re.compile("{~ (%utf8_char / ('\\' -> '\\\\') / [\n\r\t -~] / (. -> escape))* ~}", {
- utf8_char = NOMSU_DEFS.utf8_char,
- escape = (function(self)
- return ("\\%03d"):format(self:byte())
- end)
-})
-Parser.escape = function(s)
- return escaper:match(s)
-end
-return Parser