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

Side by Side Diff: tools/json_schema_compiler/code.py

Issue 22228002: Add optional schema compiler error messages (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Code clean up, fixed tests, improved errors. Created 7 years, 4 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
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 class Code(object): 5 class Code(object):
6 """A convenience object for constructing code. 6 """A convenience object for constructing code.
7 7
8 Logically each object should be a block of code. All methods except |Render| 8 Logically each object should be a block of code. All methods except |Render|
9 and |IsEmpty| return self. 9 and |IsEmpty| return self.
10 """ 10 """
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 """ 42 """
43 if not isinstance(obj, Code): 43 if not isinstance(obj, Code):
44 raise TypeError(type(obj)) 44 raise TypeError(type(obj))
45 assert self is not obj 45 assert self is not obj
46 for line in obj._code: 46 for line in obj._code:
47 try: 47 try:
48 # line % () will fail if any substitution tokens are left in line 48 # line % () will fail if any substitution tokens are left in line
49 if line.substitute: 49 if line.substitute:
50 line.value %= () 50 line.value %= ()
51 except TypeError: 51 except TypeError:
52 raise TypeError('Unsubstituted value when concatting\n' + line) 52 raise TypeError('Unsubstituted value when concatting\n' + line.value)
53 except ValueError: 53 except ValueError:
54 raise ValueError('Stray % character when concatting\n' + line) 54 raise ValueError('Stray % character when concatting\n' + line.value)
55 self.Append(line.value, line.substitute) 55 self.Append(line.value, line.substitute)
56 56
57 return self 57 return self
58 58
59 def Cblock(self, code): 59 def Cblock(self, code):
60 """Concatenates another Code object |code| onto this one followed by a 60 """Concatenates another Code object |code| onto this one followed by a
61 blank line, if |code| is non-empty.""" 61 blank line, if |code| is non-empty."""
62 if not code.IsEmpty(): 62 if not code.IsEmpty():
63 self.Concat(code).Append() 63 self.Concat(code).Append()
64 return self 64 return self
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 """Renders Code as a string. 132 """Renders Code as a string.
133 """ 133 """
134 return '\n'.join([l.value for l in self._code]) 134 return '\n'.join([l.value for l in self._code])
135 135
136 class Line(object): 136 class Line(object):
137 """A line of code. 137 """A line of code.
138 """ 138 """
139 def __init__(self, value, substitute=True): 139 def __init__(self, value, substitute=True):
140 self.value = value 140 self.value = value
141 self.substitute = substitute 141 self.substitute = substitute
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698