aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Schultheisz <kdsch@protonmail.com>2020-03-03 09:11:21 -0500
committerKarl Schultheisz <kdsch@protonmail.com>2020-03-03 09:11:21 -0500
commit34f13978633d6bb63fb843e86b72ed13117386c9 (patch)
tree91d9a5f372fba25bcdfe3d333fe7654fae0e1952
parentdc5c1166abc29b6634649eb9872908acdc18c52e (diff)
downloadvis-34f13978633d6bb63fb843e86b72ed13117386c9.tar.gz
vis-34f13978633d6bb63fb843e86b72ed13117386c9.tar.xz
Add Elm lexer
-rw-r--r--lua/lexers/elm.lua64
-rw-r--r--lua/plugins/filetype.lua3
2 files changed, 67 insertions, 0 deletions
diff --git a/lua/lexers/elm.lua b/lua/lexers/elm.lua
new file mode 100644
index 0000000..796fc93
--- /dev/null
+++ b/lua/lexers/elm.lua
@@ -0,0 +1,64 @@
+-- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
+-- Elm LPeg lexer
+-- Modified by Alex Suraci.
+-- Adapted from Haskell LPeg lexer by Karl Schultheisz.
+
+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 = 'elm'}
+
+-- Whitespace.
+local ws = token(l.WHITESPACE, l.space^1)
+
+-- Comments.
+local line_comment = '--' * l.nonnewline_esc^0
+local block_comment = '{-' * (l.any - '-}')^0 * P('-}')^-1
+local comment = token(l.COMMENT, line_comment + block_comment)
+
+-- Strings.
+local string = token(l.STRING, l.delimited_range('"'))
+
+-- Chars.
+local char = token(l.STRING, l.delimited_range("'", true))
+
+-- Numbers.
+local number = token(l.NUMBER, l.float + l.integer)
+
+-- Keywords.
+local keyword = token(l.KEYWORD, word_match{
+ 'if', 'then', 'else',
+ 'case', 'of',
+ 'let', 'in',
+ 'module', 'import', 'as', 'exposing',
+ 'type', 'alias',
+ 'port',
+})
+
+-- Identifiers.
+local word = (l.alnum + S("._'#"))^0
+local identifier = token(l.IDENTIFIER, (l.alpha + '_') * word)
+
+-- Operators.
+local op = l.punct - S('()[]{}')
+local operator = token(l.OPERATOR, op)
+
+-- Types & type constructors.
+local constructor = token(l.TYPE, (l.upper * word) + (P(":") * (op^1 - P(":"))))
+
+M._rules = {
+ {'whitespace', ws},
+ {'keyword', keyword},
+ {'type', constructor},
+ {'identifier', identifier},
+ {'string', string},
+ {'char', char},
+ {'comment', comment},
+ {'number', number},
+ {'operator', operator},
+}
+
+M._FOLDBYINDENTATION = true
+
+return M
diff --git a/lua/plugins/filetype.lua b/lua/plugins/filetype.lua
index 16d8cf0..c216a01 100644
--- a/lua/plugins/filetype.lua
+++ b/lua/plugins/filetype.lua
@@ -116,6 +116,9 @@ vis.ftdetect.filetypes = {
elixir = {
ext = { "%.ex$", "%.exs$" },
},
+ elm = {
+ ext = { "%.elm$" },
+ },
erlang = {
ext = { "%.erl$", "%.hrl$" },
},