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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/parse/parser.py

Issue 293033005: Mojo: Mojom: Remove default values for structs and arrays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar generator bugs Created 6 years, 7 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 | « mojo/public/interfaces/bindings/tests/sample_service.mojom ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 | """ 136 | """
137 if len(p) > 1: 137 if len(p) > 1:
138 p[0] = _ListFromConcat(p[1], p[2]) 138 p[0] = _ListFromConcat(p[1], p[2])
139 139
140 def p_field(self, p): 140 def p_field(self, p):
141 """field : typename NAME default ordinal SEMI""" 141 """field : typename NAME default ordinal SEMI"""
142 p[0] = ('FIELD', p[1], p[2], p[4], p[3]) 142 p[0] = ('FIELD', p[1], p[2], p[4], p[3])
143 143
144 def p_default(self, p): 144 def p_default(self, p):
145 """default : EQUALS expression 145 """default : EQUALS expression
146 | EQUALS expression_object
147 | """ 146 | """
148 if len(p) > 2: 147 if len(p) > 2:
149 p[0] = p[2] 148 p[0] = p[2]
150 149
151 def p_interface(self, p): 150 def p_interface(self, p):
152 """interface : attribute_section INTERFACE NAME LBRACE interface_body \ 151 """interface : attribute_section INTERFACE NAME LBRACE interface_body \
153 RBRACE SEMI""" 152 RBRACE SEMI"""
154 p[0] = ('INTERFACE', p[3], p[1], p[5]) 153 p[0] = ('INTERFACE', p[3], p[1], p[5])
155 154
156 def p_interface_body(self, p): 155 def p_interface_body(self, p):
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 p[0] = ('ENUM_FIELD', p[1], None) 249 p[0] = ('ENUM_FIELD', p[1], None)
251 else: 250 else:
252 p[0] = ('ENUM_FIELD', p[1], p[3]) 251 p[0] = ('ENUM_FIELD', p[1], p[3])
253 252
254 def p_const(self, p): 253 def p_const(self, p):
255 """const : CONST typename NAME EQUALS expression SEMI""" 254 """const : CONST typename NAME EQUALS expression SEMI"""
256 p[0] = ('CONST', p[2], p[3], p[5]) 255 p[0] = ('CONST', p[2], p[3], p[5])
257 256
258 ### Expressions ### 257 ### Expressions ###
259 258
260 def p_expression_object(self, p):
261 """expression_object : expression_array
262 | LBRACE expression_object_elements RBRACE """
263 if len(p) < 3:
264 p[0] = p[1]
265 else:
266 p[0] = ('OBJECT', p[2])
267
268 def p_expression_object_elements(self, p):
269 """expression_object_elements : expression_object
270 | expression_object COMMA expression_object_el ements
271 | """
272 if len(p) == 2:
273 p[0] = _ListFromConcat(p[1])
274 elif len(p) > 3:
275 p[0] = _ListFromConcat(p[1], p[3])
276
277 def p_expression_array(self, p):
278 """expression_array : expression
279 | LBRACKET expression_array_elements RBRACKET """
280 if len(p) < 3:
281 p[0] = p[1]
282 else:
283 p[0] = ('ARRAY', p[2])
284
285 def p_expression_array_elements(self, p):
286 """expression_array_elements : expression_object
287 | expression_object COMMA expression_array_elem ents
288 | """
289 if len(p) == 2:
290 p[0] = _ListFromConcat(p[1])
291 elif len(p) > 3:
292 p[0] = _ListFromConcat(p[1], p[3])
293
294 # TODO(vtl): This is now largely redundant. 259 # TODO(vtl): This is now largely redundant.
295 def p_expression(self, p): 260 def p_expression(self, p):
296 """expression : binary_expression""" 261 """expression : binary_expression"""
297 p[0] = ('EXPRESSION', p[1]) 262 p[0] = ('EXPRESSION', p[1])
298 263
299 # PLY lets us specify precedence of operators, but since we don't actually 264 # PLY lets us specify precedence of operators, but since we don't actually
300 # evaluate them, we don't need that here. 265 # evaluate them, we don't need that here.
301 # TODO(vtl): We're going to need to evaluate them. 266 # TODO(vtl): We're going to need to evaluate them.
302 def p_binary_expression(self, p): 267 def p_binary_expression(self, p):
303 """binary_expression : unary_expression 268 """binary_expression : unary_expression
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 329
365 def Parse(source, filename): 330 def Parse(source, filename):
366 lexer = Lexer(filename) 331 lexer = Lexer(filename)
367 parser = Parser(lexer, source, filename) 332 parser = Parser(lexer, source, filename)
368 333
369 lex.lex(object=lexer) 334 lex.lex(object=lexer)
370 yacc.yacc(module=parser, debug=0, write_tables=0) 335 yacc.yacc(module=parser, debug=0, write_tables=0)
371 336
372 tree = yacc.parse(source) 337 tree = yacc.parse(source)
373 return tree 338 return tree
OLDNEW
« no previous file with comments | « mojo/public/interfaces/bindings/tests/sample_service.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698