feat(node): add header, footer, prefix, suffix, data_type, value fields
- CTNode에 6개 신규 필드 추가 - header : 머리글 (노드 블록 앞 텍스트) - footer : 꼬리글 (노드 블록 뒤 텍스트) - prefix : 접두사 (content 직전 인라인) - suffix : 접미사 (content 직후 인라인) - data_type : 값의 자료형 힌트 (DataType enum) - value : 해석된 값 (Any — str/int/float/bool/list/dict 등) - types.py: DataType enum 추가 (UNSET, STRING~CODE, CUSTOM) - node.py: full_text() 메서드 추가 (6개 필드 순서대로 조합) - tree.py: to_dict / from_dict 직렬화에 신규 필드 포함 - 테스트: test_node_fields.py 신규 추가 (15개 케이스) - 전체 테스트 42/42 통과
This commit is contained in:
@@ -8,7 +8,7 @@ from __future__ import annotations
|
||||
from typing import Any, Callable, Iterator, Optional
|
||||
|
||||
from .node import CTNode
|
||||
from .types import NodeType
|
||||
from .types import NodeType, DataType
|
||||
|
||||
|
||||
class CTTree:
|
||||
@@ -150,11 +150,19 @@ class CTTree:
|
||||
"""트리 전체를 Python dict 로 직렬화."""
|
||||
def _serialize(node: CTNode) -> dict:
|
||||
return {
|
||||
"id": node.node_id,
|
||||
"type": node.node_type.name,
|
||||
"content": node.content,
|
||||
"id": node.node_id,
|
||||
"type": node.node_type.name,
|
||||
"content": node.content,
|
||||
"attributes": node.attributes,
|
||||
"children": [_serialize(c) for c in node.children],
|
||||
# ── 텍스트 장식 ──
|
||||
"header": node.header,
|
||||
"footer": node.footer,
|
||||
"prefix": node.prefix,
|
||||
"suffix": node.suffix,
|
||||
# ── 타입 값 ──
|
||||
"data_type": node.data_type.value,
|
||||
"value": node.value,
|
||||
"children": [_serialize(c) for c in node.children],
|
||||
}
|
||||
return _serialize(self.root)
|
||||
|
||||
@@ -164,11 +172,23 @@ class CTTree:
|
||||
tree = cls()
|
||||
|
||||
def _deserialize(d: dict) -> CTNode:
|
||||
raw_dtype = d.get("data_type", DataType.UNSET.value)
|
||||
try:
|
||||
dtype = DataType(raw_dtype)
|
||||
except ValueError:
|
||||
dtype = DataType.CUSTOM
|
||||
|
||||
node = CTNode(
|
||||
node_type=NodeType[d["type"]],
|
||||
content=d.get("content"),
|
||||
attributes=d.get("attributes", {}),
|
||||
node_id=d.get("id", ""),
|
||||
node_type = NodeType[d["type"]],
|
||||
content = d.get("content"),
|
||||
attributes = d.get("attributes", {}),
|
||||
node_id = d.get("id", ""),
|
||||
header = d.get("header"),
|
||||
footer = d.get("footer"),
|
||||
prefix = d.get("prefix"),
|
||||
suffix = d.get("suffix"),
|
||||
data_type = dtype,
|
||||
value = d.get("value"),
|
||||
)
|
||||
for child_data in d.get("children", []):
|
||||
node.append(_deserialize(child_data))
|
||||
|
||||
Reference in New Issue
Block a user