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

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: Windows-specific fixes Created 4 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
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
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):
8 """Helper class for code indentation."""
9 def __init__(self):
10 self.indent = 0
11 self.value = []
12 self.errors = []
13
14 def GetErrors(self):
15 return self.errors
16
17 @contextlib.contextmanager
18 def AddIndent(self, indent=2):
19 self.indent += indent
20 yield 0
21 self.indent -= indent
22
23 def IncreaseIndent(self, indent=2):
24 self.indent += indent
25
26 def DecreaseIndent(self, indent=2):
27 self.indent -= indent
28
29 def Output(self, fmt, **kwargs):
30 s = fmt.format(**kwargs)
31 s = s.rstrip('\n')
32 lines = s.split('\n')
33 lines = map(lambda s: (' ' * self.indent + s).rstrip(), lines)
34 self.value.extend(lines)
35
36 def AddError(self, fmt, **kwargs):
37 self.errors.append(fmt.format(**kwargs))
38
39 def GetValue(self):
40 return '\n'.join(self.value) + '\n'
41
42 def WriteCStyleHeader(self):
43 self.Output("// GENERATED FILE")
44 self.Output("// This file generated by DomDistillerJs protoc plugin.")
OLDNEW
« no previous file with comments | « third_party/dom_distiller_js/protoc_plugins/util/types.py ('k') | third_party/dom_distiller_js/test_sample.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698