From 3ef75f488a3fe7df372c714d10cd2587d8a16392 Mon Sep 17 00:00:00 2001 From: Lerking Date: Sun, 31 Mar 2019 17:16:37 +0200 Subject: [PATCH] Added comment.py and metaclasses.py --- comment.py | 14 ++++++++++++++ metaclasses.py | 8 ++++++++ 2 files changed, 22 insertions(+) create mode 100644 comment.py create mode 100644 metaclasses.py diff --git a/comment.py b/comment.py new file mode 100644 index 0000000..63ce5ca --- /dev/null +++ b/comment.py @@ -0,0 +1,14 @@ +from metaclasses import InstanceCounterMeta + +class comment(object, metaclass=InstanceCounterMeta): + def __init__(self,com): + self.id = next(self.__class__._ids) + self.comment = com + self.block_comment = False + self.line_comment = False + + def parse_comment(self): + com = self.comment + if com.startswith('/*'): + self.block_comment = True + diff --git a/metaclasses.py b/metaclasses.py new file mode 100644 index 0000000..795b8f7 --- /dev/null +++ b/metaclasses.py @@ -0,0 +1,8 @@ +import itertools + +class InstanceCounterMeta(type): + """ Metaclass to make instance counter not share count with descendants + """ + def __init__(cls, name, bases, attrs): + super().__init__(name, bases, attrs) + cls._ids = itertools.count(1) \ No newline at end of file