summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2024-09-23 13:11:08 +0200
committerEddy Pedroni <epedroni@pm.me>2024-09-23 13:11:08 +0200
commit22bfa00d56233ddb93394b23313efb7c2fcebbc8 (patch)
tree64621a806adceb68e8ccc9c1ab080ffca87e6208 /src
parent513e102fc92aabfeffc441c75c4f87c31cdc4cc6 (diff)
Improve parser documentation
Diffstat (limited to 'src')
-rw-r--r--src/parser.py52
1 files changed, 30 insertions, 22 deletions
diff --git a/src/parser.py b/src/parser.py
index 69718e5..4836bdf 100644
--- a/src/parser.py
+++ b/src/parser.py
@@ -1,3 +1,32 @@
+"""
+Load .fcard files into dictionaries.
+
+The parser expects .fcard files in the following format:
+
+FRONT
+This is the front of the first card.
+
+BACK
+This is the back of the first card.
+
+FRONT
+This is another card.
+
+Multiple lines on the front are allowed.
+
+BACK
+Multiple lines on the back?
+
+Also allowed.
+
+FRONT
+...
+
+The cards are represented in dictionary entries of the form:
+
+id: (front_text, back_text)
+"""
+
from pathlib import Path
from collections import namedtuple
from enum import Enum
@@ -65,28 +94,7 @@ def _getCards(f: TextIO) -> Iterator[tuple[id, Card]]:
def parse(path: Path) -> dict[int, Card]:
"""
- Parse a .fcard file and return a list of Card instances.
-
- The parser expects .fcard files in the following format:
-
- FRONT
- This is the front of the first card.
-
- BACK
- This is the back of the first card.
-
- FRONT
- This is another card.
-
- Multiple lines on the front are allowed.
-
- BACK
- Multiple lines on the back?
-
- Also allowed.
-
- FRONT
- ...
+ Parse a .fcard file and return a dictionary of Card instances indexed by ID.
"""
if not path.is_file():
print(f"[Warning] Not a file: {path}")