Skip to content

Commit

Permalink
Working on better parser API
Browse files Browse the repository at this point in the history
  • Loading branch information
stepancheg committed Feb 7, 2022
1 parent 908147d commit eae7ac4
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
8 changes: 6 additions & 2 deletions protobuf-codegen/src/codegen/pure.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use protobuf_parse::pure;
use protobuf_parse::Parser;
use protobuf_parse::ParsedAndTypechecked;

use crate::codegen::Codegen;

pub(crate) fn parse_and_typecheck(
codegen: &Codegen,
) -> anyhow::Result<(ParsedAndTypechecked, String)> {
let p = pure::parse_and_typecheck(&codegen.includes, &codegen.inputs)?;
let p = Parser::new()
.pure()
.includes(&codegen.includes)
.inputs(&codegen.inputs)
.parse_and_typecheck()?;
Ok((p, format!("protobuf-codegen={}", env!("CARGO_PKG_VERSION"))))
}
4 changes: 2 additions & 2 deletions protobuf-parse/src/bin/parse-and-typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;
use std::path::PathBuf;
use std::process::exit;

use protobuf_parse::pure;
use protobuf_parse::Parser;

fn main() {
let args = env::args_os()
Expand All @@ -25,7 +25,7 @@ fn main() {

assert!(args.len() >= 2);
let (input, includes) = args.split_at(1);
let t = pure::parse_and_typecheck(includes, input).expect("parse_and_typecheck");
let t = Parser::new().pure().includes(includes).inputs(input).parse_and_typecheck().expect("parse_and_typecheck");
for fd in t.file_descriptors {
println!("{:#?}", fd);
}
Expand Down
4 changes: 2 additions & 2 deletions protobuf-parse/src/parse_and_typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub(crate) fn parse_and_typecheck(
input: &[PathBuf],
) -> anyhow::Result<ParsedAndTypechecked> {
match which_parser {
WhichParser::Pure => pure::parse_and_typecheck(includes, input),
WhichParser::Protoc => protoc::parse_and_typecheck(includes, input),
WhichParser::Pure => pure::parse_and_typecheck::parse_and_typecheck(includes, input),
WhichParser::Protoc => protoc::parse_and_typecheck::parse_and_typecheck(includes, input),
}
}

Expand Down
4 changes: 1 addition & 3 deletions protobuf-parse/src/protoc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//! Parse `.proto` files using `protoc` command.
mod parse_and_typecheck;

pub use parse_and_typecheck::*;
pub(crate) mod parse_and_typecheck;
4 changes: 2 additions & 2 deletions protobuf-parse/src/protoc/parse_and_typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use protobuf::descriptor::FileDescriptorSet;
use protobuf::Message;
use protoc::Protoc;

use crate::pure::path_to_proto_path;
use crate::ParsedAndTypechecked;
use crate::ProtoPathBuf;
use crate::pure::parse_and_typecheck::path_to_proto_path;

/// Parse `.proto` files using `protoc` command.
pub fn parse_and_typecheck(
pub(crate) fn parse_and_typecheck(
includes: &[PathBuf],
input: &[PathBuf],
) -> anyhow::Result<ParsedAndTypechecked> {
Expand Down
2 changes: 1 addition & 1 deletion protobuf-parse/src/pure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ pub(crate) mod parse_and_typecheck;
pub(crate) mod parse_dependencies;
mod parser;

pub use parse_and_typecheck::*;
pub use parse_dependencies::*;
pub use parse_and_typecheck::parse_and_typecheck_custom;
2 changes: 1 addition & 1 deletion protobuf-parse/src/pure/parse_and_typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub fn parse_and_typecheck(
})
}

#[doc(hidden)]
/// TODO: this API is to be refactored.
pub fn parse_and_typecheck_custom(
input: &[ProtoPathBuf],
resolver: impl ProtoPathResolver,
Expand Down

0 comments on commit eae7ac4

Please sign in to comment.