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

lisp.lua (2531B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Lisp LPeg lexer.
  3. local lexer = require('lexer')
  4. local token, word_match = lexer.token, lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('lisp')
  7. -- Whitespace.
  8. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  9. -- Keywords.
  10. lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
  11. 'defclass', 'defconstant', 'defgeneric', 'define-compiler-macro', 'define-condition',
  12. 'define-method-combination', 'define-modify-macro', 'define-setf-expander', 'define-symbol-macro',
  13. 'defmacro', 'defmethod', 'defpackage', 'defparameter', 'defsetf', 'defstruct', 'deftype', 'defun',
  14. 'defvar', --
  15. 'abort', 'assert', 'block', 'break', 'case', 'catch', 'ccase', 'cerror', 'cond', 'ctypecase',
  16. 'declaim', 'declare', 'do', 'do*', 'do-all-symbols', 'do-external-symbols', 'do-symbols',
  17. 'dolist', 'dotimes', 'ecase', 'error', 'etypecase', 'eval-when', 'flet', 'handler-bind',
  18. 'handler-case', 'if', 'ignore-errors', 'in-package', 'labels', 'lambda', 'let', 'let*', 'locally',
  19. 'loop', 'macrolet', 'multiple-value-bind', 'proclaim', 'prog', 'prog*', 'prog1', 'prog2', 'progn',
  20. 'progv', 'provide', 'require', 'restart-bind', 'restart-case', 'restart-name', 'return',
  21. 'return-from', 'signal', 'symbol-macrolet', 'tagbody', 'the', 'throw', 'typecase', 'unless',
  22. 'unwind-protect', 'when', 'with-accessors', 'with-compilation-unit', 'with-condition-restarts',
  23. 'with-hash-table-iterator', 'with-input-from-string', 'with-open-file', 'with-open-stream',
  24. 'with-output-to-string', 'with-package-iterator', 'with-simple-restart', 'with-slots',
  25. 'with-standard-io-syntax', --
  26. 't', 'nil'
  27. }))
  28. -- Identifiers.
  29. local word = lexer.alpha * (lexer.alnum + S('_-'))^0
  30. lex:add_rule('identifier', token(lexer.IDENTIFIER, word))
  31. -- Strings.
  32. lex:add_rule('string', token(lexer.STRING, "'" * word + lexer.range('"') + '#\\' * lexer.any))
  33. -- Comments.
  34. local line_comment = lexer.to_eol(';')
  35. local block_comment = lexer.range('#|', '|#')
  36. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  37. -- Numbers.
  38. lex:add_rule('number', token(lexer.NUMBER, P('-')^-1 * lexer.digit^1 * (S('./') * lexer.digit^1)^-1))
  39. -- Operators.
  40. lex:add_rule('operator', token(lexer.OPERATOR, S('<>=*/+-`@%()')))
  41. -- Fold points.
  42. lex:add_fold_point(lexer.OPERATOR, '(', ')')
  43. lex:add_fold_point(lexer.OPERATOR, '[', ']')
  44. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  45. lex:add_fold_point(lexer.COMMENT, '#|', '|#')
  46. lexer.property['scintillua.comment'] = ';'
  47. return lex