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

coffeescript.lua (1817B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- CoffeeScript LPeg lexer.
  3. local lexer = require('lexer')
  4. local word_match = lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('coffeescript', {fold_by_indentation = true})
  7. -- Whitespace.
  8. lex:add_rule('whitespace', lex:tag(lexer.WHITESPACE, lexer.space^1))
  9. -- Keywords.
  10. lex:add_rule('keyword', lex:tag(lexer.KEYWORD, word_match{
  11. 'all', 'and', 'bind', 'break', 'by', 'case', 'catch', 'class', 'const', 'continue', 'default',
  12. 'delete', 'do', 'each', 'else', 'enum', 'export', 'extends', 'false', 'finally', 'for',
  13. 'function', 'if', 'import', 'in', 'instanceof', 'is', 'isnt', 'let', 'loop', 'native', 'new',
  14. 'no', 'not', 'of', 'off', 'on', 'or', 'return', 'super', 'switch', 'then', 'this', 'throw',
  15. 'true', 'try', 'typeof', 'unless', 'until', 'var', 'void', 'when', 'while', 'with', 'yes'
  16. }))
  17. -- Fields: object properties and methods.
  18. lex:add_rule('field',
  19. lex:tag(lexer.FUNCTION, '.' * (S('_$') + lexer.alpha) * (S('_$') + lexer.alnum)^0))
  20. -- Identifiers.
  21. lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
  22. -- Strings.
  23. local sq_str = lexer.range("'")
  24. local dq_str = lexer.range('"')
  25. local string = lex:tag(lexer.STRING, sq_str + dq_str)
  26. local regex_str = lexer.after_set('+-*%<>!=^&|?~:;,([{', lexer.range('/', true) * S('igm')^0)
  27. local regex = lex:tag(lexer.REGEX, regex_str)
  28. lex:add_rule('string', string + regex)
  29. -- Comments.
  30. local block_comment = lexer.range('###')
  31. local line_comment = lexer.to_eol('#', true)
  32. lex:add_rule('comment', lex:tag(lexer.COMMENT, block_comment + line_comment))
  33. -- Numbers.
  34. lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number))
  35. -- Operators.
  36. lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;,.()[]{}')))
  37. lexer.property['scintillua.comment'] = '#'
  38. return lex