mirror of
https://github.com/uutils/awk.git
synced 2026-06-10 16:15:04 -07:00
lexer: move arena to be behind NonNull<T>
This commit is contained in:
+5
-4
@@ -10,6 +10,7 @@ use core::str;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
fmt::{Debug, Display},
|
||||
ptr::NonNull,
|
||||
slice::SliceIndex,
|
||||
};
|
||||
|
||||
@@ -228,10 +229,10 @@ pub enum Token<'a> {
|
||||
Semicolon,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct Extra {
|
||||
ctx: Context,
|
||||
arena: *const Bump,
|
||||
arena: NonNull<Bump>,
|
||||
posix_strict: bool,
|
||||
gnu_strict: bool,
|
||||
}
|
||||
@@ -279,7 +280,7 @@ impl<'a> Token<'a> {
|
||||
source,
|
||||
Extra {
|
||||
ctx: Context::AcceptExpression,
|
||||
arena,
|
||||
arena: NonNull::from_ref(arena),
|
||||
posix_strict,
|
||||
gnu_strict,
|
||||
},
|
||||
@@ -582,6 +583,6 @@ impl Extra {
|
||||
fn arena<'a>(&self) -> &'a Bump {
|
||||
// SAFETY: lives for as long as self because it's the same lifetime as
|
||||
// the source being lexed; Logos just can't take lifetimes on extras.
|
||||
unsafe { &*self.arena }
|
||||
unsafe { self.arena.as_ref() }
|
||||
}
|
||||
}
|
||||
|
||||
+4
-12
@@ -5,7 +5,7 @@
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
use crate::{Context, Extra, Identifier, Lexer, Token};
|
||||
use crate::{Identifier, Token};
|
||||
use bumpalo::{
|
||||
Bump,
|
||||
collections::{CollectIn, Vec},
|
||||
@@ -17,17 +17,9 @@ fn lex<'a>(
|
||||
posix_strict: bool,
|
||||
gnu_strict: bool,
|
||||
) -> Vec<'a, Token<'a>> {
|
||||
Lexer::with_extras(
|
||||
src,
|
||||
Extra {
|
||||
ctx: Context::AcceptExpression,
|
||||
arena,
|
||||
posix_strict,
|
||||
gnu_strict,
|
||||
},
|
||||
)
|
||||
.collect_in::<Result<Vec<_>, _>>(arena)
|
||||
.unwrap()
|
||||
Token::lex(src, arena, posix_strict, gnu_strict)
|
||||
.collect_in::<Result<Vec<_>, _>>(arena)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user