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

objective_c.lua (2510B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Objective C 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('objective_c')
  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. -- From C.
  12. 'asm', 'auto', 'break', 'case', 'const', 'continue', 'default', 'do', 'else', 'extern', 'false',
  13. 'for', 'goto', 'if', 'inline', 'register', 'return', 'sizeof', 'static', 'switch', 'true',
  14. 'typedef', 'void', 'volatile', 'while', 'restrict', '_Bool', '_Complex', '_Pragma', '_Imaginary',
  15. -- Objective C.
  16. 'oneway', 'in', 'out', 'inout', 'bycopy', 'byref', 'self', 'super',
  17. -- Preprocessor directives.
  18. '@interface', '@implementation', '@protocol', '@end', '@private', '@protected', '@public',
  19. '@class', '@selector', '@encode', '@defs', '@synchronized', '@try', '@throw', '@catch',
  20. '@finally',
  21. -- Constants.
  22. 'TRUE', 'FALSE', 'YES', 'NO', 'NULL', 'nil', 'Nil', 'METHOD_NULL'
  23. }))
  24. -- Types.
  25. lex:add_rule('type', token(lexer.TYPE, word_match(
  26. 'apply_t id Class MetaClass Object Protocol retval_t SEL STR IMP BOOL TypedStream')))
  27. -- Strings.
  28. local sq_str = P('L')^-1 * lexer.range("'", true)
  29. local dq_str = P('L')^-1 * lexer.range('"', true)
  30. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  31. -- Identifiers.
  32. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  33. -- Comments.
  34. local line_comment = lexer.to_eol('//', true)
  35. local block_comment = lexer.range('/*', '*/')
  36. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  37. -- Numbers.
  38. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  39. -- Preprocessor.
  40. lex:add_rule('preprocessor',
  41. #lexer.starts_line('#') * token(lexer.PREPROCESSOR, '#' * S('\t ')^0 * word_match{
  42. 'define', 'elif', 'else', 'endif', 'error', 'if', 'ifdef', 'ifndef', 'import', 'include',
  43. 'line', 'pragma', 'undef', 'warning'
  44. }))
  45. -- Operators.
  46. lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}')))
  47. -- Fold symbols.
  48. lex:add_fold_point(lexer.PREPROCESSOR, 'region', 'endregion')
  49. lex:add_fold_point(lexer.PREPROCESSOR, 'if', 'endif')
  50. lex:add_fold_point(lexer.PREPROCESSOR, 'ifdef', 'endif')
  51. lex:add_fold_point(lexer.PREPROCESSOR, 'ifndef', 'endif')
  52. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  53. lex:add_fold_point(lexer.COMMENT, '/*', '*/')
  54. lexer.property['scintillua.comment'] = '//'
  55. return lex