diff --git a/implementations/python/preserves/text.py b/implementations/python/preserves/text.py index d448126..424441b 100644 --- a/implementations/python/preserves/text.py +++ b/implementations/python/preserves/text.py @@ -312,10 +312,16 @@ def parse_with_annotations(bs, **kwargs): return Parser(input_buffer=bs, include_annotations=True, **kwargs).next() class Formatter(TextCodec): - def __init__(self, format_embedded=lambda x: x, indent=None): + def __init__(self, + format_embedded=lambda x: x, + indent=None, + with_commas=False, + trailing_comma=False): super(Formatter, self).__init__() self.indent_delta = 0 if indent is None else indent self.indent_distance = 0 + self.with_commas = with_commas + self.trailing_comma = trailing_comma self.chunks = [] self._format_embedded = format_embedded @@ -362,9 +368,11 @@ class Formatter(TextCodec): self.write_indent() appender(vs[0]) for v in vs[1:]: + if self.with_commas: self.chunks.append(',') self.write_indent_space() appender(v) self.indent_distance = self.indent_distance - self.indent_delta + if self.trailing_comma: self.chunks.append(',') self.write_indent() self.chunks.append(closer) diff --git a/implementations/python/setup.py b/implementations/python/setup.py index fcd39be..767b0ae 100644 --- a/implementations/python/setup.py +++ b/implementations/python/setup.py @@ -5,7 +5,7 @@ except ImportError: setup( name="preserves", - version="0.11.0", + version="0.12.0", author="Tony Garnock-Jones", author_email="tonyg@leastfixedpoint.com", license="Apache Software License",