diff --git a/naga/src/front/wgsl/parse/lexer.rs b/naga/src/front/wgsl/parse/lexer.rs index 6f8dfa519..b1b340f0d 100644 --- a/naga/src/front/wgsl/parse/lexer.rs +++ b/naga/src/front/wgsl/parse/lexer.rs @@ -243,7 +243,6 @@ fn is_word_part(c: char) -> bool { unicode_ident::is_xid_continue(c) } -#[derive(Clone)] pub(in crate::front::wgsl) struct Lexer<'a> { /// The remaining unconsumed input. input: &'a str, @@ -330,13 +329,6 @@ impl<'a> Lexer<'a> { } } - fn peek_token_and_rest(&mut self) -> (TokenSpan<'a>, &'a str) { - let mut cloned = self.clone(); - let token = cloned.next(); - let rest = cloned.input; - (token, rest) - } - /// Collect all module doc comments until a non doc token is found. pub(in crate::front::wgsl) fn accumulate_module_doc_comments(&mut self) -> Vec<&'a str> { let mut doc_comments = Vec::new(); @@ -426,10 +418,28 @@ impl<'a> Lexer<'a> { #[must_use] pub(in crate::front::wgsl) fn peek(&mut self) -> TokenSpan<'a> { - let (token, _) = self.peek_token_and_rest(); + let input = self.input; + let last_end_offset = self.last_end_offset; + let token = self.next(); + self.input = input; + self.last_end_offset = last_end_offset; token } + /// If the next token matches it's consumed and true is returned + pub(in crate::front::wgsl) fn next_if(&mut self, what: Token<'_>) -> bool { + let input = self.input; + let last_end_offset = self.last_end_offset; + let token = self.next(); + if token.0 == what { + true + } else { + self.input = input; + self.last_end_offset = last_end_offset; + false + } + } + pub(in crate::front::wgsl) fn expect_span(&mut self, expected: Token<'a>) -> Result<'a, Span> { let next = self.next(); if next.0 == expected { @@ -466,17 +476,6 @@ impl<'a> Lexer<'a> { self.next_if(Token::Separator(',')) && self.peek().0 != Token::Paren('>') } - /// If the next token matches it's consumed and true is returned - pub(in crate::front::wgsl) fn next_if(&mut self, what: Token<'_>) -> bool { - let (peeked_token, rest) = self.peek_token_and_rest(); - if peeked_token.0 == what { - self.input = rest; - true - } else { - false - } - } - pub(in crate::front::wgsl) fn next_ident_with_span(&mut self) -> Result<'a, (&'a str, Span)> { match self.next() { (Token::Word("_"), span) => Err(Box::new(Error::InvalidIdentifierUnderscore(span))), diff --git a/naga/tests/naga/validation.rs b/naga/tests/naga/validation.rs index 86bb75a8f..230870f9d 100644 --- a/naga/tests/naga/validation.rs +++ b/naga/tests/naga/validation.rs @@ -670,11 +670,14 @@ fn validation_error_messages() { "\ error: Function [1] 'main' is invalid ┌─ wgsl:7:17 - │ \n7 │ ╭ fn main() { + │\x20\x20 +7 │ ╭ fn main() { 8 │ │ foo(); - │ │ ^^^^ invalid function call - │ ╰──────────────────────────^ naga::ir::Function [1] - │ \n = Call to [0] is invalid + │ │ ^^^^^ invalid function call +9 │ │ } + │ ╰─────────────────^ naga::ir::Function [1] + │\x20\x20 + = Call to [0] is invalid = Requires 1 arguments, but 0 are provided ", diff --git a/naga/tests/naga/wgsl_errors.rs b/naga/tests/naga/wgsl_errors.rs index 62dc901a9..dfc724056 100644 --- a/naga/tests/naga/wgsl_errors.rs +++ b/naga/tests/naga/wgsl_errors.rs @@ -2933,7 +2933,7 @@ fn use_me(a: i32) { 2 │ @must_use │ ^^^^^^^^ 3 │ fn use_me(a: i32) { - │ ^^^^^^^^^^^^^ + │ ^^^^^^^^^^^^^^ │ = note: declare a return type or remove the attribute @@ -3753,7 +3753,7 @@ fn inconsistent_type() { ┌─ wgsl:2:20 │ 2 │ return dot(vec4(), vec3()); - │ ^^^ ^^^^^^^^^^ ^^^^^^^^^^ argument #2 has type vec3 + │ ^^^ ^^^^^^^^^^^ ^^^^^^^^^^^ argument #2 has type vec3 │ │\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20 │ this argument has type vec4, which constrains subsequent arguments │ @@ -4301,7 +4301,8 @@ fn max_type_size_two_arrays_in_struct() { 2 │ ╭ struct TwoArrays { 3 │ │ arr1: array, 4 │ │ arr2: array, - │ ╰───────────────────────────────────────────────^ this type exceeds the maximum size +5 │ │ } + │ ╰─────────────^ this type exceeds the maximum size │\x20\x20 = note: the maximum size is 1073741824 bytes