braket.default_simulator.openqasm.parser.openqasm_parser module
Parser (openqasm3.parser
)
Tools for parsing OpenQASM 3 programs into the reference AST
.
The quick-start interface is simply to call openqasm3.parse
:
The rest of this module provides some lower-level internals of the parser.
- braket.default_simulator.openqasm.parser.openqasm_parser.parse(input_: str, *, permissive=False) Program [source]
Parse a complete OpenQASM 3 program from a string.
- Parameters:
input – A string containing a complete OpenQASM 3 program.
permissive – A Boolean controlling whether ANTLR should attempt to recover from incorrect input or not. Defaults to
False
; if set toTrue
, the reference AST produced may be invalid if ANTLR emits any warning messages during its parsing phase.
- Returns:
A complete
Program
node.
- braket.default_simulator.openqasm.parser.openqasm_parser.get_span(node: ParserRuleContext | TerminalNode) Span [source]
Get the span of a node
- braket.default_simulator.openqasm.parser.openqasm_parser.add_span(node: _NodeT, span: Span) _NodeT [source]
Set the span of a node and return the node
- braket.default_simulator.openqasm.parser.openqasm_parser.combine_span(first: Span, second: Span)[source]
Combine two spans and return the combined one
- braket.default_simulator.openqasm.parser.openqasm_parser.span(func)[source]
Function decorator to automatic attach span to nodes for visit* methods.
- class braket.default_simulator.openqasm.parser.openqasm_parser.QASMNodeVisitor[source]
Bases:
qasm3ParserVisitor
- visitScope(ctx: ScopeContext) List[Statement] [source]
- visitPowerExpression(**kwargs)
- visitMultiplicativeExpression(**kwargs)
- visitAdditiveExpression(**kwargs)
- visitBitshiftExpression(**kwargs)
- visitComparisonExpression(**kwargs)
- visitEqualityExpression(**kwargs)
- visitBitwiseAndExpression(**kwargs)
- visitBitwiseXorExpression(**kwargs)
- visitBitwiseOrExpression(**kwargs)
- visitLogicalAndExpression(**kwargs)
- visitLogicalOrExpression(**kwargs)
- visitIndexOperator(ctx: IndexOperatorContext)[source]
- visitStatementOrScope(ctx: StatementOrScopeContext) List[Statement] [source]