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

protobuf.lua (1576B)


  1. -- Copyright 2016-2024 David B. Lamkins <david@lamkins.net>. See LICENSE.
  2. -- Protocol Buffer IDL LPeg lexer.
  3. -- <https://developers.google.com/protocol-buffers/>
  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('protobuf')
  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. 'contained', 'syntax', 'import', 'option', 'package', 'message', 'group', 'oneof', 'optional',
  13. 'required', 'repeated', 'default', 'extend', 'extensions', 'to', 'max', 'reserved', 'service',
  14. 'rpc', 'returns'
  15. }))
  16. -- Types.
  17. lex:add_rule('type', token(lexer.TYPE, word_match{
  18. 'int32', 'int64', 'uint32', 'uint64', 'sint32', 'sint64', 'fixed32', 'fixed64', 'sfixed32',
  19. 'sfixed64', 'float', 'double', 'bool', 'string', 'bytes', 'enum', 'true', 'false'
  20. }))
  21. -- Strings.
  22. local sq_str = P('L')^-1 * lexer.range("'", true)
  23. local dq_str = P('L')^-1 * lexer.range('"', true)
  24. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
  25. -- Identifiers.
  26. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  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. -- Operators.
  34. lex:add_rule('operator', token(lexer.OPERATOR, S('<>=|;,.()[]{}')))
  35. lexer.property['scintillua.comment'] = '//'
  36. return lex