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

idl.lua (1743B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- IDL 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('idl')
  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. 'abstract', 'attribute', 'case', 'const', 'context', 'custom', 'default', 'enum', 'exception',
  12. 'factory', 'FALSE', 'in', 'inout', 'interface', 'local', 'module', 'native', 'oneway', 'out',
  13. 'private', 'public', 'raises', 'readonly', 'struct', 'support', 'switch', 'TRUE', 'truncatable',
  14. 'typedef', 'union', 'valuetype'
  15. }))
  16. -- Types.
  17. lex:add_rule('type', token(lexer.TYPE, word_match{
  18. 'any', 'boolean', 'char', 'double', 'fixed', 'float', 'long', 'Object', 'octet', 'sequence',
  19. 'short', 'string', 'unsigned', 'ValueBase', 'void', 'wchar', 'wstring'
  20. }))
  21. -- Identifiers.
  22. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  23. -- Strings.
  24. local sq_str = lexer.range("'", true)
  25. local dq_str = lexer.range('"', true)
  26. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  27. -- Comments.
  28. local line_comment = lexer.to_eol('//', true)
  29. local block_comment = lexer.range('/*', '*/')
  30. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  31. -- Numbers.
  32. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  33. -- Preprocessor.
  34. lex:add_rule('preproc', token(lexer.PREPROCESSOR, lexer.starts_line('#') *
  35. word_match('define undef ifdef ifndef if elif else endif include warning pragma')))
  36. -- Operators.
  37. lex:add_rule('operator', token(lexer.OPERATOR, S('!<>=+-/*%&|^~.,:;?()[]{}')))
  38. lexer.property['scintillua.comment'] = '//'
  39. return lex