The OpenQASM code string to parse
Optionalversion: number | OpenQASMVersionThe OpenQASM version to use (defaults to 3.0)
Optionalverbose: booleanWhether to include class names in the output (defaults to false)
Optionalstringify: booleanWhether to return stringified JSON (defaults to false)
The corresponding AST as an array of nodes, or stringified JSON if stringify is true
import { parseString } from 'qasm-ts';
const qasmCode = `
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
h q[0];
cx q[0], q[1];
`;
const ast = parseString(qasmCode);
console.log(ast);
Parses OpenQASM code from a string and returns the abstract syntax tree.
This is the primary entry point for parsing OpenQASM code. It handles both OpenQASM 2.0 and 3.0 syntax, automatically selecting the appropriate lexer and parser based on the version parameter.