Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
Implement parsing for hexadecimal integers
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Christian Schmitz committed Aug 20, 2021
1 parent 6f77e4d commit e6efcfa
Show file tree
Hide file tree
Showing 2 changed files with 288 additions and 77 deletions.
30 changes: 1 addition & 29 deletions src/front/wgsl/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn consume_any(input: &str, what: impl Fn(char) -> bool) -> (&str, &str) {
/// Tries to skip a given prefix in the input string.
/// Returns whether the prefix was present and could therefore be skipped,
/// the remaining str and the number of *bytes* skipped.
fn try_skip_prefix<'a, 'b>(input: &'a str, prefix: &'b str) -> (bool, &'a str, usize) {
pub fn try_skip_prefix<'a, 'b>(input: &'a str, prefix: &'b str) -> (bool, &'a str, usize) {
if input.starts_with(prefix) {
(true, &input[prefix.len()..], prefix.len())
} else {
Expand Down Expand Up @@ -549,34 +549,6 @@ impl<'a> Lexer<'a> {
}
}

fn _next_float_literal(&mut self) -> Result<f32, Error<'a>> {
match self.next() {
(Token::Number { value, .. }, span) => {
value.parse().map_err(|e| Error::BadFloat(span, e))
}
other => Err(Error::Unexpected(other, ExpectedToken::Float)),
}
}

pub(super) fn next_uint_literal(&mut self) -> Result<u32, Error<'a>> {
match self.next() {
(Token::Number { value, .. }, span) => {
let v = value.parse();
v.map_err(|e| Error::BadU32(span, e))
}
other => Err(Error::Unexpected(other, ExpectedToken::Uint)),
}
}

pub(super) fn next_sint_literal(&mut self) -> Result<i32, Error<'a>> {
match self.next() {
(Token::Number { value, .. }, span) => {
value.parse().map_err(|e| Error::BadI32(span, e))
}
other => Err(Error::Unexpected(other, ExpectedToken::Sint)),
}
}

/// Parses a generic scalar type, for example `<f32>`.
pub(super) fn next_scalar_generic(
&mut self,
Expand Down
Loading

0 comments on commit e6efcfa

Please sign in to comment.