OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Generates a syntax tree from a Mojo IDL file.""" | 5 """Generates a syntax tree from a Mojo IDL file.""" |
6 | 6 |
7 import imp | 7 import imp |
8 import os.path | 8 import os.path |
9 import sys | 9 import sys |
10 | 10 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 """parameter : typename NAME ordinal""" | 186 """parameter : typename NAME ordinal""" |
187 p[0] = ('PARAM', p[1], p[2], p[3]) | 187 p[0] = ('PARAM', p[1], p[2], p[3]) |
188 | 188 |
189 def p_typename(self, p): | 189 def p_typename(self, p): |
190 """typename : basictypename | 190 """typename : basictypename |
191 | array""" | 191 | array""" |
192 p[0] = p[1] | 192 p[0] = p[1] |
193 | 193 |
194 def p_basictypename(self, p): | 194 def p_basictypename(self, p): |
195 """basictypename : identifier | 195 """basictypename : identifier |
196 | HANDLE | 196 | handletype""" |
197 | specializedhandle""" | |
198 p[0] = p[1] | 197 p[0] = p[1] |
199 | 198 |
200 def p_specializedhandle(self, p): | 199 def p_handletype(self, p): |
201 """specializedhandle : HANDLE LANGLE specializedhandlename RANGLE""" | 200 """handletype : HANDLE |
202 p[0] = "handle<" + p[3] + ">" | 201 | HANDLE LANGLE identifier RANGLE""" |
203 | 202 if len(p) == 2: |
204 def p_specializedhandlename(self, p): | 203 p[0] = p[1] |
205 """specializedhandlename : DATA_PIPE_CONSUMER | 204 else: |
206 | DATA_PIPE_PRODUCER | 205 if p[3] not in ('data_pipe_consumer', |
207 | MESSAGE_PIPE | 206 'data_pipe_producer', |
208 | SHARED_BUFFER""" | 207 'message_pipe', |
209 p[0] = p[1] | 208 'shared_buffer'): |
| 209 # Note: We don't enable tracking of line numbers for everything, so we |
| 210 # can't use |p.lineno(3)|. |
| 211 raise ParseError(self.filename, "Invalid handle type %r:" % p[3], |
| 212 lineno=p.lineno(1), |
| 213 snippet=self._GetSnippet(p.lineno(1))) |
| 214 p[0] = "handle<" + p[3] + ">" |
210 | 215 |
211 def p_array(self, p): | 216 def p_array(self, p): |
212 """array : typename LBRACKET RBRACKET""" | 217 """array : typename LBRACKET RBRACKET""" |
213 p[0] = p[1] + "[]" | 218 p[0] = p[1] + "[]" |
214 | 219 |
215 def p_ordinal(self, p): | 220 def p_ordinal(self, p): |
216 """ordinal : ORDINAL | 221 """ordinal : ORDINAL |
217 | """ | 222 | """ |
218 if len(p) > 1: | 223 if len(p) > 1: |
219 value = int(p[1][1:]) | 224 value = int(p[1][1:]) |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 364 |
360 def Parse(source, filename): | 365 def Parse(source, filename): |
361 lexer = Lexer(filename) | 366 lexer = Lexer(filename) |
362 parser = Parser(lexer, source, filename) | 367 parser = Parser(lexer, source, filename) |
363 | 368 |
364 lex.lex(object=lexer) | 369 lex.lex(object=lexer) |
365 yacc.yacc(module=parser, debug=0, write_tables=0) | 370 yacc.yacc(module=parser, debug=0, write_tables=0) |
366 | 371 |
367 tree = yacc.parse(source) | 372 tree = yacc.parse(source) |
368 return tree | 373 return tree |
OLD | NEW |