Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: ppapi/generators/idl_lexer.py

Issue 9359040: WIP IDL-IPC2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Checkpoint before going back to returning ListValue via ExtensionMsg_Response. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/generators/apps_example.py ('k') | ppapi/generators/idl_parser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ Lexer for PPAPI IDL """ 6 """ Lexer for PPAPI IDL """
7 7
8 # 8 #
9 # IDL Lexer 9 # IDL Lexer
10 # 10 #
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 'COMMENT', 48 'COMMENT',
49 'DESCRIBE', 49 'DESCRIBE',
50 'ENUM', 50 'ENUM',
51 'LABEL', 51 'LABEL',
52 'SYMBOL', 52 'SYMBOL',
53 'INLINE', 53 'INLINE',
54 'INTERFACE', 54 'INTERFACE',
55 'STRUCT', 55 'STRUCT',
56 'TYPEDEF', 56 'TYPEDEF',
57 57
58 # Extra WebIDL keywords
59 'CALLBACK',
60 'DICTIONARY',
61 'OPTIONAL',
62 'STATIC',
63
64 # Invented for apps use
65 'NAMESPACE',
66
67
58 # Data types 68 # Data types
59 'FLOAT', 69 'FLOAT',
60 'OCT', 70 'OCT',
61 'INT', 71 'INT',
62 'HEX', 72 'HEX',
63 'STRING', 73 'STRING',
64 74
65 # Operators 75 # Operators
66 'LSHIFT', 76 'LSHIFT',
67 'RSHIFT' 77 'RSHIFT'
68 ] 78 ]
69 79
70 # 'keywords' is a map of string to token type. All SYMBOL tokens are 80 # 'keywords' is a map of string to token type. All SYMBOL tokens are
71 # matched against keywords, to determine if the token is actually a keyword. 81 # matched against keywords, to determine if the token is actually a keyword.
72 keywords = { 82 keywords = {
73 'describe' : 'DESCRIBE', 83 'describe' : 'DESCRIBE',
74 'enum' : 'ENUM', 84 'enum' : 'ENUM',
75 'label' : 'LABEL', 85 'label' : 'LABEL',
76 'interface' : 'INTERFACE', 86 'interface' : 'INTERFACE',
77 'readonly' : 'READONLY', 87 'readonly' : 'READONLY',
78 'struct' : 'STRUCT', 88 'struct' : 'STRUCT',
79 'typedef' : 'TYPEDEF', 89 'typedef' : 'TYPEDEF',
90
91 'callback' : 'CALLBACK',
92 'dictionary' : 'DICTIONARY',
93 'optional' : 'OPTIONAL',
94 'static' : 'STATIC',
95 'namespace' : 'NAMESPACE',
80 } 96 }
81 97
82 # 'literals' is a value expected by lex which specifies a list of valid 98 # 'literals' is a value expected by lex which specifies a list of valid
83 # literal tokens, meaning the token type and token value are identical. 99 # literal tokens, meaning the token type and token value are identical.
84 literals = '"*.(){}[],;:=+-/~|&^' 100 literals = '"*.(){}[],;:=+-/~|&^?'
85 101
86 # Token definitions 102 # Token definitions
87 # 103 #
88 # Lex assumes any value or function in the form of 't_<TYPE>' represents a 104 # Lex assumes any value or function in the form of 't_<TYPE>' represents a
89 # regular expression where a match will emit a token of type <TYPE>. In the 105 # regular expression where a match will emit a token of type <TYPE>. In the
90 # case of a function, the function is called when a match is made. These 106 # case of a function, the function is called when a match is made. These
91 # definitions come from WebIDL. 107 # definitions come from WebIDL.
92 108
93 # 't_ignore' is a special match of items to ignore 109 # 't_ignore' is a special match of items to ignore
94 t_ignore = ' \t' 110 t_ignore = ' \t'
(...skipping 14 matching lines...) Expand all
109 # We do not process escapes in the IDL strings. Strings are exclusively 125 # We do not process escapes in the IDL strings. Strings are exclusively
110 # used for attributes, and not used as typical 'C' constants. 126 # used for attributes, and not used as typical 'C' constants.
111 def t_STRING(self, t): 127 def t_STRING(self, t):
112 r'"[^"]*"' 128 r'"[^"]*"'
113 t.value = t.value[1:-1] 129 t.value = t.value[1:-1]
114 self.AddLines(t.value.count('\n')) 130 self.AddLines(t.value.count('\n'))
115 return t 131 return t
116 132
117 # A C or C++ style comment: /* xxx */ or // 133 # A C or C++ style comment: /* xxx */ or //
118 def t_COMMENT(self, t): 134 def t_COMMENT(self, t):
119 r'(/\*(.|\n)*?\*/)|(//.*)' 135 r'(/\*(.|\n)*?\*/)|(//.*(\n//.*)*)'
120 self.AddLines(t.value.count('\n')) 136 self.AddLines(t.value.count('\n'))
121 return t 137 return t
122 138
123 # Return a "preprocessor" inline block 139 # Return a "preprocessor" inline block
124 def t_INLINE(self, t): 140 def t_INLINE(self, t):
125 r'\#inline (.|\n)*?\#endinl.*' 141 r'\#inline (.|\n)*?\#endinl.*'
126 self.AddLines(t.value.count('\n')) 142 self.AddLines(t.value.count('\n'))
127 return t 143 return t
128 144
129 # A symbol or keyword. 145 # A symbol or keyword.
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 return -1 336 return -1
321 return 0 337 return 0
322 338
323 except lex.LexError as le: 339 except lex.LexError as le:
324 sys.stderr.write('%s\n' % str(le)) 340 sys.stderr.write('%s\n' % str(le))
325 return -1 341 return -1
326 342
327 343
328 if __name__ == '__main__': 344 if __name__ == '__main__':
329 sys.exit(Main(sys.argv[1:])) 345 sys.exit(Main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « ppapi/generators/apps_example.py ('k') | ppapi/generators/idl_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698