Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the ability to turn off semicolons in WIT #1779

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions crates/wit-component/src/printing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::mem;
use wit_parser::*;

// NB: keep in sync with `crates/wit-parser/src/ast/lex.rs`
const PRINT_SEMICOLONS_DEFAULT: bool = true;
const PRINT_F32_F64_DEFAULT: bool = false;

/// A utility for printing WebAssembly interface definitions to a string.
Expand All @@ -19,7 +18,6 @@ pub struct WitPrinter {
// Whether to print doc comments.
emit_docs: bool,

print_semicolons: bool,
print_f32_f64: bool,
}

Expand All @@ -29,10 +27,6 @@ impl Default for WitPrinter {
output: Default::default(),
any_items: false,
emit_docs: true,
print_semicolons: match std::env::var("WIT_REQUIRE_SEMICOLONS") {
Ok(s) => s == "1",
Err(_) => PRINT_SEMICOLONS_DEFAULT,
},
print_f32_f64: match std::env::var("WIT_REQUIRE_F32_F64") {
Ok(s) => s == "1",
Err(_) => PRINT_F32_F64_DEFAULT,
Expand Down Expand Up @@ -119,9 +113,7 @@ impl WitPrinter {
}

fn print_semicolon(&mut self) {
if self.print_semicolons {
self.output.push_str(";");
}
self.output.push_str(";");
}

fn new_item(&mut self) {
Expand Down
9 changes: 1 addition & 8 deletions crates/wit-parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,6 @@ fn eat_id(tokens: &mut Tokenizer<'_>, expected: &str) -> Result<Span> {
pub struct SourceMap {
sources: Vec<Source>,
offset: u32,
require_semicolons: Option<bool>,
require_f32_f64: Option<bool>,
}

Expand All @@ -1641,11 +1640,6 @@ impl SourceMap {
SourceMap::default()
}

#[doc(hidden)] // NB: only here for a transitionary period
pub fn set_require_semicolons(&mut self, enable: bool) {
self.require_semicolons = Some(enable);
}

#[doc(hidden)] // NB: only here for a transitionary period
pub fn set_require_f32_f64(&mut self, enable: bool) {
self.require_f32_f64 = Some(enable);
Expand Down Expand Up @@ -1702,7 +1696,6 @@ impl SourceMap {
// passing through the source to get tokenized.
&src.contents[..src.contents.len() - 1],
src.offset,
self.require_semicolons,
self.require_f32_f64,
)
.with_context(|| format!("failed to tokenize path: {}", src.path.display()))?;
Expand Down Expand Up @@ -1872,7 +1865,7 @@ pub enum ParsedUsePath {
}

pub fn parse_use_path(s: &str) -> Result<ParsedUsePath> {
let mut tokens = Tokenizer::new(s, 0, Some(true), None)?;
let mut tokens = Tokenizer::new(s, 0, None)?;
let path = UsePath::parse(&mut tokens)?;
if tokens.next()?.is_some() {
bail!("trailing tokens in path specifier");
Expand Down
17 changes: 2 additions & 15 deletions crates/wit-parser/src/ast/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub struct Tokenizer<'a> {
input: &'a str,
span_offset: u32,
chars: CrlfFold<'a>,
require_semicolons: bool,
require_f32_f64: bool,
}

Expand Down Expand Up @@ -117,14 +116,12 @@ pub enum Error {
}

// NB: keep in sync with `crates/wit-component/src/printing.rs`.
const REQUIRE_SEMICOLONS_BY_DEFAULT: bool = true;
const REQUIRE_F32_F64_BY_DEFAULT: bool = false;

impl<'a> Tokenizer<'a> {
pub fn new(
input: &'a str,
span_offset: u32,
require_semicolons: Option<bool>,
require_f32_f64: Option<bool>,
) -> Result<Tokenizer<'a>> {
detect_invalid_input(input)?;
Expand All @@ -135,12 +132,6 @@ impl<'a> Tokenizer<'a> {
chars: CrlfFold {
chars: input.char_indices(),
},
require_semicolons: require_semicolons.unwrap_or_else(|| {
match std::env::var("WIT_REQUIRE_SEMICOLONS") {
Ok(s) => s == "1",
Err(_) => REQUIRE_SEMICOLONS_BY_DEFAULT,
}
}),
require_f32_f64: require_f32_f64.unwrap_or_else(|| {
match std::env::var("WIT_REQUIRE_F32_F64") {
Ok(s) => s == "1",
Expand All @@ -154,11 +145,7 @@ impl<'a> Tokenizer<'a> {
}

pub fn expect_semicolon(&mut self) -> Result<()> {
if self.require_semicolons {
self.expect(Token::Semicolon)?;
} else {
self.eat(Token::Semicolon)?;
}
self.expect(Token::Semicolon)?;
Ok(())
}

Expand Down Expand Up @@ -668,7 +655,7 @@ fn test_validate_id() {
#[test]
fn test_tokenizer() {
fn collect(s: &str) -> Result<Vec<Token>> {
let mut t = Tokenizer::new(s, 0, Some(true), None)?;
let mut t = Tokenizer::new(s, 0, None)?;
let mut tokens = Vec::new();
while let Some(token) = t.next()? {
tokens.push(token.1);
Expand Down