1 -- Copyright 2016-2017 David B. Lamkins <david@lamkins.net>. See LICENSE.
2 -- Protocol Buffer IDL LPeg lexer.
3 -- <https://developers.google.com/protocol-buffers/>
5 local l
= require('lexer')
6 local token
, word_match
= l
.token
, l
.word_match
7 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
9 local M
= {_NAME
= 'protobuf'}
12 local ws
= token(l
.WHITESPACE
, l
.space^
1)
15 local line_comment
= '//' * l
.nonnewline_esc^
0
16 local block_comment
= '/*' * (l
.any
- '*/')^
0 * P('*/')^
-1
17 local comment
= token(l
.COMMENT
, line_comment
+ block_comment
)
20 local sq_str
= P('L')^
-1 * l
.delimited_range("'", true)
21 local dq_str
= P('L')^
-1 * l
.delimited_range('"', true)
22 local string = token(l
.STRING
, sq_str
+ dq_str
)
25 local number = token(l
.NUMBER
, l
.float
+ l
.integer
)
28 local keyword
= token(l
.KEYWORD
, word_match
{
29 'contained', 'syntax', 'import', 'option', 'package', 'message', 'group',
30 'oneof', 'optional', 'required', 'repeated', 'default', 'extend',
31 'extensions', 'to', 'max', 'reserved', 'service', 'rpc', 'returns'
35 local type = token(l
.TYPE
, word_match
{
36 'int32', 'int64', 'uint32', 'uint64', 'sint32', 'sint64', 'fixed32',
37 'fixed64', 'sfixed32', 'sfixed64', 'float', 'double', 'bool', 'string',
38 'bytes', 'enum', 'true', 'false'
42 local identifier
= token(l
.IDENTIFIER
, l
.word
)
45 local operator
= token(l
.OPERATOR
, S('<>=|;,.()[]{}'))
51 {'identifier', identifier
},
55 {'operator', operator
},