@@ -50,7 +50,7 @@ included generator, since yours will always end in ``.babelg.py``.
5050Generating Output Files
5151=======================
5252
53- To create an output file, use the ``self. output_to_relative_path() `` method.
53+ To create an output file, use the ``output_to_relative_path() `` method.
5454Its only argument is the path relative to the output directory, which was
5555specified as an argument to ``babelapi ``, where the file should be created.
5656
@@ -61,16 +61,16 @@ Each file contains a one line C++-style comment::
6161 from babelapi.generator import CodeGenerator
6262
6363 class ExampleGenerator(CodeGenerator):
64- def generate(self):
65- for namespace_name in self. api.namespaces:
64+ def generate(self, api ):
65+ for namespace_name in api.namespaces:
6666 with self.output_to_relative_path(namespace_name + '.cpp'):
6767 self.emit_line('/* {} */'.format(namespace_name))
6868
6969Using the API Object
7070====================
7171
72- Code generators have a `` self. api `` member variable, which represents the input
73- specs as a Python object. The object is an instance of the ``babelapi.api.Api ``
72+ The `` generate `` method receives an `` api `` variable, which represents the API
73+ spec as a Python object. The object is an instance of the ``babelapi.api.Api ``
7474class. From this object, you can access all the defined namespaces, data types,
7575and routes.
7676
@@ -218,7 +218,7 @@ manager for adding incremental indentation. Here's an example::
218218 from babelapi.generator import CodeGenerator
219219
220220 class ExampleGenerator(CodeGenerator):
221- def generate(self):
221+ def generate(self, api ):
222222 with self.output_to_relative_path('ex_indent.out'):
223223 with self.indent()
224224 self.emit_line('hello')
@@ -238,7 +238,6 @@ future.
238238Helpers for Code Generation
239239===========================
240240
241-
242241``generate_multiline_list(items, before='', after='', delim=('(', ')'), compact=True, sep=',', skip_last_sep=False) ``
243242 Given a list of items, emits one item per line. This is convenient for
244243 function prototypes and invocations, as well as for instantiating arrays,
@@ -270,6 +269,19 @@ Helpers for Code Generation
270269 space and then ``after ``. ``dent `` is the amount to indent the block. If
271270 none, the default indentation increment is used.
272271
272+ Generator Instance Variables
273+ ============================
274+
275+ logger
276+ This is an instance of the `logging.Logger
277+ <https://docs.python.org/2/library/logging.html#logger-objects> `_ class
278+ from the Python standard library. Messages written to the logger will be
279+ output to standard error as the generator runs.
280+
281+ target_folder_path
282+ The path to the output folder. Use this when the
283+ ``output_to_relative_path `` method is insufficient for your purposes.
284+
273285Examples
274286========
275287
@@ -285,10 +297,10 @@ We'll create a generator ``ex1.babelg.py`` that generates a file called
285297 from babelapi.generator import CodeGenerator
286298
287299 class ExampleGenerator(CodeGenerator):
288- def generate(self):
300+ def generate(self, api ):
289301 """Generates a file that lists each namespace."""
290302 with self.output_to_relative_path('ex1.out'):
291- for namespace in self. api.namespaces.values():
303+ for namespace in api.namespaces.values():
292304 self.emit(namespace.name)
293305
294306We use ``output_to_relative_path() `` a member of ``CodeGenerator `` to specify
@@ -314,9 +326,9 @@ a ``noop()`` function::
314326 from babelapi.generator import CodeGenerator
315327
316328 class ExamplePythonGenerator(CodeGenerator):
317- def generate(self):
329+ def generate(self, api ):
318330 """Generates a module for each namespace."""
319- for namespace in self. api.namespaces.values():
331+ for namespace in api.namespaces.values():
320332 # One module per namespace is created. The module takes the name
321333 # of the namespace.
322334 with self.output_to_relative_path('{}.py'.format(namespace.name)):
@@ -365,9 +377,9 @@ declared::
365377 # others use camelcase).
366378 lang = PythonTargetLanguage()
367379
368- def generate(self):
380+ def generate(self, api ):
369381 """Generates a module for each namespace."""
370- for namespace in self. api.namespaces.values():
382+ for namespace in api.namespaces.values():
371383 # One module per namespace is created. The module takes the name
372384 # of the namespace.
373385 with self.output_to_relative_path('{}.py'.format(namespace.name)):
0 commit comments