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

elm.lua (1368B)


  1. -- Copyright 2020-2024 Mitchell. See LICENSE.
  2. -- Elm LPeg lexer
  3. -- Adapted from Haskell LPeg lexer by Karl Schultheisz.
  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('elm', {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. 'if then else case of let in module import as exposing type alias port')))
  13. -- Types & type constructors.
  14. local word = (lexer.alnum + S("._'#"))^0
  15. local op = lexer.punct - S('()[]{}')
  16. lex:add_rule('type', token(lexer.TYPE, lexer.upper * word + ':' * (op^1 - ':')))
  17. -- Identifiers.
  18. lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * word))
  19. -- Strings.
  20. lex:add_rule('string', token(lexer.STRING, lexer.range('"')))
  21. -- Chars.
  22. lex:add_rule('character', token(lexer.STRING, lexer.range("'", true)))
  23. -- Comments.
  24. local line_comment = lexer.to_eol('--', true)
  25. local block_comment = lexer.range('{-', '-}', false, false, true)
  26. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  27. -- Numbers.
  28. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  29. -- Operators.
  30. lex:add_rule('operator', token(lexer.OPERATOR, op))
  31. lexer.property['scintillua.comment'] = '--'
  32. return lex