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

io_lang.lua (1542B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Io 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('io_lang')
  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. 'block', 'method', 'while', 'foreach', 'if', 'else', 'do', 'super', 'self', 'clone', 'proto',
  12. 'setSlot', 'hasSlot', 'type', 'write', 'print', 'forward'
  13. }))
  14. -- Types.
  15. lex:add_rule('type', token(lexer.TYPE, word_match{
  16. 'Block', 'Buffer', 'CFunction', 'Date', 'Duration', 'File', 'Future', 'LinkedList', 'List', 'Map',
  17. 'Message', 'Nil', 'Nop', 'Number', 'Object', 'String', 'WeakLink'
  18. }))
  19. -- Identifiers.
  20. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  21. -- Strings.
  22. local sq_str = lexer.range("'")
  23. local dq_str = lexer.range('"')
  24. local tq_str = lexer.range('"""')
  25. lex:add_rule('string', token(lexer.STRING, tq_str + sq_str + dq_str))
  26. -- Comments.
  27. local line_comment = lexer.to_eol(P('#') + '//')
  28. local block_comment = lexer.range('/*', '*/')
  29. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  30. -- Numbers.
  31. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  32. -- Operators.
  33. lex:add_rule('operator', token(lexer.OPERATOR, S('`~@$%^&*-+/=\\<>?.,:;()[]{}')))
  34. -- Fold points.
  35. lex:add_fold_point(lexer.OPERATOR, '(', ')')
  36. lex:add_fold_point(lexer.COMMENT, '/*', '*/')
  37. lexer.property['scintillua.comment'] = '#'
  38. return lex