计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
python-ast-tooling【效率与协作】Use openqasm3 from Python to parse and print OpenQASM 3, construct and inspect its AST, traverse or conservatively transform nodes, and validate compiler-pass scaffolding with parse-print-reparse checks.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the task mentions openqasm3, Python AST nodes, parse,
dumps, source spans or comments, AST visitors, transformers, identifier
rewrites, or a small compiler-pass scaffold. It covers the reference Python
API, not a complete semantic compiler or a provider toolchain.
Read the focused references before an expert workflow:
The AST and printer are available from the openqasm3 package. Install the
parser extra for parsing text:
python -m pip install 'openqasm3[parser]'
Confirm the runtime rather than assuming a remembered API:
import inspect
import openqasm3
from openqasm3 import ast, spec
print(openqasm3.__version__, spec.supported_versions)
print(inspect.signature(openqasm3.parse))
print(len(ast.__all__))
The current verified baseline is package version 1.0.1, with specification
versions 3.0 and 3.1 supported by the parser. The AST API is explicitly
unstable; if a signature or node field differs, use the installed runtime's
introspection and then record the discrepancy.
openqasm3.parse_version(text) when choosing
a parser or diagnosing a source. It returns an integer tuple or None.openqasm3.parse(text) with defaults. Use
permissive=True only for exploratory recovery, and treat any recovered AST
as potentially invalid. Use ignore_version=True only for deliberate
compatibility experiments, never as proof of conformance.QASMVisitor/
QASMTransformer; do not assume a binding or semantic symbol table exists.openqasm3.dumps(program, ...), then parse the
result again. Compare AST structure after deliberately ignoring spans when
testing formatting-only changes. A successful reparse proves grammar/parser
acceptance, not semantic or provider validity.openqasm3.ast: dataclass AST nodes, enums, Span, and base classes.openqasm3.parse and openqasm3.parser.parse: text to ast.Program.openqasm3.parse_version: leading version probe.openqasm3.parser.get_comments: separate line/block comment extraction.openqasm3.dump/dumps: AST to normalized text.openqasm3.printer.Printer: configurable visitor-backed printer.openqasm3.visitor.QASMVisitor: read-only traversal base.openqasm3.visitor.QASMTransformer: in-place rewrite base.openqasm3.properties.precedence: expression precedence comparison only.For repeatable inspection, use scripts/inspect_program.py. For a deliberately
narrow rename demonstration, use scripts/rename_identifiers.py; it refuses
obvious global collisions, reparses before success, and never silently
replaces the input file.