From 34f13978633d6bb63fb843e86b72ed13117386c9 Mon Sep 17 00:00:00 2001 From: Karl Schultheisz Date: Tue, 3 Mar 2020 09:11:21 -0500 Subject: Add Elm lexer --- lua/lexers/elm.lua | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ lua/plugins/filetype.lua | 3 +++ 2 files changed, 67 insertions(+) create mode 100644 lua/lexers/elm.lua (limited to 'lua') 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$" }, }, -- cgit v1.2.3