aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/lexers/README.md3
-rw-r--r--lua/lexers/bash.lua2
-rw-r--r--lua/lexers/fennel.lua88
-rw-r--r--lua/lexers/html.lua13
-rw-r--r--lua/lexers/rc.lua2
-rw-r--r--lua/lexers/rest.lua2
-rw-r--r--lua/lexers/text.lua9
-rw-r--r--lua/lexers/wsf.lua8
-rw-r--r--lua/lexers/xml.lua8
-rw-r--r--lua/lexers/yaml.lua7
-rw-r--r--lua/plugins/filetype.lua13
-rw-r--r--lua/themes/solarized.lua4
12 files changed, 125 insertions, 34 deletions
diff --git a/lua/lexers/README.md b/lua/lexers/README.md
index 72fa67f..e97ea1f 100644
--- a/lua/lexers/README.md
+++ b/lua/lexers/README.md
@@ -2,7 +2,8 @@ Lua LPeg lexers for vis
=======================
Vis reuses the [Lua](http://www.lua.org/) [LPeg](http://www.inf.puc-rio.br/~roberto/lpeg/)
-based lexers from the [Scintillua](http://foicica.com/scintillua/) project.
+based lexers from the [Scintillua](http://foicica.com/scintillua/) project
+which is now part of the [Scintilla 3.x branch](https://foicica.com/hg/scintilla/file/tip/lexlua).
# Vis integration
diff --git a/lua/lexers/bash.lua b/lua/lexers/bash.lua
index 2fa72f2..207cb22 100644
--- a/lua/lexers/bash.lua
+++ b/lua/lexers/bash.lua
@@ -21,7 +21,7 @@ local heredoc = '<<' * P(function(input, index)
local s, e, _, delimiter =
input:find('%-?(["\']?)([%a_][%w_]*)%1[\n\r\f;]+', index)
if s == index and delimiter then
- local _, e = input:find('[\n\r\f]+'..delimiter, e)
+ local _, e = input:find('[\n\r\f]+'..delimiter..'\n', e)
return e and e + 1 or #input + 1
end
end)
diff --git a/lua/lexers/fennel.lua b/lua/lexers/fennel.lua
new file mode 100644
index 0000000..ee8127c
--- /dev/null
+++ b/lua/lexers/fennel.lua
@@ -0,0 +1,88 @@
+-- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
+-- Lua LPeg lexer.
+-- Original written by Peter Odding, 2007/04/04.
+
+local l = require('lexer')
+local token, word_match = l.token, l.word_match
+local P, R, S = lpeg.P, lpeg.R, lpeg.S
+
+local M = {_NAME = 'fennel'}
+
+-- Whitespace.
+local ws = token(l.WHITESPACE, l.space^1)
+
+-- Comments.
+local line_comment = ';' * l.nonnewline^0
+local comment = token(l.COMMENT, line_comment)
+
+-- Strings.
+local dq_str = l.delimited_range('"')
+local string = token(l.STRING, dq_str)
+
+-- Numbers.
+local lua_integer = P('-')^-1 * (l.hex_num + l.dec_num)
+local number = token(l.NUMBER, l.float + lua_integer)
+
+-- Keywords.
+local keyword = token(l.KEYWORD, word_match({
+ '%', '*', '+', '-', '->', '->>', '-?>', '-?>>', '.', '..', '/', '//', ':', '<', '<=', '=', '>', '>=', '^', '~=', 'λ',
+ 'and', 'comment', 'do', 'doc', 'doto', 'each', 'eval-compiler', 'fn', 'for', 'global', 'hashfn', 'if', 'include', 'lambda',
+ 'length', 'let', 'local', 'lua', 'macro', 'macros', 'match', 'not', 'not=', 'or', 'partial', 'quote', 'require-macros',
+ 'set', 'set-forcibly!', 'tset', 'values', 'var', 'when', 'while'
+}, "%*+-./:<=>?~^λ!"))
+
+-- Libraries.
+local library = token('library', word_match({
+ -- Coroutine.
+ 'coroutine', 'coroutine.create', 'coroutine.resume', 'coroutine.running',
+ 'coroutine.status', 'coroutine.wrap', 'coroutine.yield',
+ -- Module.
+ 'package', 'package.cpath', 'package.loaded', 'package.loadlib',
+ 'package.path', 'package.preload',
+ -- String.
+ 'string', 'string.byte', 'string.char', 'string.dump', 'string.find',
+ 'string.format', 'string.gmatch', 'string.gsub', 'string.len', 'string.lower',
+ 'string.match', 'string.rep', 'string.reverse', 'string.sub', 'string.upper',
+ -- Table.
+ 'table', 'table.concat', 'table.insert', 'table.remove', 'table.sort',
+ -- Math.
+ 'math', 'math.abs', 'math.acos', 'math.asin', 'math.atan', 'math.ceil',
+ 'math.cos', 'math.deg', 'math.exp', 'math.floor', 'math.fmod', 'math.huge',
+ 'math.log', 'math.max', 'math.min', 'math.modf', 'math.pi', 'math.rad',
+ 'math.random', 'math.randomseed', 'math.sin', 'math.sqrt', 'math.tan',
+ -- IO.
+ 'io', 'io.close', 'io.flush', 'io.input', 'io.lines', 'io.open', 'io.output',
+ 'io.popen', 'io.read', 'io.stderr', 'io.stdin', 'io.stdout', 'io.tmpfile',
+ 'io.type', 'io.write',
+ -- OS.
+ 'os', 'os.clock', 'os.date', 'os.difftime', 'os.execute', 'os.exit',
+ 'os.getenv', 'os.remove', 'os.rename', 'os.setlocale', 'os.time',
+ 'os.tmpname',
+ -- Debug.
+ 'debug', 'debug.debug', 'debug.gethook', 'debug.getinfo', 'debug.getlocal',
+ 'debug.getmetatable', 'debug.getregistry', 'debug.getupvalue',
+ 'debug.sethook', 'debug.setlocal', 'debug.setmetatable', 'debug.setupvalue',
+ 'debug.traceback',
+}, '.'))
+
+local initial = l.alpha + S"|$%&#*+-./:<=>?~^_λ!"
+local subsequent = initial + l.digit
+
+-- Identifiers.
+local identifier = token(l.IDENTIFIER, initial * subsequent^0)
+
+M._rules = {
+ {'whitespace', ws},
+ {'keyword', keyword},
+ {'library', library},
+ {'identifier', identifier},
+ {'string', string},
+ {'comment', comment},
+ {'number', number}
+}
+
+M._tokenstyles = {
+ library = l.STYLE_TYPE,
+}
+
+return M
diff --git a/lua/lexers/html.lua b/lua/lexers/html.lua
index 7d29881..ba6e3e2 100644
--- a/lua/lexers/html.lua
+++ b/lua/lexers/html.lua
@@ -21,18 +21,11 @@ local dq_str = l.delimited_range('"')
local string = #S('\'"') * l.last_char_includes('=') *
token(l.STRING, sq_str + dq_str)
--- TODO: performance is terrible on large files.
-local in_tag = P(function(input, index)
- local before = input:sub(1, index - 1)
- local s, e = before:find('<[^>]-$'), before:find('>[^<]-$')
- if s and e then return s > e and index or nil end
- if s then return index end
- return input:find('^[^<]->', index) and index or nil
-end)
+local in_tag = #P((1 - S'><')^0 * '>')
-- Numbers.
local number = #l.digit * l.last_char_includes('=') *
- token(l.NUMBER, l.digit^1 * P('%')^-1) --* in_tag
+ token(l.NUMBER, l.digit^1 * P('%')^-1) * in_tag
-- Elements.
local known_element = token('element', '<' * P('/')^-1 * word_match({
@@ -80,7 +73,7 @@ local attribute = (known_attribute + unknown_attribute) * #(l.space^0 * '=')
local tag_close = token('element', P('/')^-1 * '>')
-- Equals.
-local equals = token(l.OPERATOR, '=') --* in_tag
+local equals = token(l.OPERATOR, '=') * in_tag
-- Entities.
local entity = token('entity', '&' * (l.any - l.space - ';')^1 * ';')
diff --git a/lua/lexers/rc.lua b/lua/lexers/rc.lua
index fcf9ef0..3e61be8 100644
--- a/lua/lexers/rc.lua
+++ b/lua/lexers/rc.lua
@@ -31,7 +31,7 @@ local number = token(l.NUMBER, l.integer + l.float)
-- Keywords.
local keyword = token(l.KEYWORD, word_match({
- 'for', 'in', 'while', 'if', 'not', 'switch', 'fn',
+ 'for', 'in', 'while', 'if', 'not', 'switch', 'case', 'fn',
'builtin', 'cd', 'eval', 'exec', 'exit', 'flag', 'rfork', 'shift', 'ulimit',
'umask', 'wait', 'whatis', '.', '~',
}, '!"%*+,-./:?@[]~'))
diff --git a/lua/lexers/rest.lua b/lua/lexers/rest.lua
index 5a968dc..be5b839 100644
--- a/lua/lexers/rest.lua
+++ b/lua/lexers/rest.lua
@@ -28,7 +28,7 @@ local overline = lpeg.Cmt(starts_line(adornment), function(input, index, adm, c)
return #input + 1
end)
local underline = lpeg.Cmt(starts_line(adornment), function(_, index, adm, c)
- local pos = adm:match('^%'..c..'+()%s*$')
+ local pos = adm:match('^%'..c..'+%s*()$')
return pos and index - #adm + pos - 1 or nil
end)
-- Token needs to be a predefined one in order for folder to work.
diff --git a/lua/lexers/text.lua b/lua/lexers/text.lua
index 4988d95..cc41bfa 100644
--- a/lua/lexers/text.lua
+++ b/lua/lexers/text.lua
@@ -1,6 +1,15 @@
-- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
-- Text LPeg lexer.
+local l = require('lexer')
+
local M = {_NAME = 'text'}
+-- Whitespace.
+local ws = l.token(l.WHITESPACE, l.space^1)
+
+M._rules = {
+ {'whitespace', ws},
+}
+
return M
diff --git a/lua/lexers/wsf.lua b/lua/lexers/wsf.lua
index e00c363..37cb33e 100644
--- a/lua/lexers/wsf.lua
+++ b/lua/lexers/wsf.lua
@@ -20,13 +20,7 @@ local dq_str = l.delimited_range('"', false, true)
local string = #S('\'"') * l.last_char_includes('=') *
token(l.STRING, sq_str + dq_str)
-local in_tag = P(function(input, index)
- local before = input:sub(1, index - 1)
- local s, e = before:find('<[^>]-$'), before:find('>[^<]-$')
- if s and e then return s > e and index or nil end
- if s then return index end
- return input:find('^[^<]->', index) and index or nil
-end)
+local in_tag = #P((1 - S'><')^0 * '>')
-- Numbers.
local number = #l.digit * l.last_char_includes('=') *
diff --git a/lua/lexers/xml.lua b/lua/lexers/xml.lua
index d429ebb..e0098e5 100644
--- a/lua/lexers/xml.lua
+++ b/lua/lexers/xml.lua
@@ -20,13 +20,7 @@ local dq_str = l.delimited_range('"', false, true)
local string = #S('\'"') * l.last_char_includes('=') *
token(l.STRING, sq_str + dq_str)
-local in_tag = P(function(input, index)
- local before = input:sub(1, index - 1)
- local s, e = before:find('<[^>]-$'), before:find('>[^<]-$')
- if s and e then return s > e and index or nil end
- if s then return index end
- return input:find('^[^<]->', index) and index or nil
-end)
+local in_tag = #P((1 - S'><')^0 * '>')
-- Numbers.
local number = #l.digit * l.last_char_includes('=') *
diff --git a/lua/lexers/yaml.lua b/lua/lexers/yaml.lua
index 4ec85ea..7b22451 100644
--- a/lua/lexers/yaml.lua
+++ b/lua/lexers/yaml.lua
@@ -60,12 +60,7 @@ local word = (l.alpha + '-' * -l.space) * (l.alnum + '-')^0
-- Keys and literals.
local colon = S(' \t')^0 * ':' * (l.space + -1)
-local key = token(l.KEYWORD,
- #word * (l.nonnewline - colon)^1 * #colon *
- P(function(input, index)
- local line = input:sub(1, index - 1):match('[^\r\n]+$')
- return not line:find('[%w-]+:') and index
- end))
+local key = token(l.KEYWORD, (l.alnum + '_' + '-')^1 * #(':' * l.space))
local value = #word * (l.nonnewline - l.space^0 * S(',]}'))^1
local block = S('|>') * S('+-')^-1 * (l.newline + -1) * function(input, index)
local rest = input:sub(index)
diff --git a/lua/plugins/filetype.lua b/lua/plugins/filetype.lua
index 35912f6..cff073a 100644
--- a/lua/plugins/filetype.lua
+++ b/lua/plugins/filetype.lua
@@ -125,6 +125,9 @@ vis.ftdetect.filetypes = {
faust = {
ext = { "%.dsp$" },
},
+ fennel = {
+ ext = { "%.fnl$" },
+ },
fish = {
ext = { "%.fish$" },
},
@@ -385,6 +388,10 @@ vis.ftdetect.filetypes = {
texinfo = {
ext = { "%.texi$" },
},
+ text = {
+ ext = { "%.txt$" },
+ mime = { "text/plain" },
+ },
toml = {
ext = { "%.toml$" },
},
@@ -497,6 +504,12 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win)
end
end
+ -- try text lexer as a last resort
+ if (mime or 'text/plain'):match('^text/.+$') then
+ set_filetype('text', vis.ftdetect.filetypes.text)
+ return
+ end
+
win:set_syntax(nil)
end)
diff --git a/lua/themes/solarized.lua b/lua/themes/solarized.lua
index a5d4c4d..7f40858 100644
--- a/lua/themes/solarized.lua
+++ b/lua/themes/solarized.lua
@@ -27,6 +27,10 @@ local bg = ',back:'..colors.base03..','
-- light
-- local fg = ',fore:'..colors.base03..','
-- local bg = ',back:'..colors.base3..','
+-- solarized term
+-- local fg = ',fore:default,'
+-- local bg = ',back:default,'
+
lexers.STYLE_DEFAULT = bg..fg
lexers.STYLE_NOTHING = bg