From 4ec0f069f06cae1413cdc3ce2d2cd89247380f16 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 16 Nov 2022 12:47:51 -0800 Subject: [PATCH] Remove legacy parsing from `wit-parser` There's no longer any need to parse a single `Interface`, so support for parsing that from a file can now be removed. --- crates/wit-parser/src/ast.rs | 9 ------ crates/wit-parser/src/lib.rs | 59 ------------------------------------ 2 files changed, 68 deletions(-) diff --git a/crates/wit-parser/src/ast.rs b/crates/wit-parser/src/ast.rs index 218f469d9d..8f48308717 100644 --- a/crates/wit-parser/src/ast.rs +++ b/crates/wit-parser/src/ast.rs @@ -201,15 +201,6 @@ impl<'a> Interface<'a> { } Ok(items) } - - pub(super) fn parse_legacy_items(tokens: &mut Tokenizer<'a>) -> Result>> { - let mut items = Vec::new(); - while tokens.clone().next()?.is_some() { - let docs = parse_docs(tokens)?; - items.push(InterfaceItem::parse(tokens, docs)?); - } - Ok(items) - } } pub enum InterfaceItem<'a> { diff --git a/crates/wit-parser/src/lib.rs b/crates/wit-parser/src/lib.rs index 4e6e9d46e1..e53ac01477 100644 --- a/crates/wit-parser/src/lib.rs +++ b/crates/wit-parser/src/lib.rs @@ -407,65 +407,6 @@ fn unwrap_md(contents: &str) -> String { } impl Interface { - pub fn parse(name: &str, input: &str) -> Result { - Interface::parse_with(name, input) - } - - pub fn parse_file(path: impl AsRef) -> Result { - let path = path.as_ref(); - let contents = std::fs::read_to_string(&path) - .with_context(|| format!("failed to read: {}", path.display()))?; - Interface::parse_with(path, &contents) - } - - pub fn parse_with(filename: impl AsRef, contents: &str) -> Result { - Interface::_parse_with(filename.as_ref(), contents) - } - - fn _parse_with(filename: &Path, contents: &str) -> Result { - let name = filename - .file_name() - .context("wit path must end in a file name")? - .to_str() - .context("wit filename must be valid unicode")? - // TODO: replace with `file_prefix` if/when that gets stabilized. - .split(".") - .next() - .unwrap(); - let mut contents = contents; - - // If we have a ".md" file, it's a wit file wrapped in a markdown file; - // parse the markdown to extract the `wit` code blocks. - let md_contents; - if filename.extension().and_then(|s| s.to_str()) == Some("md") { - md_contents = unwrap_md(contents); - contents = &md_contents[..]; - } - - let mut lexer = Tokenizer::new(&contents)?; - - // Parse the `contents `into an AST - let items = match ast::Interface::parse_legacy_items(&mut lexer) { - Ok(ast) => ast, - Err(mut e) => { - let file = filename.display().to_string(); - ast::rewrite_error(&mut e, &file, contents); - return Err(e); - } - }; - - // and finally resolve everything into our final instance - let mut resolver = ast::Resolver::default(); - match resolver.resolve(name, &items, &Default::default()) { - Ok(i) => Ok(i), - Err(mut e) => { - let file = filename.display().to_string(); - ast::rewrite_error(&mut e, &file, contents); - Err(e) - } - } - } - pub fn topological_types(&self) -> Vec { let mut ret = Vec::new(); let mut visited = HashSet::new();