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

Side by Side Diff: mojo/public/bindings/pylib/parse/mojo_parser.py

Issue 141893004: Support default values for arrays of POD data types in mojom. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 11 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 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 """Generates a syntax tree from a Mojo IDL file.""" 6 """Generates a syntax tree from a Mojo IDL file."""
7 7
8 8
9 import sys 9 import sys
10 import os.path 10 import os.path
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 | """ 93 | """
94 if len(p) > 1: 94 if len(p) > 1:
95 p[0] = ListFromConcat(p[1], p[2]) 95 p[0] = ListFromConcat(p[1], p[2])
96 96
97 def p_field(self, p): 97 def p_field(self, p):
98 """field : typename NAME default ordinal SEMI""" 98 """field : typename NAME default ordinal SEMI"""
99 p[0] = ('FIELD', p[1], p[2], p[4], p[3]) 99 p[0] = ('FIELD', p[1], p[2], p[4], p[3])
100 100
101 def p_default(self, p): 101 def p_default(self, p):
102 """default : EQUALS expression 102 """default : EQUALS expression
103 | EQUALS expression_array
103 | """ 104 | """
104 if len(p) > 2: 105 if len(p) > 2:
105 p[0] = p[2] 106 p[0] = p[2]
106 107
107 def p_interface(self, p): 108 def p_interface(self, p):
108 """interface : attribute_section INTERFACE NAME LBRACE interface_body \ 109 """interface : attribute_section INTERFACE NAME LBRACE interface_body \
109 RBRACE SEMI""" 110 RBRACE SEMI"""
110 p[0] = ('INTERFACE', p[3], p[1], p[5]) 111 p[0] = ('INTERFACE', p[3], p[1], p[5])
111 112
112 def p_interface_body(self, p): 113 def p_interface_body(self, p):
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 def p_enum_field(self, p): 183 def p_enum_field(self, p):
183 """enum_field : NAME 184 """enum_field : NAME
184 | NAME EQUALS expression""" 185 | NAME EQUALS expression"""
185 if len(p) == 2: 186 if len(p) == 2:
186 p[0] = ('ENUM_FIELD', p[1], None) 187 p[0] = ('ENUM_FIELD', p[1], None)
187 else: 188 else:
188 p[0] = ('ENUM_FIELD', p[1], p[3]) 189 p[0] = ('ENUM_FIELD', p[1], p[3])
189 190
190 ### Expressions ### 191 ### Expressions ###
191 192
193 def p_expression_array(self, p):
194 """expression_array : expression
195 | LBRACKET expression_array_elements RBRACKET """
196 if len(p) < 3:
197 p[0] = p[1]
198 else:
199 p[0] = p[2]
200
201 def p_expression_array_elements(self, p):
202 """expression_array_elements : expression
203 | expression COMMA expression_array_elements
204 | """
205 if len(p) == 2:
206 p[0] = ListFromConcat(p[1])
207 elif len(p) > 3:
208 p[0] = ListFromConcat(p[1], p[3])
209
192 def p_expression(self, p): 210 def p_expression(self, p):
193 """expression : conditional_expression""" 211 """expression : conditional_expression"""
194 p[0] = p[1] 212 p[0] = p[1]
195 213
196 def p_conditional_expression(self, p): 214 def p_conditional_expression(self, p):
197 """conditional_expression : binary_expression 215 """conditional_expression : binary_expression
198 | binary_expression CONDOP expression COLON \ 216 | binary_expression CONDOP expression COLON \
199 conditional_expression""" 217 conditional_expression"""
200 # Just pass the arguments through. I don't think it's possible to preserve 218 # Just pass the arguments through. I don't think it's possible to preserve
201 # the spaces of the original, so just put a single space between them. 219 # the spaces of the original, so just put a single space between them.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 def Main(): 297 def Main():
280 if len(sys.argv) < 2: 298 if len(sys.argv) < 2:
281 print("usage: %s filename" % (sys.argv[0])) 299 print("usage: %s filename" % (sys.argv[0]))
282 sys.exit(1) 300 sys.exit(1)
283 tree = Parse(filename=sys.argv[1]) 301 tree = Parse(filename=sys.argv[1])
284 print(tree) 302 print(tree)
285 303
286 304
287 if __name__ == '__main__': 305 if __name__ == '__main__':
288 Main() 306 Main()
OLDNEW
« no previous file with comments | « mojo/public/bindings/generators/mojom_js_generator.py ('k') | mojo/public/bindings/sample/sample_service_unittests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698