feat: composer improvements

This commit is contained in:
2026-04-05 09:53:01 +02:00
parent 7838760ca4
commit e1db06104e
17 changed files with 1301 additions and 332 deletions

View File

@@ -138,7 +138,7 @@ def _parse_list_style(s: str) -> ListStyle:
}.get(s.lower(), ListStyle.BULLET)
def _parse_line(keyword: str, args: list[str], line_num: int) -> IRNode:
def _parse_line(keyword: str, args: list[str], line_num: int, raw_args: str = "") -> IRNode:
"""Parse a single line into an IR node based on the keyword."""
if keyword == "page":
@@ -364,7 +364,7 @@ def _parse_line(keyword: str, args: list[str], line_num: int) -> IRNode:
# Dynamic features
elif keyword == "let":
# let name = "value" or let name = 1,2,3
raw = " ".join(args)
raw = raw_args
eq = raw.find("=")
if eq != -1:
var_name = raw[:eq].strip()
@@ -377,11 +377,10 @@ def _parse_line(keyword: str, args: list[str], line_num: int) -> IRNode:
elif keyword == "source":
# source cpu : shell "grep 'cpu' /proc/stat"
# source name : type "command"
raw = " ".join(args)
colon = raw.find(":")
colon = raw_args.find(":")
if colon != -1:
var_name = raw[:colon].strip()
rest = raw[colon + 1:].strip()
var_name = raw_args[:colon].strip()
rest = raw_args[colon + 1:].strip()
parts = _split_args(rest)
src_type_str = parts[0] if parts else "shell"
command = parts[1] if len(parts) > 1 else ""
@@ -392,17 +391,38 @@ def _parse_line(keyword: str, args: list[str], line_num: int) -> IRNode:
"python": SourceType.PYTHON,
"rns": SourceType.RNS,
"param": SourceType.PARAM,
"http": SourceType.HTTP,
"sqlite": SourceType.SQLITE,
"env": SourceType.ENV,
}.get(src_type_str.lower(), SourceType.SHELL)
# Parse optional timeout
# Parse optional params from remaining parts
timeout = 5
for p in parts[2:]:
if p.startswith("timeout"):
http_method = "GET"
http_body = ""
http_headers = ""
query = ""
extra = parts[2:]
if src_type == SourceType.SQLITE and len(parts) > 2:
# sqlite "/path/db" "SELECT ..."
query = parts[2]
extra = parts[3:]
for p in extra:
if p.startswith("timeout="):
try:
timeout = int(p.split("=")[1]) if "=" in p else int(parts[parts.index(p) + 1])
timeout = int(p.split("=", 1)[1])
except (ValueError, IndexError):
pass
elif p.startswith("method="):
http_method = p.split("=", 1)[1].upper()
elif p.startswith("body="):
http_body = p.split("=", 1)[1]
elif p.startswith("headers="):
http_headers = p.split("=", 1)[1]
return Source(var_name=var_name, source_type=src_type,
command=command, timeout=timeout, source_line=line_num)
command=command, timeout=timeout,
http_method=http_method, http_body=http_body,
http_headers=http_headers, query=query,
source_line=line_num)
else:
return Source(var_name=args[0] if args else "", source_line=line_num)
@@ -817,7 +837,7 @@ def parse(source: str, components: dict[str, ComponentDef] | None = None) -> Pag
args = _split_args(arg_str)
# Parse this line into a node
node = _parse_line(keyword, args, line_num)
node = _parse_line(keyword, args, line_num, raw_args=arg_str)
# Pop stack back to find the parent (parent indent < this indent)
while stack and stack[-1][0] >= indent: