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

Unified Diff: ppapi/generators/idl_parser.py

Issue 8161006: Allow enum values in IDL files to be simple arithmetic expressions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/generators/idl_lexer.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/generators/idl_parser.py
===================================================================
--- ppapi/generators/idl_parser.py (revision 104195)
+++ ppapi/generators/idl_parser.py (working copy)
@@ -428,6 +428,53 @@
if self.parse_debug: DumpReduction('number_lshift', p)
#
+# Expression
+#
+# A simple arithmetic expression.
+#
+ precedence = (
+ ('left','LSHIFT','RSHIFT'),
+ ('left','+','-'),
+ ('left','*','/'),
+ ('right','UMINUS'),
+ )
+
+ def p_expression_binop(self, p):
+ """expression : expression '+' expression
+ | expression '-' expression
+ | expression '*' expression
+ | expression '/' expression
+ | expression LSHIFT expression
+ | expression RSHIFT expression"""
+ if p[2] == '+' : p[0] = p[1] + p[3]
noelallen1 2011/10/05 23:35:51 I think what you really want to do, is take a bunc
+ elif p[2] == '-': p[0] = p[1] - p[3]
+ elif p[2] == '*': p[0] = p[1] * p[3]
+ elif p[2] == '/': p[0] = p[1] / p[3]
+ elif p[2] == 'LSHIFT': p[0] = p[1] << p[3]
+ elif p[2] == 'RSHIFT': p[0] = p[1] >> p[3]
+ if self.parse_debug: DumpReduction('expression_binop', p)
+
+ def p_expression_uminus(self, p):
+ "expression : '-' expression %prec UMINUS"
+ p[0] = -p[2]
+ if self.parse_debug: DumpReduction('expression_uminus', p)
+
+ def p_expression_term(self, p):
+ "expression : '(' expression ')'"
+ p[0] = p[2]
+ if self.parse_debug: DumpReduction('expression_term', p)
+
+ def p_expression_symbol(self, p):
+ "expression : SYMBOL"
+ p[0] = p[1]
+ if self.parse_debug: DumpReduction('expression_symbol', p)
+
+ def p_expression_number(self, p):
+ "expression : number"
+ p[0] = p[1]
noelallen1 2011/10/05 23:35:51 only allow INT, HEX, OCT? No float
+ if self.parse_debug: DumpReduction('expression_integer', p)
+
+#
# Array List
#
# Defined a list of array sizes (if any).
@@ -523,7 +570,7 @@
if self.parse_debug: DumpReduction('enum_block', p)
def p_enum_list(self, p):
- """enum_list : modifiers SYMBOL '=' number enum_cont
+ """enum_list : modifiers SYMBOL '=' expression enum_cont
| modifiers SYMBOL enum_cont"""
if len(p) > 4:
val = self.BuildAttribute('VALUE', p[4])
« no previous file with comments | « ppapi/generators/idl_lexer.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698