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

gap.lua (1344B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Gap 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('gap')
  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. 'and', 'break', 'continue', 'do', 'elif', 'else', 'end', 'fail', 'false', 'fi', 'for', 'function',
  12. 'if', 'in', 'infinity', 'local', 'not', 'od', 'or', 'rec', 'repeat', 'return', 'then', 'true',
  13. 'until', 'while'
  14. }))
  15. -- Identifiers.
  16. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  17. -- Strings.
  18. local sq_str = lexer.range("'", true)
  19. local dq_str = lexer.range('"', true)
  20. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  21. -- Comments.
  22. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
  23. -- Numbers.
  24. lex:add_rule('number', token(lexer.NUMBER, lexer.dec_num * -lexer.alpha))
  25. -- Operators.
  26. lex:add_rule('operator', token(lexer.OPERATOR, S('*+-,./:;<=>~^#()[]{}')))
  27. -- Fold points.
  28. lex:add_fold_point(lexer.KEYWORD, 'function', 'end')
  29. lex:add_fold_point(lexer.KEYWORD, 'do', 'od')
  30. lex:add_fold_point(lexer.KEYWORD, 'if', 'fi')
  31. lex:add_fold_point(lexer.KEYWORD, 'repeat', 'until')
  32. lexer.property['scintillua.comment'] = '#'
  33. return lex