Open jlapeyre opened 8 months ago
I would like to work on this issue as a start for contributing to #119!
I see in openqasm3_parser/crates/oq3_parser/src/grammar/items.rs that there are kinds defined in openqasm3_parser/crates/oq3_parser/src/syntax_kind/syntax_kind_enum.rs, but I don't see one specifically for EXTERN
, only one for EXTERN_KW
. I assume this is needed, so does this need to be defined manually or was it supposed to be generated at some point? Also, although it wasn't mentioned in the tasks, would it be correct to add Extern
to each of the casting-related functions for Stmt
and AnyHasName
?
For example this fails to parse without errors, although it is valid OQ3.
Implementing
extern
requires several steps, as do most or all language features. However there is a model that you can follow closely at every step.AST
Add
Extern
to this (alphabetized) list https://github.com/Qiskit/openqasm3_parser/blob/ea3ab9c002eb314241f3c7ee7af1727eca18b135/crates/oq3_syntax/openqasm3.ungram#L74Make an entry like the following for
Extern
https://github.com/Qiskit/openqasm3_parser/blob/ea3ab9c002eb314241f3c7ee7af1727eca18b135/crates/oq3_syntax/openqasm3.ungram#L155-L158It will be just about the same as the entry for
Def
, but of course, the block will be absent.Add
EXTERN
to ast_src.rs in the same list whereDEF
appears: https://github.com/Qiskit/openqasm3_parser/blob/ea3ab9c002eb314241f3c7ee7af1727eca18b135/crates/oq3_syntax/src/tests/ast_src.rs#L149Generate code with
If this fails, you might ask in this issue for help.
Check that code was generated similar to this code for
Def
: https://github.com/Qiskit/openqasm3_parser/blob/ea3ab9c002eb314241f3c7ee7af1727eca18b135/crates/oq3_syntax/src/ast/generated/nodes.rs#L150-L167These methods will be called from
syntax_to_semantics.rs
to translate the AST to ASG.substituting
extern
fordef
. And https://github.com/Qiskit/openqasm3_parser/blob/ea3ab9c002eb314241f3c7ee7af1727eca18b135/crates/oq3_parser/src/grammar/items.rs#L339-L357ASG
Follow this model: https://github.com/Qiskit/openqasm3_parser/blob/ea3ab9c002eb314241f3c7ee7af1727eca18b135/crates/oq3_semantics/src/asg.rs#L180
https://github.com/Qiskit/openqasm3_parser/blob/ea3ab9c002eb314241f3c7ee7af1727eca18b135/crates/oq3_semantics/src/asg.rs#L622-L628
AST -> ASG
Follow this model: https://github.com/Qiskit/openqasm3_parser/blob/ea3ab9c002eb314241f3c7ee7af1727eca18b135/crates/oq3_semantics/src/syntax_to_semantics.rs#L368-L390
Done
And it's as easy as that! Now enjoy parsing
extern
statements !