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

smalltalk.lua (1246B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Smalltalk 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('smalltalk')
  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. 'true false nil self super isNil not Smalltalk Transcript')))
  12. -- Types.
  13. lex:add_rule('type', token(lexer.TYPE, word_match(
  14. 'Date Time Boolean True False Character String Array Symbol Integer Object')))
  15. -- Identifiers.
  16. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  17. -- Strings.
  18. local sq_str = lexer.range("'")
  19. local word_str = '$' * lexer.word
  20. lex:add_rule('string', token(lexer.STRING, sq_str + word_str))
  21. -- Comments.
  22. lex:add_rule('comment', token(lexer.COMMENT, lexer.range('"', false, false)))
  23. -- Numbers.
  24. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  25. -- Operators.
  26. lex:add_rule('operator', token(lexer.OPERATOR, S(':=_<>+-/*!()[]')))
  27. -- Labels.
  28. lex:add_rule('label', token(lexer.LABEL, '#' * lexer.word))
  29. -- Fold points.
  30. lex:add_fold_point(lexer.OPERATOR, '[', ']')
  31. lexer.property['scintillua.comment'] = '"|"'
  32. return lex