This commit is contained in:
mlokr 2024-07-19 21:19:03 +02:00
parent cac99cd34d
commit 33a4bf7d01
No known key found for this signature in database
GPG key ID: DEA147DDEE644993
3 changed files with 12 additions and 20 deletions

View file

@ -3227,14 +3227,13 @@ mod tests {
}
}
let input = find_block(input, ident).trim();
parser::test::format(ident, input);
let input = find_block(input, ident);
let mut module_map = Vec::new();
let mut last_start = 0;
let mut last_module_name = "test";
for (i, m) in input.match_indices("// in module: ") {
parser::test::format(ident, input[last_start..i].trim());
module_map.push((last_module_name, &input[last_start..i]));
let (module_name, _) = input[i + m.len()..].split_once('\n').unwrap();
last_module_name = module_name;
@ -3253,7 +3252,7 @@ mod tests {
let mut codegen = super::Codegen {
files: module_map
.iter()
.map(|&(path, content)| parser::Ast::new(path, content, &loader, false))
.map(|&(path, content)| parser::Ast::new(path, content, &loader))
.collect(),
..Default::default()
};

View file

@ -424,7 +424,7 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> {
let mut file = std::fs::File::open(path)?;
file.read_to_end(buffer)?;
let src = std::str::from_utf8(buffer).map_err(InvalidFileData)?;
Ok(Ast::new(path, src, &loader, false))
Ok(Ast::new(path, src, &loader))
};
let thread = || {

View file

@ -70,16 +70,10 @@ pub struct Parser<'a, 'b> {
trailing_sep: bool,
idents: Vec<ScopeIdent>,
captured: Vec<Ident>,
loose: bool,
}
impl<'a, 'b> Parser<'a, 'b> {
pub fn new(
arena: &'b Arena<'a>,
symbols: &'b mut Symbols,
loader: Loader<'b>,
loose: bool,
) -> Self {
pub fn new(arena: &'b Arena<'a>, symbols: &'b mut Symbols, loader: Loader<'b>) -> Self {
let mut lexer = Lexer::new("");
Self {
loader,
@ -92,7 +86,6 @@ impl<'a, 'b> Parser<'a, 'b> {
trailing_sep: false,
idents: Vec::new(),
captured: Vec::new(),
loose,
}
}
@ -220,7 +213,7 @@ impl<'a, 'b> Parser<'a, 'b> {
}
let index = self.idents.binary_search_by_key(&id, |s| s.ident).expect("fck up");
if std::mem::replace(&mut self.idents[index].declared, true) && !self.loose {
if std::mem::replace(&mut self.idents[index].declared, true) {
self.report_pos(
pos,
format_args!("redeclaration of identifier: {}", self.lexer.slice(ident::range(id))),
@ -1084,10 +1077,10 @@ impl AstInner<[Symbol]> {
.0
}
fn new(content: &str, path: &str, loader: Loader, loose: bool) -> NonNull<Self> {
fn new(content: &str, path: &str, loader: Loader) -> NonNull<Self> {
let arena = Arena::default();
let mut syms = Vec::new();
let mut parser = Parser::new(&arena, &mut syms, loader, loose);
let mut parser = Parser::new(&arena, &mut syms, loader);
let exprs = parser.file(content, path) as *const [Expr<'static>];
syms.sort_unstable_by_key(|s| s.name);
@ -1119,8 +1112,8 @@ impl AstInner<[Symbol]> {
pub struct Ast(NonNull<AstInner<[Symbol]>>);
impl Ast {
pub fn new(path: &str, content: &str, loader: Loader, loose: bool) -> Self {
Self(AstInner::new(content, path, loader, loose))
pub fn new(path: &str, content: &str, loader: Loader) -> Self {
Self(AstInner::new(content, path, loader))
}
pub fn exprs(&self) -> &[Expr] {
@ -1150,7 +1143,7 @@ impl std::fmt::Display for Ast {
impl Default for Ast {
fn default() -> Self {
Self(AstInner::new("", "", &no_loader, false))
Self(AstInner::new("", "", &no_loader))
}
}
@ -1326,7 +1319,7 @@ impl Drop for ArenaChunk {
#[cfg(test)]
pub mod test {
pub fn format(ident: &str, input: &str) {
let ast = super::Ast::new(ident, input, &|_, _| Ok(0), true);
let ast = super::Ast::new(ident, input, &|_, _| Ok(0));
let mut output = Vec::new();
crate::format_to(&ast, input, &mut output).unwrap();