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

icon.lua (2255B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- LPeg lexer for the Icon programming language.
  3. -- http://www.cs.arizona.edu/icon
  4. -- Contributed by Carl Sturtivant.
  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('icon')
  9. -- Whitespace.
  10. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  11. -- Keywords.
  12. lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
  13. 'break', 'by', 'case', 'create', 'default', 'do', 'else', 'end', 'every', 'fail', 'global', 'if',
  14. 'initial', 'invocable', 'link', 'local', 'next', 'not', 'of', 'procedure', 'record', 'repeat',
  15. 'return', 'static', 'suspend', 'then', 'to', 'until', 'while'
  16. }))
  17. -- Icon Keywords: unique to Icon.
  18. lex:add_rule('special_keyword', token('special_keyword', '&' * word_match{
  19. 'allocated', 'ascii', 'clock', 'collections', 'cset', 'current', 'date', 'dateline', 'digits',
  20. 'dump', 'e', 'error', 'errornumber', 'errortext', 'errorvalue', 'errout', 'fail', 'features',
  21. 'file', 'host', 'input', 'lcase', 'letters', 'level', 'line', 'main', 'null', 'output', 'phi',
  22. 'pi', 'pos', 'progname', 'random', 'regions', 'source', 'storage', 'subject', 'time', 'trace',
  23. 'ucase', 'version'
  24. }))
  25. lex:add_style('special_keyword', lexer.styles.type)
  26. -- Identifiers.
  27. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  28. -- Strings.
  29. local sq_str = lexer.range("'")
  30. local dq_str = lexer.range('"')
  31. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  32. -- Comments.
  33. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#', true)))
  34. -- Numbers.
  35. local radix_literal = P('-')^-1 * lexer.dec_num * S('rR') * lexer.alnum^1
  36. lex:add_rule('number', token(lexer.NUMBER, radix_literal + lexer.number))
  37. -- Preprocessor.
  38. lex:add_rule('preproc', token(lexer.PREPROCESSOR, '$' *
  39. word_match('define else endif error ifdef ifndef include line undef')))
  40. -- Operators.
  41. lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>~!=^&|?~@:;,.()[]{}')))
  42. -- Fold points.
  43. lex:add_fold_point(lexer.PREPROCESSOR, 'ifdef', 'endif')
  44. lex:add_fold_point(lexer.PREPROCESSOR, 'ifndef', 'endif')
  45. lex:add_fold_point(lexer.KEYWORD, 'procedure', 'end')
  46. lexer.property['scintillua.comment'] = '#'
  47. return lex