2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """ Lexer for PPAPI IDL
8 The lexer uses the PLY library to build a tokenizer which understands both
9 WebIDL and Pepper tokens.
11 WebIDL, and WebIDL regular expressions can be found at:
12 http://www.w3.org/TR/2012/CR-WebIDL-20120419/
14 http://www.dabeaz.com/ply/
17 from idl_lexer
import IDLLexer
23 class IDLPPAPILexer(IDLLexer
):
26 # These need to be methods for lexer construction, despite not using self.
27 # pylint: disable=R0201
29 # Special multi-character operators
30 def t_LSHIFT(self
, t
):
34 def t_RSHIFT(self
, t
):
38 def t_INLINE(self
, t
):
39 r
'\#inline (.|\n)*?\#endinl.*'
40 self
.AddLines(t
.value
.count('\n'))
43 # Return a "preprocessor" inline block
45 IDLLexer
.__init
__(self
)
46 self
._AddTokens
(['INLINE', 'LSHIFT', 'RSHIFT'])
47 self
._AddKeywords
(['label', 'struct'])
50 self
._AddKeywords
(['char', 'int8_t', 'int16_t', 'int32_t', 'int64_t'])
51 self
._AddKeywords
(['uint8_t', 'uint16_t', 'uint32_t', 'uint64_t'])
52 self
._AddKeywords
(['double_t', 'float_t'])
55 self
._AddKeywords
(['handle_t', 'PP_FileHandle'])
57 # Add pointer types (void*, char*, const char*, const void*)
58 self
._AddKeywords
(['mem_t', 'str_t', 'cstr_t', 'interface_t'])
61 self
._DelKeywords
(['boolean', 'byte', 'Date', 'DOMString', 'double',
62 'float', 'long', 'object', 'octet', 'short', 'unsigned'])
65 # If run by itself, attempt to build the lexer
66 if __name__
== '__main__':
67 lexer
= IDLPPAPILexer()
68 lexer
.Tokenize(open('test_parser/inline_ppapi.idl').read())
69 for tok
in lexer
.GetTokens():