算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
grammar-conformance【设计与创意】Reason about OpenQASM 3 lexical and syntactic conformance, parser acceptance, diagnostics, and fixture design without conflating parsing with semantic or execution validity.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the question is is this valid syntax, which grammar rule accepts this, an ANTLR parse error, a parser accept/reject dispute, or a conformance fixture. This is the grammar-and-parser boundary for the OpenQASM 3 reference implementation.
openqasm3 parse check. It reads exactly one path, --source, or stdin.If the question is about the meaning of a language construct or how to author a useful OpenQASM program, route to language-authoring. If it is about Python AST classes, visitors, transformers, or printing, route to python-ast-tooling.
Own lexical rules, parser-rule acceptance, diagnostics, and conformance fixture methodology. Do not use this sub-skill for normative source design, complete semantic/type checking, lowering, optimization, execution, provider compilation, or generated-parser release/maintenance workflows. Those later layers may consume a syntax result but must not be inferred from it.
The public Python parser exposes:
parse(input_: str, *, permissive=False, ignore_version=False) -> Program
parse_version(prog: str) -> Optional[Tuple[int, ...]]
get_comments(input_: str) -> List[dict]
The inspected package is openqasm3 1.0.1. Its declared supported versions
are 3.0 and 3.1. parse returns an AST Program, not an ANTLR concrete
syntax tree. parse_version only detects a potential first OPENQASM header;
it can return a version for input that later fails parsing or version policy.
parse_version first. A valid-looking
header must be the first non-comment construct. With normal parsing,
unsupported versions and more than two version components are rejected;
ignore_version=True is only a diagnostic experiment.parse(source) or the helper with default strict
behavior. Capture success, exception class/message, line, and column. Do
not use permissive=True to prove conformance.dumps, route to
the Python AST sub-skill. For exact ANTLR rule acceptance, compare the
expected rule path/tree in a grammar harness generated from the same grammar
and runtime minor.include "name"; and defcalgrammar "name"; require a non-empty quoted
string token, but parsing does not open or resolve that name.OPENQASM 3; or OPENQASM 3.0; header is accepted. No header is also
accepted by this parser and produces an AST with no version; it is not proof
that a downstream tool accepts headerless input.get_comments. Newlines normally separate tokens only where grammar needs
them; annotations and pragmas explicitly consume the rest of their line.cal and defcal bodies are opaque to the OpenQASM grammar except for
balanced braces. Their payload is not pulse-language validation.break; outside a loop, a pragma outside global scope, a
non-unitary operation in a gate, or invalid built-in argument counts. Label
these parser-context checks, not grammar rejection.A useful conformance fixture has a stable id, minimal source, expected layer,
expected accept/reject result, and expected observation. Positive grammar
fixtures should name the top rule (for example expressionStatement,
includeStatement, gateStatement, or calStatement) and, where useful, the
nested rule path. Negative fixtures should identify the first deliberately
invalid token or delimiter and avoid relying on an unstable full ANTLR error
string. Diagnostic tests may assert line/column and a stable message fragment.
Do not copy generated parser files into this runtime skill. Do not add native test output, reports, caches, or review artifacts here; place only reusable routing material, references, and the bounded helper in this subtree.