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

dart.lua (1899B)


  1. -- Copyright 2013-2024 Mitchell. See LICENSE.
  2. -- Dart LPeg lexer.
  3. -- Written by Brian Schott (@Hackerpilot on Github).
  4. local lexer = require('lexer')
  5. local token, word_match = lexer.token, lexer.word_match
  6. local P, S = lpeg.P, lpeg.S
  7. local lex = lexer.new('dart')
  8. -- Whitespace.
  9. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  10. -- Keywords.
  11. lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
  12. 'assert', 'break', 'case', 'catch', 'class', 'const', 'continue', 'default', 'do', 'else', 'enum',
  13. 'extends', 'false', 'final', 'finally', 'for', 'if', 'in', 'is', 'new', 'null', 'rethrow',
  14. 'return', 'super', 'switch', 'this', 'throw', 'true', 'try', 'var', 'void', 'while', 'with'
  15. }))
  16. -- Built-ins.
  17. lex:add_rule('builtin', token(lexer.CONSTANT, word_match{
  18. 'abstract', 'as', 'dynamic', 'export', 'external', 'factory', 'get', 'implements', 'import',
  19. 'library', 'operator', 'part', 'set', 'static', 'typedef'
  20. }))
  21. -- Strings.
  22. local sq_str = S('r')^-1 * lexer.range("'", true)
  23. local dq_str = S('r')^-1 * lexer.range('"', true)
  24. local tq_str = S('r')^-1 * (lexer.range("'''") + lexer.range('"""'))
  25. lex:add_rule('string', token(lexer.STRING, tq_str + sq_str + dq_str))
  26. -- Identifiers.
  27. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  28. -- Comments.
  29. local line_comment = lexer.to_eol('//', true)
  30. local block_comment = lexer.range('/*', '*/', false, false, true)
  31. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  32. -- Numbers.
  33. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  34. -- Operators.
  35. lex:add_rule('operator', token(lexer.OPERATOR, S('#?=!<>+-*$/%&|^~.,;()[]{}')))
  36. -- Annotations.
  37. lex:add_rule('annotation', token(lexer.ANNOTATION, '@' * lexer.word^1))
  38. -- Fold points.
  39. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  40. lex:add_fold_point(lexer.COMMENT, '/*', '*/')
  41. lexer.property['scintillua.comment'] = '//'
  42. return lex