Skip to content

Commit

Permalink
Prepare crates for publishing
Browse files Browse the repository at this point in the history
This commit updates the openqasm3_parser project for publishing crates.
Primarily this involves unifying the packaging metadata between all the
crates in the workspace. The other big change is all the crates and
library names are renamed to have a `oq3_` prefix with the exception of
qasm3_bytecode because it already had a descriptive name that was
unlikely to conflict with anything.
  • Loading branch information
mtreinish committed Jan 11, 2024
1 parent a430111 commit 3d2a342
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 167 deletions.
43 changes: 12 additions & 31 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,26 @@ members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.0.1"
rust-version = "1.70"
edition = "2021"
license = "MIT OR Apache-2.0"
license = "Apache-2.0"
authors = ["OpenQASM3 parser team"]

[profile.dev]
# Disabling debug info speeds up builds a bunch,
# and we don't rely on it for debugging that much.
# debug = 0

[profile.dev.package]
# These speed up local tests.
# rowan.opt-level = 3
# rustc-hash.opt-level = 3
# smol_str.opt-level = 3
# text-size.opt-level = 3
# # This speeds up `cargo xtask dist`.
# miniz_oxide.opt-level = 3

# [profile.release]
# incremental = true
# # Set this to 1 or 2 to get more useful backtraces in debugger.
# debug = 0
readme = "README.md"
keywords = ["QASM", "OpenQASM3", "parser"]
categories = ["parser-implementations"]
repository = "https://github.com/Qiskit/openqasm3_parser"

[workspace.dependencies]
# local crates

lexer = { path = "./crates/lexer", version = "0.0.0" }
parser = { path = "./crates/parser", version = "0.1.0" }
oq3_syntax = { path = "./crates/oq3_syntax", version = "0.0.0" }
semantics = { path = "./crates/semantics", version = "0.0.0" }
sourcegen = { path = "./crates/sourcegen", version = "0.0.0" }
ast_pyo3 = { path = "./crates/ast_pyo3", version = "0.0.0" }
source_file = { path = "./crates/source_file", version = "0.0.0" }
oq3_lexer = { path = "crates/lexer", version = "0.0.1" }
oq3_parser = { path = "crates/parser", version = "0.0.1" }
oq3_syntax = { path = "crates/oq3_syntax", version = "0.0.1" }
oq3_semantics = { path = "crates/semantics", version = "0.0.1" }
oq3_sourcegen = { path = "crates/sourcegen", version = "0.0.1" }
oq3_source_file = { path = "crates/source_file", version = "0.0.1" }

# non-local crates
# sourcegen has a hard-coded path. This is a bug, it cannot be used as a standalone crate
# sourcegen = { version = "0.0.187", package = "ra_ap_sourcegen" }
limit = { version = "0.0.188", package = "ra_ap_limit" }
stdx = { version = "0.0.188", package = "ra_ap_stdx"}
triomphe = { version = "0.1.8", default-features = false, features = ["std"] }
Expand All @@ -52,6 +34,5 @@ smallvec = { version = "1.10.0", features = [
smol_str = "0.2.0"
nohash-hasher = "0.2.0"
text-size = "1.1.0"

# can't upgrade due to dashmap depending on 0.12.3 currently
hashbrown = { version = "0.12.3", features = ["inline-more"], default-features = false }
14 changes: 11 additions & 3 deletions crates/lexer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
[package]
name = "lexer"
version = "0.0.0"
edition = "2021"
name = "oq3_lexer"
description = ""
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
authors.workspace = true
readme.workspace = true
keywords.workspace = true
categories.workspace = true
repository.workspace = true

[dependencies]
unicode-xid = "0.2.0"
Expand Down
31 changes: 10 additions & 21 deletions crates/oq3_syntax/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
[package]
name = "oq3_syntax"
version = "0.0.0"
description = "Comment and whitespace preserving parser for the OpenQASM 3 language"

authors.workspace = true
version.workspace = true
edition.workspace = true
license.workspace = true
rust-version.workspace = true
license.workspace = true
authors.workspace = true
readme.workspace = true
keywords.workspace = true
categories.workspace = true
repository.workspace = true

[lib]
doctest = false

[dependencies]

# external crates
cov-mark = "2.0.0-pre.1"
either = "1.7.0"
Expand All @@ -23,15 +25,10 @@ once_cell = "1.17.0"
indexmap = "2.0.0"
smol_str.workspace = true
triomphe.workspace = true

# local crates

# rustc_lexer.workspace = true
lexer.workspace = true
parser.workspace = true
# profile.workspace = true
oq3_lexer.workspace = true
oq3_parser.workspace = true
stdx.workspace = true
# text-edit.workspace = true

[dev-dependencies]
rayon = "1.6.1"
Expand All @@ -40,13 +37,5 @@ proc-macro2 = "1.0.47"
quote = "1.0.20"
ungrammar = "1.16.1"
clap = { version = "4.0", features = ["derive"] }

# local crate

sourcegen.workspace = true

# This brings in tons of things
#test-utils.workspace = true

# [features]
# in-rust-tree = []
oq3_sourcegen.workspace = true
4 changes: 2 additions & 2 deletions crates/oq3_syntax/src/ast/token_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use std::borrow::Cow;

use lexer::unescape::{unescape_byte, unescape_char, unescape_literal, Mode};
use oq3_lexer::unescape::{unescape_byte, unescape_char, unescape_literal, Mode};

use crate::{
ast::{self, AstToken},
Expand Down Expand Up @@ -164,7 +164,7 @@ pub trait IsString: AstToken {
}
fn escaped_char_ranges(
&self,
cb: &mut dyn FnMut(TextRange, Result<char, lexer::unescape::EscapeError>),
cb: &mut dyn FnMut(TextRange, Result<char, oq3_lexer::unescape::EscapeError>),
) {
let text_range_no_quotes = match self.text_range_between_quotes() {
Some(it) => it,
Expand Down
2 changes: 1 addition & 1 deletion crates/oq3_syntax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub use crate::{
},
token_text::TokenText,
};
pub use parser::{SyntaxKind, T};
pub use oq3_parser::{SyntaxKind, T};
pub use rowan::{
api::Preorder, Direction, GreenNode, NodeOrToken, SyntaxText, TextRange, TextSize,
TokenAtOffset, WalkEvent,
Expand Down
16 changes: 8 additions & 8 deletions crates/oq3_syntax/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ use rowan::TextRange;
use crate::{syntax_node::GreenNode, SyntaxError, SyntaxTreeBuilder};

pub fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
let lexed = parser::LexedStr::new(text);
let lexed = oq3_parser::LexedStr::new(text);
let parser_input = lexed.to_input();
let parser_output = parser::TopEntryPoint::SourceFile.parse(&parser_input);
let parser_output = oq3_parser::TopEntryPoint::SourceFile.parse(&parser_input);
let (node, errors, _eof) = build_tree(lexed, parser_output);
(node, errors)
}

pub(crate) fn build_tree(
lexed: parser::LexedStr<'_>,
parser_output: parser::Output,
lexed: oq3_parser::LexedStr<'_>,
parser_output: oq3_parser::Output,
) -> (GreenNode, Vec<SyntaxError>, bool) {
let mut builder = SyntaxTreeBuilder::default();

let is_eof = lexed.intersperse_trivia(&parser_output, &mut |step| match step {
parser::StrStep::Token { kind, text } => builder.token(kind, text),
parser::StrStep::Enter { kind } => builder.start_node(kind),
parser::StrStep::Exit => builder.finish_node(),
parser::StrStep::Error { msg, pos } => {
oq3_parser::StrStep::Token { kind, text } => builder.token(kind, text),
oq3_parser::StrStep::Enter { kind } => builder.start_node(kind),
oq3_parser::StrStep::Exit => builder.finish_node(),
oq3_parser::StrStep::Error { msg, pos } => {
builder.error(msg.to_string(), pos.try_into().unwrap())
}
});
Expand Down
2 changes: 1 addition & 1 deletion crates/oq3_syntax/src/ted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! up elements around the edges.
use std::{mem, ops::RangeInclusive};

use parser::T;
use oq3_parser::T;

use crate::{
ast::{self, edit::IndentLevel, make, AstNode},
Expand Down
4 changes: 2 additions & 2 deletions crates/oq3_syntax/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

mod block;
//mod lexer;
pub use parser::T;
pub use oq3_parser::T;

//use rowan::Direction;
use lexer::unescape::{self, unescape_literal, Mode};
use oq3_lexer::unescape::{self, unescape_literal, Mode};

use crate::{
ast::{self, IsString},
Expand Down
18 changes: 13 additions & 5 deletions crates/parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
[package]
name = "parser"
version = "0.1.0"
edition = "2021"
name = "oq3_parser"
description = ""
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
authors.workspace = true
readme.workspace = true
keywords.workspace = true
categories.workspace = true
repository.workspace = true

# Added this explicit target just so I could disable the doc tests (GJL Sept 2023)
[lib]
name = "parser"
name = "oq3_parser"
doctest = false

[dependencies]
lexer.workspace = true
oq3_lexer.workspace = true
drop_bomb = "0.1.5"

limit.workspace = true
Expand Down
Loading

0 comments on commit 3d2a342

Please sign in to comment.