masaori335 commented on code in PR #14038:
URL: https://github.com/apache/trafficserver/pull/14038#discussion_r4534182798


##########
tools/hrw4u/src/common.py:
##########
@@ -309,24 +302,51 @@ def compile_to_conf(
     sema.source_map.add(filename, source_text)
     program = sema.analyze(ast)
     if error_collector is not None and error_collector.has_errors():
+        return None
+    return sema, ast, program
+
+
+def compile_to_conf(tree: Any, filename: str, source_text: str, **kwargs: Any) 
-> list[str]:
+    """Compile to header_rewrite lines through the resolved tree.
+
+    The single wiring both the CLI and the parity test use, so the two cannot 
drift. A
+    run that reported an error returns no lines: what the emitter renders 
around an
+    unresolved node is not a configuration anyone asked for.
+    """
+    from hrw4u.emit_conf import ConfEmitter
+
+    if (analyzed := _analyze(tree, filename, source_text, **kwargs)) is None:
         return []
+    _, _, program = analyzed
     return ConfEmitter().emit(program)
 
 
+def compile_to_hrw4u(tree: Any, filename: str, source_text: str, **kwargs: 
Any) -> list[str]:
+    """Rewrite to hrw4u with every procedure call written out in place, so the 
program needs no
+    procedures path. Fails like compile_to_conf."""
+    from hrw4u.ast_unparse import unparse
+
+    if (analyzed := _analyze(tree, filename, source_text, **kwargs)) is None:
+        return []
+    sema, ast, _ = analyzed
+    return unparse(sema.expand(ast)).splitlines()

Review Comment:
   Fixed in c2af966b78: compile_to_hrw4u now splits only on the LF that unparse 
emits. It uses split("\n")[:-1] rather than removesuffix("\n").split("\n"), so 
that an empty program still yields no lines; the latter would make the CLI 
print a lone newline. Added a CLI test with U+2028 in a comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to