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

Side by Side Diff: third_party/dom_distiller_js/protoc_plugins/util/writer.py

Issue 2034373002: Generate the proto JSON converter for DOM distiller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
nyquist 2016/06/14 00:48:11 Could you in general update these numbers?
wychen 2016/08/07 09:16:27 Done.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import contextlib
6
7 class CodeWriter(object):
nyquist 2016/06/14 00:48:11 Could you add an explanatory comment for this clas
wychen 2016/08/07 09:16:27 Done.
8 def __init__(self):
9 self.indent = 0
10 self.value = []
11 self.errors = []
12
13 def GetErrors(self):
14 return self.errors
15
16 @contextlib.contextmanager
17 def AddIndent(self, indent=2):
18 self.indent += indent
19 yield 0
20 self.indent -= indent
21
22 def IncreaseIndent(self, indent=2):
23 self.indent += indent
24
25 def DecreaseIndent(self, indent=2):
26 self.indent -= indent
27
28 def Output(self, fmt, **kwargs):
29 s = fmt.format(**kwargs)
30 s = s.rstrip('\n')
31 lines = s.split('\n')
32 lines = map(lambda s: (' ' * self.indent + s).rstrip(), lines)
33 self.value.extend(lines)
34
35 def AddError(self, fmt, **kwargs):
36 self.errors.append(fmt.format(**kwargs))
37
38 def GetValue(self):
39 return '\n'.join(self.value) + '\n'
40
41 def WriteCStyleHeader(self):
42 self.Output("// GENERATED FILE")
43 self.Output("// This file generated by DomDistillerJs protoc plugin.")
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698