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

fennel.lua (1699B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Fennel LPeg lexer.
  3. -- Contributed by Momohime Honda.
  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('fennel', {inherit = lexer.load('lua')})
  8. -- Whitespace.
  9. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  10. -- Keywords.
  11. lex:modify_rule('keyword', token(lexer.KEYWORD, word_match{
  12. '#', '%', '*', '+', '-', '->>', '->', '-?>>', '-?>', '..', '.', '//', '/', ':', '<=', '<', '=',
  13. '>=', '>', '?.', '^', '~=', 'λ', 'accumulate', 'and', 'band', 'bnot', 'bor', 'bxor', 'collect',
  14. 'comment', 'do', 'doto', 'each', 'eval-compiler', 'fn', 'for', 'global', 'hashfn', 'icollect',
  15. 'if', 'import-macros', 'include', 'lambda', 'length', 'let', 'local', 'lshift', 'lua', 'macro',
  16. 'macrodebug', 'macros', 'match', 'not', 'not=', 'or', 'partial', 'pick-args', 'pick-values',
  17. 'quote', 'require-macros', 'rshift', 'set', 'set-forcibly!', 'tset', 'values', 'var', 'when',
  18. 'while', 'with-open'
  19. }))
  20. -- Identifiers.
  21. local initial = lexer.alpha + S('|$%&#*+-/<=>?~^_λ!')
  22. local subsequent = initial + lexer.digit
  23. lex:modify_rule('identifier', token(lexer.IDENTIFIER, initial * subsequent^0 * P('#')^-1))
  24. -- Strings.
  25. local dq_str = lexer.range('"')
  26. local kw_str = lpeg.B(1 - subsequent) * ':' * subsequent^1
  27. lex:modify_rule('string', token(lexer.STRING, dq_str + kw_str))
  28. -- Comments.
  29. lex:modify_rule('comment', token(lexer.COMMENT, lexer.to_eol(';')))
  30. -- Ignore these rules.
  31. -- lex:modify_rule('longstring', P(false))
  32. lex:modify_rule('label', P(false))
  33. lex:modify_rule('operator', P(false))
  34. lexer.property['scintillua.comment'] = ';'
  35. return lex