You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

4 years ago
  1. class Node(object):
  2. def __init__(self, tag, value, start_mark, end_mark):
  3. self.tag = tag
  4. self.value = value
  5. self.start_mark = start_mark
  6. self.end_mark = end_mark
  7. def __repr__(self):
  8. value = self.value
  9. #if isinstance(value, list):
  10. # if len(value) == 0:
  11. # value = '<empty>'
  12. # elif len(value) == 1:
  13. # value = '<1 item>'
  14. # else:
  15. # value = '<%d items>' % len(value)
  16. #else:
  17. # if len(value) > 75:
  18. # value = repr(value[:70]+u' ... ')
  19. # else:
  20. # value = repr(value)
  21. value = repr(value)
  22. return '%s(tag=%r, value=%s)' % (self.__class__.__name__, self.tag, value)
  23. class ScalarNode(Node):
  24. id = 'scalar'
  25. def __init__(self, tag, value,
  26. start_mark=None, end_mark=None, style=None):
  27. self.tag = tag
  28. self.value = value
  29. self.start_mark = start_mark
  30. self.end_mark = end_mark
  31. self.style = style
  32. class CollectionNode(Node):
  33. def __init__(self, tag, value,
  34. start_mark=None, end_mark=None, flow_style=None):
  35. self.tag = tag
  36. self.value = value
  37. self.start_mark = start_mark
  38. self.end_mark = end_mark
  39. self.flow_style = flow_style
  40. class SequenceNode(CollectionNode):
  41. id = 'sequence'
  42. class MappingNode(CollectionNode):
  43. id = 'mapping'