pr 08
This commit is contained in:
parent
407111cfef
commit
c01c6ee17c
@ -9,6 +9,7 @@ pub enum DiagnosticLevel {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Diagnostic {
|
pub struct Diagnostic {
|
||||||
pub level: DiagnosticLevel,
|
pub level: DiagnosticLevel,
|
||||||
|
pub code: Option<String>,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub span: Option<Span>,
|
pub span: Option<Span>,
|
||||||
}
|
}
|
||||||
@ -33,6 +34,7 @@ impl DiagnosticBundle {
|
|||||||
let mut bundle = Self::new();
|
let mut bundle = Self::new();
|
||||||
bundle.push(Diagnostic {
|
bundle.push(Diagnostic {
|
||||||
level: DiagnosticLevel::Error,
|
level: DiagnosticLevel::Error,
|
||||||
|
code: None,
|
||||||
message,
|
message,
|
||||||
span,
|
span,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,9 +2,15 @@ pub mod token;
|
|||||||
pub mod lexer;
|
pub mod lexer;
|
||||||
pub mod ast;
|
pub mod ast;
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
|
pub mod symbols;
|
||||||
|
pub mod collector;
|
||||||
|
pub mod resolver;
|
||||||
|
|
||||||
pub use lexer::Lexer;
|
pub use lexer::Lexer;
|
||||||
pub use token::{Token, TokenKind};
|
pub use token::{Token, TokenKind};
|
||||||
|
pub use symbols::{Symbol, SymbolTable, ModuleSymbols, Visibility, SymbolKind, Namespace};
|
||||||
|
pub use collector::SymbolCollector;
|
||||||
|
pub use resolver::{Resolver, ModuleProvider};
|
||||||
|
|
||||||
use crate::common::diagnostics::DiagnosticBundle;
|
use crate::common::diagnostics::DiagnosticBundle;
|
||||||
use crate::common::files::FileManager;
|
use crate::common::files::FileManager;
|
||||||
@ -30,9 +36,21 @@ impl Frontend for PbsFrontend {
|
|||||||
let file_id = file_manager.add(entry.to_path_buf(), source.clone());
|
let file_id = file_manager.add(entry.to_path_buf(), source.clone());
|
||||||
|
|
||||||
let mut parser = parser::Parser::new(&source, file_id);
|
let mut parser = parser::Parser::new(&source, file_id);
|
||||||
let _ast = parser.parse_file()?;
|
let ast = parser.parse_file()?;
|
||||||
|
|
||||||
// Parsing and full compilation will be implemented in future PRs.
|
let mut collector = SymbolCollector::new();
|
||||||
Err(DiagnosticBundle::error("Frontend 'pbs' not yet fully implemented (Parser OK)".to_string(), None))
|
let (type_symbols, value_symbols) = collector.collect(&ast)?;
|
||||||
|
let module_symbols = ModuleSymbols { type_symbols, value_symbols };
|
||||||
|
|
||||||
|
struct EmptyProvider;
|
||||||
|
impl ModuleProvider for EmptyProvider {
|
||||||
|
fn get_module_symbols(&self, _path: &str) -> Option<&ModuleSymbols> { None }
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut resolver = Resolver::new(&module_symbols, &EmptyProvider);
|
||||||
|
resolver.resolve(&ast)?;
|
||||||
|
|
||||||
|
// Compilation to IR will be implemented in future PRs.
|
||||||
|
Err(DiagnosticBundle::error("Frontend 'pbs' not yet fully implemented (Resolver OK)".to_string(), None))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -630,6 +630,7 @@ impl Parser {
|
|||||||
fn error(&mut self, message: &str) -> DiagnosticBundle {
|
fn error(&mut self, message: &str) -> DiagnosticBundle {
|
||||||
let diag = Diagnostic {
|
let diag = Diagnostic {
|
||||||
level: DiagnosticLevel::Error,
|
level: DiagnosticLevel::Error,
|
||||||
|
code: None,
|
||||||
message: message.to_string(),
|
message: message.to_string(),
|
||||||
span: Some(self.peek().span),
|
span: Some(self.peek().span),
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user