1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """ Lexer for PPAPI IDL
7 The lexer uses the PLY library to build a tokenizer which understands both
8 WebIDL and Pepper tokens.
10 WebIDL, and WebIDL regular expressions can be found at:
11 http://www.w3.org/TR/2012/CR-WebIDL-20120419/
13 http://www.dabeaz.com/ply/
16 from idl_lexer
import IDLLexer
25 class IDLPPAPILexer(IDLLexer
):
26 # Special multi-character operators
27 def t_LSHIFT(self
, t
):
31 def t_RSHIFT(self
, t
):
35 def t_INLINE(self
, t
):
36 r
'\#inline (.|\n)*?\#endinl.*'
37 self
.AddLines(t
.value
.count('\n'))
40 # Return a "preprocessor" inline block
42 IDLLexer
.__init
__(self
)
43 self
._AddTokens
(['LSHIFT', 'RSHIFT', 'INLINE'])
44 self
._AddKeywords
(['label', 'namespace', 'struct'])
47 # If run by itself, attempt to build the lexer
48 if __name__
== '__main__':
49 lexer
= IDLPPAPILexer()