Chunk.py 695 B

123456789101112131415161718192021222324252627282930
  1. #
  2. # Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
  3. # Use of this file is governed by the BSD 3-clause license that
  4. # can be found in the LICENSE.txt file in the project root.
  5. #
  6. class Chunk(object):
  7. pass
  8. class TagChunk(Chunk):
  9. __slots__ = ('tag', 'label')
  10. def __init__(self, tag:str, label:str=None):
  11. self.tag = tag
  12. self.label = label
  13. def __str__(self):
  14. if self.label is None:
  15. return self.tag
  16. else:
  17. return self.label + ":" + self.tag
  18. class TextChunk(Chunk):
  19. __slots__ = 'text'
  20. def __init__(self, text:str):
  21. self.text = text
  22. def __str__(self):
  23. return "'" + self.text + "'"