Martin Sivák has uploaded a new change for review. Change subject: Fix the lexical priority of operators ......................................................................
Fix the lexical priority of operators As python dictionary has no defined key ordering the GenericEvaluator.get_operators could return the operators in bad order. (for example "<" before "<<") This caused << to be parsed as two < elements and resulted in parse errors. This patch fixes it by ordering the returned value by string size - longer names first. Change-Id: I7dcb7b110b994b351534ccca4da6dc4b79e20895 Signed-off-by: Martin Sivak <[email protected]> --- M mom/Policy/Parser.py 1 file changed, 20 insertions(+), 13 deletions(-) git pull ssh://gerrit.ovirt.org:29418/mom refs/changes/97/16097/1 diff --git a/mom/Policy/Parser.py b/mom/Policy/Parser.py index 5bd400f..3bfe45d 100644 --- a/mom/Policy/Parser.py +++ b/mom/Policy/Parser.py @@ -1,6 +1,6 @@ # Memory Overcommitment Manager # Copyright (C) 2010 Anthony Liguori and Adam Litke, IBM Corporation -# +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. @@ -32,7 +32,7 @@ def __repr__(self): return '[%s %s]' % (self.kind, self.value) - + class NumericToken(Token): def __init__(self, type, value): self.type = type @@ -60,11 +60,11 @@ self.rv = [] GenericScanner.tokenize(self, input) return self.rv - + def t_whitespace(self, s): r' \s+ ' pass - + def t_pound_comment(self, s): r' \#.*?\n ' pass @@ -83,12 +83,12 @@ def t_float(self, s): r' -?(0|([1-9][0-9]*))*(\.[0-9]+)([Ee][+-]?[0-9]+)? ' - self.rv.append(NumericToken('float', s)) + self.rv.append(NumericToken('float', s)) def t_integer(self, s): r' -?(0(?![0-9Xx])|[1-9][0-9]*)(?![0-9eE]) ' self.rv.append(NumericToken('integer', s)) - + def t_integer_with_exponent(self, s): r' -?(0(?![0-9Xx])|[1-9][0-9]*)[Ee][+-]?[0-9]+ ' # Python only recognizes scientific notation on float types @@ -179,7 +179,15 @@ pass def get_operators(self): - return self.operator_map.keys() + """ + Return the list of defined operators. It must return more specific + operators first or parsing errors will appear. + + eg. << must appear before < + """ + return sorted(self.operator_map.keys(), + cmp = lambda x,y: cmp(len(x), len(y)), + reverse = True) def parse_doc(self, doc): scanner = Scanner(['...']) @@ -309,7 +317,7 @@ def eval_symbol(self, name): return self.stack.get(name) - + def eval_number(self, token): if token.type == 'float': return float(token.value) @@ -364,7 +372,7 @@ def c_with(self, iterable, iterator, code): 'symbol symbol code' - + # Iteration is restricted to the list of Guest entities if iterable != 'Guests': raise PolicyError("Unexpected iterable '%s' in with statement" % @@ -421,13 +429,13 @@ def c_shr(self, x, y): return x >> y - + def c_and(self, x, y): return x and y - + def c_or(self, x, y): return x or y - + def c_not(self, x): return not x @@ -473,4 +481,3 @@ print result else: repl(e) - -- To view, visit http://gerrit.ovirt.org/16097 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7dcb7b110b994b351534ccca4da6dc4b79e20895 Gerrit-PatchSet: 1 Gerrit-Project: mom Gerrit-Branch: master Gerrit-Owner: Martin Sivák <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
