vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

haskell.lua

(1426B)


      1 -- Copyright 2006-2025 Mitchell. See LICENSE.
      2 -- Haskell LPeg lexer.
      3 -- Modified by Alex Suraci.
      4 -- Migrated by Samuel Marquis.
      5 
      6 local lexer = lexer
      7 local P, S = lpeg.P, lpeg.S
      8 
      9 local lex = lexer.new(..., {fold_by_indentation = true})
     10 
     11 -- Keywords.
     12 lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD)))
     13 
     14 -- Types & type constructors.
     15 local word = (lexer.alnum + S("._'#"))^0
     16 local op = lexer.punct - S('()[]{}')
     17 lex:add_rule('type', lex:tag(lexer.TYPE, (lexer.upper * word) + (':' * (op^1 - ':'))))
     18 
     19 -- Identifiers.
     20 lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, (lexer.alpha + '_') * word))
     21 
     22 -- Strings.
     23 local sq_str = lexer.range("'", true)
     24 local dq_str = lexer.range('"')
     25 lex:add_rule('string', lex:tag(lexer.STRING, sq_str + dq_str))
     26 
     27 -- Comments.
     28 local line_comment = lexer.to_eol('--', true)
     29 local block_comment = lexer.range('{-', '-}')
     30 lex:add_rule('comment', lex:tag(lexer.COMMENT, line_comment + block_comment))
     31 
     32 -- Numbers.
     33 lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number))
     34 
     35 -- Operators.
     36 lex:add_rule('operator', lex:tag(lexer.OPERATOR, op))
     37 
     38 lexer.property['scintillua.comment'] = '--'
     39 
     40 -- Word lists.
     41 lex:set_word_list(lexer.KEYWORD, {
     42 	'case', 'class', 'data', 'default', 'deriving', 'do', 'else', 'if', 'import', 'in', 'infix',
     43 	'infixl', 'infixr', 'instance', 'let', 'module', 'newtype', 'of', 'then', 'type', 'where', '_',
     44 	'as', 'qualified', 'hiding'
     45 })
     46 
     47 return lex