Source

htsql / src / htsql / core / syn / syntax.py

Diff from to

src/htsql/core/syn/syntax.py

 
 
 from ..util import (maybe, listof, oneof, Clonable, Hashable, Printable,
-        to_name, to_literal)
+        YAMLable, to_name, to_literal)
 import re
 import decimal
 
 
-class Syntax(Clonable, Hashable, Printable):
+class Syntax(Clonable, Hashable, Printable, YAMLable):
     """
     A syntax node.
     """
     def __unicode__(self):
         return u"%s:=%s" % (self.larm, self.rarm)
 
+    def __yaml__(self):
+        yield ('larm', self.larm)
+        yield ('rarm', self.rarm)
+
 
 class SpecifySyntax(Syntax):
     """
             chunks.append(u")")
         return u"".join(chunks)
 
+    def __yaml__(self):
+        yield ('larms', self.larms)
+        if self.rarms is not None:
+            yield ('rarms', self.rarms)
+
 
 class ApplySyntax(Syntax):
     """
         return u"%s(%s)" % (self.identifier,
                             u",".join(unicode(arm) for arm in self.arms))
 
+    def __yaml__(self):
+        yield ('identifier', self.identifier)
+        yield ('arms', self.arms)
+
 
 class PipeSyntax(ApplySyntax):
     """
             chunks.append(u")")
         return u"".join(chunks)
 
+    def __yaml__(self):
+        yield ('is_flow', self.is_flow)
+        yield ('is_open', self.is_open)
+        yield ('identifier', self.identifier)
+        yield ('larm', self.larm)
+        if self.rarms or not self.is_open:
+            yield ('rarms', self.rarms)
+
 
 class OperatorSyntax(ApplySyntax):
     """
     def __unicode__(self):
         return u"%s%s%s" % (self.larm, self.symbol, self.rarm)
 
+    def __yaml__(self):
+        yield ('symbol', self.symbol)
+        yield ('larm', self.larm)
+        yield ('rarm', self.rarm)
+
 
 class PrefixSyntax(ApplySyntax):
     """
     def __unicode__(self):
         return u"%s%s" % (self.symbol, self.arm)
 
+    def __yaml__(self):
+        yield ('symbol', self.symbol)
+        yield ('arm', self.arm)
+
 
 class FilterSyntax(OperatorSyntax):
     """
     def __init__(self, larm, rarm):
         super(FilterSyntax, self).__init__(u'?', larm, rarm)
 
+    def __yaml__(self):
+        yield ('larm', self.larm)
+        yield ('rarm', self.rarm)
+
 
 class ProjectSyntax(OperatorSyntax):
     """
     def __init__(self, larm, rarm):
         super(ProjectSyntax, self).__init__(u'^', larm, rarm)
 
+    def __yaml__(self):
+        yield ('larm', self.larm)
+        yield ('rarm', self.rarm)
+
 
 class LinkSyntax(OperatorSyntax):
     """
     def __init__(self, larm, rarm):
         super(LinkSyntax, self).__init__(u'->', larm, rarm)
 
+    def __yaml__(self):
+        yield ('larm', self.larm)
+        yield ('rarm', self.rarm)
+
 
 class AttachSyntax(OperatorSyntax):
     """
     def __init__(self, larm, rarm):
         super(AttachSyntax, self).__init__(u'@', larm, rarm)
 
+    def __yaml__(self):
+        yield ('larm', self.larm)
+        yield ('rarm', self.rarm)
+
 
 class DetachSyntax(PrefixSyntax):
     """
     def __init__(self, arm):
         super(DetachSyntax, self).__init__(u'@', arm)
 
+    def __yaml__(self):
+        yield ('arm', self.arm)
+
 
 class CollectSyntax(PrefixSyntax):
     """
     def __init__(self, arm):
         super(CollectSyntax, self).__init__(u'/', arm)
 
+    def __yaml__(self):
+        yield ('arm', self.arm)
+
 
 class DirectSyntax(Syntax):
     """
     def __unicode__(self):
         return u"%s%s" % (self.arm, self.symbol)
 
+    def __yaml__(self):
+        yield ('symbol', self.symbol)
+        yield ('arm', self.arm)
+
 
 class ComposeSyntax(Syntax):
     """
         chunks.append(unicode(self.rarm))
         return u"".join(chunks)
 
+    def __yaml__(self):
+        yield ('larm', self.larm)
+        yield ('rarm', self.rarm)
+
 
 class UnpackSyntax(Syntax):
     """
             chunks.append(u")")
         return u"".join(chunks)
 
+    def __yaml__(self):
+        if self.index is not None:
+            yield ('is_open', self.is_open)
+            yield ('index', self.index)
+
 
 class LiftSyntax(Syntax):
     """
     def __unicode__(self):
         return u"(%s)" % self.arm
 
+    def __yaml__(self):
+        yield ('arm', self.arm)
+
 
 class SelectSyntax(Syntax):
     """
     def __unicode__(self):
         return u"%s%s" % (self.larm, self.rarm)
 
+    def __yaml__(self):
+        yield ('larm', self.larm)
+        yield ('rarm', self.rarm)
+
 
 class LocateSyntax(Syntax):
     """
     def __unicode__(self):
         return u"%s%s" % (self.larm, self.rarm)
 
+    def __yaml__(self):
+        yield ('larm', self.larm)
+        yield ('rarm', self.rarm)
+
 
 class RecordSyntax(Syntax):
     """
     def __unicode__(self):
         return u"{%s}" % u",".join(unicode(arm) for arm in self.arms)
 
+    def __yaml__(self):
+        yield ('arms', self.arms)
+
 
 class ListSyntax(Syntax):
     """
         chunks.append(u")")
         return u"".join(chunks)
 
+    def __yaml__(self):
+        yield ('arms', self.arms)
+
 
 class IdentitySyntax(Syntax):
     """
             chunks.append(u")")
         return u"".join(chunks)
 
+    def __yaml__(self):
+        yield ('is_hard', self.is_hard)
+        yield ('arms', self.arms)
+
 
 class ReferenceSyntax(Syntax):
     """
     def __unicode__(self):
         return u"$%s" % self.identifier
 
+    def __yaml__(self):
+        yield ('identifier', self.identifier)
+
 
 class IdentifierSyntax(Syntax):
     """
     def __unicode__(self):
         return self.text
 
+    def __yaml__(self):
+        yield ('text', self.text)
+        if self.name != self.text:
+            yield ('name', self.name)
+
 
 class LiteralSyntax(Syntax):
     """
     def __unicode__(self):
         return self.text
 
+    def __yaml__(self):
+        yield ('text', self.text)
+
 
 class StringSyntax(LiteralSyntax):
     """