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

boo.lua (2458B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Boo 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('boo')
  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', 'cast', 'continue', 'elif', 'else', 'ensure', 'except', 'for', 'given', 'goto',
  12. 'if', 'in', 'isa', 'is', 'not', 'or', 'otherwise', 'pass', 'raise', 'ref', 'try', 'unless',
  13. 'when', 'while',
  14. -- Definitions.
  15. 'abstract', 'callable', 'class', 'constructor', 'def', 'destructor', 'do', 'enum', 'event',
  16. 'final', 'get', 'interface', 'internal', 'of', 'override', 'partial', 'private', 'protected',
  17. 'public', 'return', 'set', 'static', 'struct', 'transient', 'virtual', 'yield',
  18. -- Namespaces.
  19. 'as', 'from', 'import', 'namespace',
  20. -- Other.
  21. 'self', 'super', 'null', 'true', 'false'
  22. }))
  23. -- Types.
  24. lex:add_rule('type', token(lexer.TYPE, word_match{
  25. 'bool', 'byte', 'char', 'date', 'decimal', 'double', 'duck', 'float', 'int', 'long', 'object',
  26. 'operator', 'regex', 'sbyte', 'short', 'single', 'string', 'timespan', 'uint', 'ulong', 'ushort'
  27. }))
  28. -- Functions.
  29. lex:add_rule('function', token(lexer.FUNCTION, word_match{
  30. 'array', 'assert', 'checked', 'enumerate', '__eval__', 'filter', 'getter', 'len', 'lock', 'map',
  31. 'matrix', 'max', 'min', 'normalArrayIndexing', 'print', 'property', 'range', 'rawArrayIndexing',
  32. 'required', '__switch__', 'typeof', 'unchecked', 'using', 'yieldAll', 'zip'
  33. }))
  34. -- Identifiers.
  35. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  36. -- Strings.
  37. local sq_str = lexer.range("'", true)
  38. local dq_str = lexer.range('"', true)
  39. local tq_str = lexer.range('"""')
  40. local string = token(lexer.STRING, tq_str + sq_str + dq_str)
  41. local regex_str = lexer.after_set('!%^&*([{-=+|:;,?<>~', lexer.range('/', true))
  42. local regex = token(lexer.REGEX, regex_str)
  43. lex:add_rule('string', string + regex)
  44. -- Comments.
  45. local line_comment = lexer.to_eol('#', true)
  46. local block_comment = lexer.range('/*', '*/')
  47. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  48. -- Numbers.
  49. lex:add_rule('number', token(lexer.NUMBER, lexer.number * (S('msdhsfFlL') + 'ms')^-1))
  50. -- Operators.
  51. lex:add_rule('operator', token(lexer.OPERATOR, S('!%^&*()[]{}-=+/|:;.,?<>~`')))
  52. lexer.property['scintillua.comment'] = '#'
  53. return lex