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

tcl.lua (1467B)


  1. -- Copyright 2014-2024 Joshua Krämer. See LICENSE.
  2. -- Tcl LPeg lexer.
  3. -- This lexer follows the TCL dodekalogue (http://wiki.tcl.tk/10259).
  4. -- It is based on the previous lexer by Mitchell.
  5. local lexer = require('lexer')
  6. local token, word_match = lexer.token, lexer.word_match
  7. local P, S = lpeg.P, lpeg.S
  8. local lex = lexer.new('tcl')
  9. -- Whitespace.
  10. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  11. -- Comment.
  12. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#' * P(function(input, index)
  13. local i = index - 2
  14. while i > 0 and input:find('^[ \t]', i) do i = i - 1 end
  15. if i < 1 or input:find('^[\r\n;]', i) then return true end
  16. end))))
  17. -- Separator (semicolon).
  18. lex:add_rule('separator', token(lexer.CLASS, ';'))
  19. -- Argument expander.
  20. lex:add_rule('expander', token(lexer.LABEL, '{*}'))
  21. -- Delimiters.
  22. lex:add_rule('braces', token(lexer.KEYWORD, S('{}')))
  23. lex:add_rule('quotes', token(lexer.FUNCTION, '"'))
  24. lex:add_rule('brackets', token(lexer.VARIABLE, S('[]')))
  25. -- Variable substitution.
  26. lex:add_rule('variable', token(lexer.STRING, '$' * (lexer.alnum + '_' + P(':')^2)^0))
  27. -- Backslash substitution.
  28. local oct = lexer.digit * lexer.digit^-2
  29. local hex = 'x' * lexer.xdigit^1
  30. local unicode = 'u' * lexer.xdigit * lexer.xdigit^-3
  31. lex:add_rule('backslash', token(lexer.TYPE, '\\' * (oct + hex + unicode + 1)))
  32. -- Fold points.
  33. lex:add_fold_point(lexer.KEYWORD, '{', '}')
  34. lexer.property['scintillua.comment'] = '#'
  35. return lex