Ensure whitespace is skipped

next
Sayan Nandan 2 years ago
parent 2434170ede
commit 08a286d543
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -253,7 +253,7 @@ impl LexItem for LitStringEscaped {
// UNSAFE(@ohsayan): First operand guarantees correctness // UNSAFE(@ohsayan): First operand guarantees correctness
scanner.deref_cursor() == b'"' scanner.deref_cursor() == b'"'
}; };
scanner.skip_separator();
match String::from_utf8(stringbuf) { match String::from_utf8(stringbuf) {
Ok(s) if is_okay => Ok(Self(s)), Ok(s) if is_okay => Ok(Self(s)),
_ => Err(LangError::TypeParseFailure), _ => Err(LangError::TypeParseFailure),
@ -279,6 +279,7 @@ macro_rules! impl_punctuation {
// UNSAFE(@ohsayan): The above condition guarantees safety // UNSAFE(@ohsayan): The above condition guarantees safety
scanner.incr_cursor() scanner.incr_cursor()
}; };
scanner.skip_separator();
Ok(Self) Ok(Self)
} else { } else {
Err(LangError::InvalidSyntax) Err(LangError::InvalidSyntax)
@ -311,15 +312,19 @@ pub enum Type {
impl LexItem for Type { impl LexItem for Type {
#[inline(always)] #[inline(always)]
fn lex(scanner: &mut Scanner) -> LangResult<Self> { fn lex(scanner: &mut Scanner) -> LangResult<Self> {
let try_ident = Ident::lex(scanner)?; let ret = match Ident::lex(scanner) {
let ret = match unsafe { Ok(ret) => {
// UNSAFE(@ohsayan): The lifetime of the `scanner` ensures validity match unsafe {
try_ident.as_slice() // UNSAFE(@ohsayan): The lifetime of the `scanner` ensures validity
} { ret.as_slice()
b"string" => Self::String, } {
b"binary" => Self::Binary, b"string" => Self::String,
b"list" => Self::List, b"binary" => Self::Binary,
_ => return Err(LangError::UnknownType), b"list" => Self::List,
_ => return Err(LangError::UnknownType),
}
}
Err(_) => return Err(LangError::InvalidSyntax),
}; };
Ok(ret) Ok(ret)
} }
@ -382,6 +387,7 @@ impl LexItem for TypeExpression {
} }
valid_expr &= open_c == close_c; valid_expr &= open_c == close_c;
if valid_expr { if valid_expr {
scanner.skip_separator();
Ok(Self(type_expr)) Ok(Self(type_expr))
} else { } else {
Err(LangError::BadExpression) Err(LangError::BadExpression)

Loading…
Cancel
Save