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

vala.lua (2156B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Vala 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('vala')
  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. 'class', 'delegate', 'enum', 'errordomain', 'interface', 'namespace', 'signal', 'struct', 'using',
  12. -- Modifiers.
  13. 'abstract', 'const', 'dynamic', 'extern', 'inline', 'out', 'override', 'private', 'protected',
  14. 'public', 'ref', 'static', 'virtual', 'volatile', 'weak',
  15. -- Other.
  16. 'as', 'base', 'break', 'case', 'catch', 'construct', 'continue', 'default', 'delete', 'do',
  17. 'else', 'ensures', 'finally', 'for', 'foreach', 'get', 'if', 'in', 'is', 'lock', 'new',
  18. 'requires', 'return', 'set', 'sizeof', 'switch', 'this', 'throw', 'throws', 'try', 'typeof',
  19. 'value', 'var', 'void', 'while',
  20. -- Etc.
  21. 'null', 'true', 'false'
  22. }))
  23. -- Types.
  24. lex:add_rule('type', token(lexer.TYPE, word_match{
  25. 'bool', 'char', 'double', 'float', 'int', 'int8', 'int16', 'int32', 'int64', 'long', 'short',
  26. 'size_t', 'ssize_t', 'string', 'uchar', 'uint', 'uint8', 'uint16', 'uint32', 'uint64', 'ulong',
  27. 'unichar', 'ushort'
  28. }))
  29. -- Identifiers.
  30. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  31. -- Strings.
  32. local sq_str = lexer.range("'", true)
  33. local dq_str = lexer.range('"', true)
  34. local tq_str = lexer.range('"""')
  35. local ml_str = '@' * lexer.range('"', false, false)
  36. lex:add_rule('string', token(lexer.STRING, tq_str + sq_str + dq_str + ml_str))
  37. -- Comments.
  38. local line_comment = lexer.to_eol('//', true)
  39. local block_comment = lexer.range('/*', '*/')
  40. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  41. -- Numbers.
  42. lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('uUlLfFdDmM')^-1))
  43. -- Operators.
  44. lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}')))
  45. -- Fold points.
  46. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  47. lex:add_fold_point(lexer.COMMENT, '/*', '*/')
  48. lexer.property['scintillua.comment'] = '//'
  49. return lex