def unparse(obj): """Turn an abstract edn element into a string. Returns a valid edn string representing 'obj'. """ builder = _Builder() return coerceToTerm(obj).build(builder)
def test_coerce(self): self.assertEqual( coerceToTerm({ 3: 4, "a": character('x'), (2, 3): [4, 5] }), parseTerm('{"a": \'x\', 3: 4, [2, 3]: [4, 5]}'))
def rule_unknown_term(self): tt, _ = self.rule_anything() oldInput = self.input self.input = InputStream.fromIterable(tt.args) newargs, e = self.many(self.rule_transform) self.end() self.input = oldInput return Term(tt.tag, None, tuple(coerceToTerm(a) for a in newargs)), e
def unparse_stream(input_elements, output_stream): """Write abstract edn elements out as edn to a file-like object. Elements will be separated by UNIX newlines. This may change in future versions. """ separator = u'\n'.encode('utf8') builder = _Builder() for element in input_elements: output_stream.write(coerceToTerm(element).build(builder)) output_stream.write(separator)
def coerceToQuasiMatch(val, isFunctorHole, tag): if isFunctorHole: if val is None: result = Term(Tag("null"), None, None) elif isinstance(val, Term): if len(val.args) != 0: return None else: result = val elif isinstance(val, basestring): result = Term(Tag(val), None, None) elif isinstance(val, bool): result = Term(Tag(["false", "true"][val]), None, None) else: return None else: result = coerceToTerm(val) if tag is not None and result.tag != tag: return None return result
def coerceToQuasiMatch(val, isFunctorHole, tag): if isFunctorHole: if val is None: result = Term(Tag("null"), None, None, None) elif isinstance(val, Term): if len(val.args) != 0: return None else: result = val elif isinstance(val, basestring): result = Term(Tag(val), None, None, None) elif isinstance(val, bool): result = Term(Tag(["false", "true"][val]), None, None, None) else: return None else: result = coerceToTerm(val) if tag is not None and result.tag != tag: return None return result
def backpatch(self, fromIdx, toIdx): old = self.instrs[fromIdx] self.instrs[fromIdx] = Term(old.tag, None, [coerceToTerm(toIdx)])
def test_coerce(self): self.assertEqual( coerceToTerm({3: 4, "a": character('x'), (2, 3): [4, 5]}), parseTerm('{"a": \'x\', 3: 4, [2, 3]: [4, 5]}'))