diff options
| author | Karl Schultheisz <kdsch@protonmail.com> | 2020-01-21 21:27:11 -0500 |
|---|---|---|
| committer | Karl Schultheisz <kdsch@protonmail.com> | 2020-01-21 21:27:11 -0500 |
| commit | 2d6150426fe825cd7b179c5c3ed648ae607be122 (patch) | |
| tree | 72d0d8be0c235900736ef0b89fe4770d98c5e1c9 /lua/lexers | |
| parent | cb03746137bc23f3c1b485088fefb9d4feffa368 (diff) | |
| parent | 30cd60cc2b2babda36ab752396df58697e9f26fd (diff) | |
| download | vis-2d6150426fe825cd7b179c5c3ed648ae607be122.tar.gz vis-2d6150426fe825cd7b179c5c3ed648ae607be122.tar.xz | |
Merge branch 'master' into add-layout-option
Diffstat (limited to 'lua/lexers')
| -rw-r--r-- | lua/lexers/bash.lua | 2 | ||||
| -rw-r--r-- | lua/lexers/fennel.lua | 88 | ||||
| -rw-r--r-- | lua/lexers/text.lua | 9 |
3 files changed, 98 insertions, 1 deletions
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/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 |
