Added comment.py and metaclasses.py

This commit is contained in:
2019-03-31 17:16:37 +02:00
parent 19f0c466f7
commit 3ef75f488a
2 changed files with 22 additions and 0 deletions

14
comment.py Normal file
View File

@@ -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

8
metaclasses.py Normal file
View File

@@ -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)