aboutsummaryrefslogtreecommitdiff
path: root/lexers/elixir.lua
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-12-07 16:49:29 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-12-07 20:11:32 +0100
commit3570869c9ae2c4df14b15423789919e514322916 (patch)
tree6b990c9ec59fbdc7abce89c1307d22e66d0fd88a /lexers/elixir.lua
parent098504f67aea8a862840d58c69e8f6360eef3073 (diff)
downloadvis-3570869c9ae2c4df14b15423789919e514322916.tar.gz
vis-3570869c9ae2c4df14b15423789919e514322916.tar.xz
Move all lua related files to lua/ subfolder
Also remove the lexers sub directory from the Lua search path. As a result we attempt to open fewer files during startup: $ strace -e open -o log ./vis +q config.h && wc -l log In order to avoid having to modifiy all lexers which `require('lexer')` we instead place a symlink in the top level directory. $ ./configure --disable-lua $ rm -rf lua Should result in a source tree with most lua specifc functionality removed.
Diffstat (limited to 'lexers/elixir.lua')
-rw-r--r--lexers/elixir.lua122
1 files changed, 0 insertions, 122 deletions
diff --git a/lexers/elixir.lua b/lexers/elixir.lua
deleted file mode 100644
index 5ec27c0..0000000
--- a/lexers/elixir.lua
+++ /dev/null
@@ -1,122 +0,0 @@
--- Copyright 2015-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
--- Contributed by Richard Philips.
--- Elixer LPeg lexer.
-
-local l = require('lexer')
-local token, style, color, word_match = l.token, l.style, l.color, l.word_match
-local B, P, R, S = lpeg.B, lpeg.P, lpeg.R, lpeg.S
-
-local M = {_NAME = 'elixir'}
-
--- Whitespace.
-local ws = token(l.WHITESPACE, l.space^1)
-
--- Comments.
-local comment = token(l.COMMENT, '#' * l.nonnewline_esc^0)
-
--- Strings.
-local dq_str = l.delimited_range('"', false)
-local triple_dq_str = '"""' * (l.any - '"""')^0 * P('"""')^-1
-local string = token(l.STRING, triple_dq_str + dq_str)
-
--- Numbers
-local dec = l.digit * (l.digit + P("_"))^0
-local bin = '0b' * S('01')^1
-local oct = '0o' * R('07')^1
-local integer = bin + l.hex_num + oct + dec
-local float = l.digit^1 * P(".") * l.digit^1 * S("eE") *
- (S('+-')^-1 * l.digit^1)^-1
-local number_token = B(1 - R('az', 'AZ', '__')) *
- (S('+-')^-1) * token(l.NUMBER, (float + integer))
-
--- Keywords.
-local keyword_token = token(l.KEYWORD, word_match{
- "is_atom", "is_binary", "is_bitstring", "is_boolean", "is_float",
- "is_function", "is_integer", "is_list", "is_map", "is_number", "is_pid",
- "is_port", "is_record", "is_reference", "is_tuple", "is_exception", "case",
- "when", "cond", "for", "if", "unless", "try", "receive", "send", "exit",
- "raise", "throw", "after", "rescue", "catch", "else", "do", "end", "quote",
- "unquote", "super", "import", "require", "alias", "use", "self", "with", "fn"
-})
-
--- Functions
-local function_token = token(l.FUNCTION, word_match{
- "defstruct", "defrecordp", "defrecord", "defprotocol", "defp",
- "defoverridable", "defmodule", "defmacrop", "defmacro", "defimpl",
- "defexception", "defdelegate", "defcallback", "def"
-})
-
--- Sigils
-local sigil11 = P("~") * S("CRSW") * l.delimited_range('<>', false, true)
-local sigil12 = P("~") * S("CRSW") * l.delimited_range('{}', false, true)
-local sigil13 = P("~") * S("CRSW") * l.delimited_range('[]', false, true)
-local sigil14 = P("~") * S("CRSW") * l.delimited_range('()', false, true)
-local sigil15 = P("~") * S("CRSW") * l.delimited_range('|', false, true)
-local sigil16 = P("~") * S("CRSW") * l.delimited_range('/', false, true)
-local sigil17 = P("~") * S("CRSW") * l.delimited_range('"', false, true)
-local sigil18 = P("~") * S("CRSW") * l.delimited_range("'", false, true)
-local sigil19 = P("~") * S("CRSW") * '"""' * (l.any - '"""')^0 * P('"""')^-1
-local sigil10 = P("~") * S("CRSW") * "'''" * (l.any - "'''")^0 * P("'''")^-1
-local sigil21 = P("~") * S("crsw") * l.delimited_range('<>', false, false)
-local sigil22 = P("~") * S("crsw") * l.delimited_range('{}', false, false)
-local sigil23 = P("~") * S("crsw") * l.delimited_range('[]', false, false)
-local sigil24 = P("~") * S("crsw") * l.delimited_range('()', false, false)
-local sigil25 = P("~") * S("crsw") * l.delimited_range('|', false, false)
-local sigil26 = P("~") * S("crsw") * l.delimited_range('/', false, false)
-local sigil27 = P("~") * S("crsw") * l.delimited_range('"', false, false)
-local sigil28 = P("~") * S("crsw") * l.delimited_range("'", false, false)
-local sigil29 = P("~") * S("csrw") * '"""' * (l.any - '"""')^0 * P('"""')^-1
-local sigil20 = P("~") * S("csrw") * "'''" * (l.any - "'''")^0 * P("'''")^-1
-local sigil_token = token(l.REGEX, sigil10 + sigil19 + sigil11 + sigil12 +
- sigil13 + sigil14 + sigil15 + sigil16 +
- sigil17 + sigil18 + sigil20 + sigil29 +
- sigil21 + sigil22 + sigil23 + sigil24 +
- sigil25 + sigil26 + sigil27 + sigil28)
-local sigiladdon_token = token(l.EMBEDDED, R('az', 'AZ')^0)
-
--- Attributes
-local attribute_token = token(l.LABEL, B(1 - R('az', 'AZ', '__')) * P('@') *
- R('az','AZ') * R('az','AZ','09','__')^0)
-
--- Booleans
-local boolean_token = token(l.NUMBER,
- P(':')^-1 * word_match{"true", "false", "nil"})
-
--- Identifiers
-local identifier = token(l.IDENTIFIER, R('az', '__') *
- R('az', 'AZ', '__', '09')^0 * S('?!')^-1)
-
--- Atoms
-local atom1 = B(1 - P(':')) * P(':') * dq_str
-local atom2 = B(1 - P(':')) * P(':') * R('az', 'AZ') *
- R('az', 'AZ', '__', '@@', '09')^0 * S('?!')^-1
-local atom3 = B(1 - R('az', 'AZ', '__', '09', '::')) *
- R('AZ') * R('az', 'AZ', '__', '@@', '09')^0 * S('?!')^-1
-local atom_token = token(l.CONSTANT, atom1 + atom2 + atom3)
-
--- Operators
-local operator1 = word_match{"and", "or", "not", "when", "xor", "in"}
-local operator2 = P('!==') + '!=' + '!' + '=~' + '===' + '==' + '=' + '<<<' +
- '<<' + '<=' + '<-' + '<' + '>>>' + '>>' + '>=' + '>' + '->' +
- '--' + '-' + '++' + '+' + '&&&' + '&&' + '&' + '|||' + '||' +
- '|>' + '|' + '..' + '.' + '^^^' + '^' + '\\\\' + '::' + '*' +
- '/' + '~~~' + '@'
-local operator_token = token(l.OPERATOR, operator1 + operator2)
-
-M._rules = {
- {'sigil', sigil_token * sigiladdon_token},
- {'atom', atom_token},
- {'string', string},
- {'comment', comment},
- {'attribute', attribute_token},
- {'boolean', boolean_token},
- {'function', function_token},
- {'keyword', keyword_token},
- {'operator', operator_token},
- {'identifier', identifier},
- {'number', number_token},
-}
-
-M._FOLDBYINDENTATION = true
-
-return M