barbar
This commit is contained in:
parent
cac99cd34d
commit
33a4bf7d01
|
@ -3227,14 +3227,13 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let input = find_block(input, ident).trim();
|
let input = find_block(input, ident);
|
||||||
|
|
||||||
parser::test::format(ident, input);
|
|
||||||
|
|
||||||
let mut module_map = Vec::new();
|
let mut module_map = Vec::new();
|
||||||
let mut last_start = 0;
|
let mut last_start = 0;
|
||||||
let mut last_module_name = "test";
|
let mut last_module_name = "test";
|
||||||
for (i, m) in input.match_indices("// in module: ") {
|
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]));
|
module_map.push((last_module_name, &input[last_start..i]));
|
||||||
let (module_name, _) = input[i + m.len()..].split_once('\n').unwrap();
|
let (module_name, _) = input[i + m.len()..].split_once('\n').unwrap();
|
||||||
last_module_name = module_name;
|
last_module_name = module_name;
|
||||||
|
@ -3253,7 +3252,7 @@ mod tests {
|
||||||
let mut codegen = super::Codegen {
|
let mut codegen = super::Codegen {
|
||||||
files: module_map
|
files: module_map
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(path, content)| parser::Ast::new(path, content, &loader, false))
|
.map(|&(path, content)| parser::Ast::new(path, content, &loader))
|
||||||
.collect(),
|
.collect(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
|
@ -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)?;
|
let mut file = std::fs::File::open(path)?;
|
||||||
file.read_to_end(buffer)?;
|
file.read_to_end(buffer)?;
|
||||||
let src = std::str::from_utf8(buffer).map_err(InvalidFileData)?;
|
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 = || {
|
let thread = || {
|
||||||
|
|
|
@ -70,16 +70,10 @@ pub struct Parser<'a, 'b> {
|
||||||
trailing_sep: bool,
|
trailing_sep: bool,
|
||||||
idents: Vec<ScopeIdent>,
|
idents: Vec<ScopeIdent>,
|
||||||
captured: Vec<Ident>,
|
captured: Vec<Ident>,
|
||||||
loose: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> Parser<'a, 'b> {
|
impl<'a, 'b> Parser<'a, 'b> {
|
||||||
pub fn new(
|
pub fn new(arena: &'b Arena<'a>, symbols: &'b mut Symbols, loader: Loader<'b>) -> Self {
|
||||||
arena: &'b Arena<'a>,
|
|
||||||
symbols: &'b mut Symbols,
|
|
||||||
loader: Loader<'b>,
|
|
||||||
loose: bool,
|
|
||||||
) -> Self {
|
|
||||||
let mut lexer = Lexer::new("");
|
let mut lexer = Lexer::new("");
|
||||||
Self {
|
Self {
|
||||||
loader,
|
loader,
|
||||||
|
@ -92,7 +86,6 @@ impl<'a, 'b> Parser<'a, 'b> {
|
||||||
trailing_sep: false,
|
trailing_sep: false,
|
||||||
idents: Vec::new(),
|
idents: Vec::new(),
|
||||||
captured: 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");
|
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(
|
self.report_pos(
|
||||||
pos,
|
pos,
|
||||||
format_args!("redeclaration of identifier: {}", self.lexer.slice(ident::range(id))),
|
format_args!("redeclaration of identifier: {}", self.lexer.slice(ident::range(id))),
|
||||||
|
@ -1084,10 +1077,10 @@ impl AstInner<[Symbol]> {
|
||||||
.0
|
.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 arena = Arena::default();
|
||||||
let mut syms = Vec::new();
|
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>];
|
let exprs = parser.file(content, path) as *const [Expr<'static>];
|
||||||
|
|
||||||
syms.sort_unstable_by_key(|s| s.name);
|
syms.sort_unstable_by_key(|s| s.name);
|
||||||
|
@ -1119,8 +1112,8 @@ impl AstInner<[Symbol]> {
|
||||||
pub struct Ast(NonNull<AstInner<[Symbol]>>);
|
pub struct Ast(NonNull<AstInner<[Symbol]>>);
|
||||||
|
|
||||||
impl Ast {
|
impl Ast {
|
||||||
pub fn new(path: &str, content: &str, loader: Loader, loose: bool) -> Self {
|
pub fn new(path: &str, content: &str, loader: Loader) -> Self {
|
||||||
Self(AstInner::new(content, path, loader, loose))
|
Self(AstInner::new(content, path, loader))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exprs(&self) -> &[Expr] {
|
pub fn exprs(&self) -> &[Expr] {
|
||||||
|
@ -1150,7 +1143,7 @@ impl std::fmt::Display for Ast {
|
||||||
|
|
||||||
impl Default for Ast {
|
impl Default for Ast {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self(AstInner::new("", "", &no_loader, false))
|
Self(AstInner::new("", "", &no_loader))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1326,7 +1319,7 @@ impl Drop for ArenaChunk {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod test {
|
pub mod test {
|
||||||
pub fn format(ident: &str, input: &str) {
|
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();
|
let mut output = Vec::new();
|
||||||
crate::format_to(&ast, input, &mut output).unwrap();
|
crate::format_to(&ast, input, &mut output).unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue