SPACE = ' '
_INDENT_CHARS = {SPACE, '\t'}
SEP_COMMENTS = ';'
-_PREFIX_DEF = '#desc '
-_PREFIX_BAL = '#balancer '
+_PREFIX_INSTRUCTION = '#'
+_ACC_MOD_INSTRUCTORS = {'description', 'balancer'}
class _Wealth():
class _Account:
'Combine name, position in tree of owner, and wealth of self + children.'
- desc = ''
+ description = ''
balancer = ''
def __init__(self, parent: Optional[Self], basename: str) -> None:
'Either IntroLine or TransferLine instructions.'
return self._into_parts()[1]
+ def _comment_unstripped(self) -> str:
+ 'Anything past ";".'
+ return self._into_parts()[2][1:]
+
@property
def comment(self) -> str:
'Anything past ";", with whitespace in-between stripped.'
- return self._into_parts()[2][1:].lstrip()
+ return self._comment_unstripped().lstrip()
@property
def raw(self) -> str:
return self._raw[:]
@property
- def comment_instructions(self) -> dict[str, dict[str, str]]:
+ def comment_instructions(self) -> Optional[tuple[str, str, str]]:
'Parse .comment into _Account modification instructions.'
- instructions: dict[str, dict[str, str]] = {}
- for prefix in (_PREFIX_DEF, _PREFIX_BAL):
- attr_name = prefix[1:].rstrip()
- instructions[attr_name] = {}
- if self.comment.startswith(prefix):
- parts = tuple(part.strip() for part
- in self.comment[len(prefix):].split(maxsplit=1))
- if not parts:
- continue
- instructions[attr_name][parts[0]] = ''.join(parts[1:])
- return instructions
+ toks = self._comment_unstripped().split(maxsplit=2)
+ if len(toks) == 3 and toks[0].startswith(_PREFIX_INSTRUCTION):
+ instructor = toks[0][len(_PREFIX_INSTRUCTION):]
+ if instructor in _ACC_MOD_INSTRUCTORS:
+ return (toks[1], instructor, toks[2])
+ return None
class _BookingLine(_DatLine, ABC):
for block in self.blocks:
collect_more_than_names = id_ < 0 or block.id_ <= id_
for line in block.lines:
- for attr_name, defs in line.comment_instructions.items():
- for acc_name, definition in defs.items():
- ensure_accounts(acc_name)
- if collect_more_than_names and definition:
- setattr(accounts[acc_name], attr_name, definition)
+ if (toks := line.comment_instructions):
+ ensure_accounts(toks[0])
+ if collect_more_than_names:
+ setattr(accounts[toks[0]], toks[1], toks[2])
if block.booking:
for acc_name, wealth in block.booking.diffs_targeted.items():
ensure_accounts(acc_name)
{{- account.basename }}
{{- ":" if account.children }}
{{_()}} </td>
-{{_()}} <td>{{ account.desc }}</td>
+{{_()}} <td>{{ account.description }}</td>
{{_()}}</tr>
{##}{% for child in account.children_euro_sorted_at(block_id) %}
{{- account_with_children(block_id, child, name_indent=name_indent+1) -}}
-; #desc bar:x bla bla bla
+;#description bar:x bla bla bla
2001-01-01 test ; foo
; in-body comment 1
bar:x:y -10 €
bar:z -1 USD
-; #desc bar:x bla foo bla
+;#description bar:x bla foo bla
2001-01-03 test
foo:x 10 €
</span>
<hr>
-<textarea name="raw_lines" class="tainter" cols="100" rows="9">; #desc bar:x bla bla bla
+<textarea name="raw_lines" class="tainter" cols="100" rows="9">;#description bar:x bla bla bla
2001-01-01 test ; foo
; in-body comment 1
</span>
<hr>
<div>Gap:</div>
-<textarea id="gap_lines" name="raw_lines" cols="100" rows="3" class="tainter">; #desc bar:x bla bla bla
+<textarea id="gap_lines" name="raw_lines" cols="100" rows="3" class="tainter">;#description bar:x bla bla bla
</textarea>
<EXPANDED>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
<hr>
<div>Gap:</div>
<textarea id="gap_lines" name="raw_lines" cols="100" rows="4" class="tainter">
-; #desc bar:x bla foo bla
+;#description bar:x bla foo bla
</textarea>
<EXPANDED>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
</td>
<td colspan="1">
<button type="button">add new</button>
+ <button type="button">balance</button>
<button type="button">delete</button>
</td>
</tr>
[<a href="/edit_raw/0">e</a>]
</td>
</tr>
- <tr><td>; #desc bar:x bla bla bla </td></tr>
+ <tr><td>;#description bar:x bla bla bla </td></tr>
<tr><td> </td></tr>
<tr><td>2001-01-01 test ; foo </td></tr>
<tr><td> ; in-body comment 1 </td></tr>
</td>
</tr>
<tr><td> </td></tr>
- <tr><td>; #desc bar:x bla foo bla </td></tr>
+ <tr><td>;#description bar:x bla foo bla </td></tr>
<tr><td> </td></tr>
<tr><td>2001-01-03 test </td></tr>
<tr><td> foo:x 10 € </td></tr>
</td>
</tr>
<tr>
- <td colspan="4">; #desc bar:x bla bla bla </td>
+ <td colspan="4">;#description bar:x bla bla bla </td>
</tr>
<tr>
<td colspan="4"> </td>
<td colspan="4"> </td>
</tr>
<tr>
- <td colspan="4">; #desc bar:x bla foo bla </td>
+ <td colspan="4">;#description bar:x bla foo bla </td>
</tr>
<tr>
<td colspan="4"> </td>