blob: a13c4e4ac95545a1efe914c1e3ed02ba8c8bac1e [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Lexer for PPAPI IDL
The lexer uses the PLY library to build a tokenizer which understands both
WebIDL and Pepper tokens.
WebIDL, and WebIDL regular expressions can be found at:
PLY can be found at:
from idl_lexer import IDLLexer
class IDLPPAPILexer(IDLLexer):
# Token definitions
# These need to be methods for lexer construction, despite not using self.
# pylint: disable=R0201
# Special multi-character operators
def t_LSHIFT(self, t):
return t
def t_RSHIFT(self, t):
return t
def t_INLINE(self, t):
r'\#inline (.|\n)*?\#endinl.*'
return t
# Return a "preprocessor" inline block
def __init__(self):
self._AddTokens(['INLINE', 'LSHIFT', 'RSHIFT'])
self._AddKeywords(['label', 'struct'])
# Add number types
self._AddKeywords(['char', 'int8_t', 'int16_t', 'int32_t', 'int64_t'])
self._AddKeywords(['uint8_t', 'uint16_t', 'uint32_t', 'uint64_t'])
self._AddKeywords(['double_t', 'float_t'])
# Add handle types
self._AddKeywords(['handle_t', 'PP_FileHandle'])
# Add pointer types (void*, char*, const char*, const void*)
self._AddKeywords(['mem_t', 'str_t', 'cstr_t', 'interface_t'])
# Remove JS types
self._DelKeywords(['boolean', 'byte', 'ByteString', 'Date', 'DOMString',
'double', 'float', 'long', 'object', 'octet', 'Promise',
'record', 'RegExp', 'short', 'unsigned', 'USVString'])
# If run by itself, attempt to build the lexer
if __name__ == '__main__':
lexer = IDLPPAPILexer()
for tok in lexer.GetTokens():
print '\n' + str(tok)