Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a basic mode for Cabal files (Haskell) #557

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions bundles/basic_modes/lexers/cabal.lua
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions bundles/basic_modes/mode_definitions.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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: { '(*', '*)' }
Expand Down