From 6f9eb24acc5c1a8c83e544fbd810daeba3999956 Mon Sep 17 00:00:00 2001 From: Damian Gaweda Date: Sat, 7 Mar 2020 08:10:23 +0100 Subject: [PATCH] Add a basic mode for Cabal files (Haskell) --- bundles/basic_modes/lexers/cabal.lua | 53 +++++++++++++++++++++++ bundles/basic_modes/mode_definitions.moon | 6 +++ 2 files changed, 59 insertions(+) create mode 100644 bundles/basic_modes/lexers/cabal.lua diff --git a/bundles/basic_modes/lexers/cabal.lua b/bundles/basic_modes/lexers/cabal.lua new file mode 100644 index 000000000..5c397f01b --- /dev/null +++ b/bundles/basic_modes/lexers/cabal.lua @@ -0,0 +1,53 @@ +-- LPeg lexer for Cabal files (Haskell) + +local l = lexer +local token, word_match = l.token, l.word_match +local P, S = lpeg.P, lpeg.S + +local M = {_NAME = 'cabal'} + +-- Whitespace +local ws = token(l.WHITESPACE, l.space^1) + +-- Comments +local comment = token(l.COMMENT, '--' * l.nonnewline_esc^0) + +-- Strings +local string = token(l.STRING, l.delimited_range('"', '\\')) + +-- Chars +local char = token(l.STRING, l.delimited_range("'", "\\", false, false, '\n')) + +-- Numbers +local number = token(l.NUMBER, l.float + l.integer) + +-- Sections +local section = token(l.KEYWORD, word_match({ + 'executable', 'library', 'benchmark', 'test-suite', 'source-repository', 'flag', 'common' +},'-',true)) + +-- 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) + +-- Colon-delimited labels (e.g. main-is:) +local label = token(l.TYPE, word * P(":") * l.space^1) + +M._rules = { + {'whitespace', ws}, + {'keyword', section}, + {'type', label}, + {'identifier', identifier}, + {'string', string}, + {'char', char}, + {'comment', comment}, + {'number', number}, + {'operator', operator}, + {'any_char', l.any_char}, +} + +return M diff --git a/bundles/basic_modes/mode_definitions.moon b/bundles/basic_modes/mode_definitions.moon index 4abe9fd01..d497a0c5d 100644 --- a/bundles/basic_modes/mode_definitions.moon +++ b/bundles/basic_modes/mode_definitions.moon @@ -50,6 +50,12 @@ common_auto_pairs = { '"': '"' } + cabal: + extensions: 'cabal' + patterns: { 'cabal.config$', 'cabal.project$', 'cabal.project.local$', 'cabal.project.freeze$' } + comment_syntax: '--' + auto_pairs: common_auto_pairs + caml: extensions: { 'caml', 'ml', 'mli', 'mll', 'mly' } comment_syntax: { '(*', '*)' }