コード例 #1
0
ファイル: _ast.py プロジェクト: dreid/edn
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)
コード例 #2
0
 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]}'))
コード例 #3
0
ファイル: runtime.py プロジェクト: CS76/ipo-galaxy
 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
コード例 #4
0
 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
コード例 #5
0
ファイル: _ast.py プロジェクト: dreid/edn
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)
コード例 #6
0
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
コード例 #7
0
ファイル: qnodes.py プロジェクト: abenassi/parsley
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
コード例 #8
0
ファイル: vm_builder.py プロジェクト: wallrj/parsley
 def backpatch(self, fromIdx, toIdx):
     old = self.instrs[fromIdx]
     self.instrs[fromIdx] = Term(old.tag, None, [coerceToTerm(toIdx)])
コード例 #9
0
ファイル: test_terml.py プロジェクト: abenassi/parsley
 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]}'))
コード例 #10
0
 def backpatch(self, fromIdx, toIdx):
     old = self.instrs[fromIdx]
     self.instrs[fromIdx] = Term(old.tag, None, [coerceToTerm(toIdx)])