logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

haskell.lua (1470B)


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