File size: 973 Bytes
d6a0939 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | diff --git a/task_module.py b/task_module.py
new file mode 100644
index 0000000..0000001
--- /dev/null
+++ b/task_module.py
@@ -0,0 +1,24 @@
+from pygments.lexers import PythonLexer
+from pygments import token
+
+class CodeAnalyzer:
+ """Analyzes Python code using pygments tokenization."""
+
+ def __init__(self):
+ self._lexer = PythonLexer()
+
+ def count_docstrings(self, source):
+ """Count the number of String.Doc tokens in the source code."""
+ if not isinstance(source, str):
+ raise TypeError("Source must be a string")
+
+ # Get tokens using pygments
+ # Note: get_tokens returns an iterator of (TokenType, value) tuples
+ tokens = list(self._lexer.get_tokens(source))
+
+ count = 0
+ for token_type, value in tokens:
+ if token_type == token.String.Doc:
+ count += 1
+
+ return count
\ No newline at end of file
|