Rename: Module → Ast (#915)
This commit is contained in:
parent
2a4c5ae0f0
commit
98457c05d7
@ -11,15 +11,12 @@ pub(crate) struct Analyzer<'src> {
|
||||
}
|
||||
|
||||
impl<'src> Analyzer<'src> {
|
||||
pub(crate) fn analyze(module: Module<'src>) -> CompilationResult<'src, Justfile> {
|
||||
Analyzer::default().justfile(module)
|
||||
pub(crate) fn analyze(ast: Ast<'src>) -> CompilationResult<'src, Justfile> {
|
||||
Analyzer::default().justfile(ast)
|
||||
}
|
||||
|
||||
pub(crate) fn justfile(
|
||||
mut self,
|
||||
module: Module<'src>,
|
||||
) -> CompilationResult<'src, Justfile<'src>> {
|
||||
for item in module.items {
|
||||
pub(crate) fn justfile(mut self, ast: Ast<'src>) -> CompilationResult<'src, Justfile<'src>> {
|
||||
for item in ast.items {
|
||||
match item {
|
||||
Item::Alias(alias) => {
|
||||
self.analyze_alias(&alias)?;
|
||||
@ -83,7 +80,7 @@ impl<'src> Analyzer<'src> {
|
||||
}
|
||||
|
||||
Ok(Justfile {
|
||||
warnings: module.warnings,
|
||||
warnings: ast.warnings,
|
||||
aliases,
|
||||
assignments,
|
||||
recipes,
|
||||
|
@ -1,21 +1,18 @@
|
||||
use crate::common::*;
|
||||
|
||||
/// A module, the top-level type produced by the parser. So-named because
|
||||
/// although at present, all justfiles consist of a single module, in the future
|
||||
/// we will likely have multi-module and multi-file justfiles.
|
||||
///
|
||||
/// Not all successful parses result in valid justfiles, so additional
|
||||
/// consistency checks and name resolution are performed by the `Analyzer`,
|
||||
/// which produces a `Justfile` from a `Module`.
|
||||
/// The top-level type produced by the parser.Not all successful parses result
|
||||
/// in valid justfiles, so additional consistency checks and name resolution
|
||||
/// are performed by the `Analyzer`, which produces a `Justfile` from an
|
||||
/// `Ast`.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct Module<'src> {
|
||||
pub(crate) struct Ast<'src> {
|
||||
/// Items in the justfile
|
||||
pub(crate) items: Vec<Item<'src>>,
|
||||
/// Non-fatal warnings encountered during parsing
|
||||
pub(crate) warnings: Vec<Warning>,
|
||||
}
|
||||
|
||||
impl<'src> Display for Module<'src> {
|
||||
impl<'src> Display for Ast<'src> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
let mut iter = self.items.iter().peekable();
|
||||
|
@ -44,16 +44,16 @@ pub(crate) use crate::{
|
||||
// structs and enums
|
||||
pub(crate) use crate::{
|
||||
alias::Alias, analyzer::Analyzer, assignment::Assignment,
|
||||
assignment_resolver::AssignmentResolver, binding::Binding, color::Color,
|
||||
assignment_resolver::AssignmentResolver, ast::Ast, binding::Binding, color::Color,
|
||||
compilation_error::CompilationError, compilation_error_kind::CompilationErrorKind,
|
||||
config::Config, config_error::ConfigError, count::Count, delimiter::Delimiter,
|
||||
dependency::Dependency, enclosure::Enclosure, evaluator::Evaluator, expression::Expression,
|
||||
fragment::Fragment, function::Function, function_context::FunctionContext,
|
||||
interrupt_guard::InterruptGuard, interrupt_handler::InterruptHandler, item::Item,
|
||||
justfile::Justfile, keyword::Keyword, lexer::Lexer, line::Line, list::List,
|
||||
load_error::LoadError, module::Module, name::Name, output_error::OutputError,
|
||||
parameter::Parameter, parameter_kind::ParameterKind, parser::Parser, platform::Platform,
|
||||
position::Position, positional::Positional, recipe::Recipe, recipe_context::RecipeContext,
|
||||
load_error::LoadError, name::Name, output_error::OutputError, parameter::Parameter,
|
||||
parameter_kind::ParameterKind, parser::Parser, platform::Platform, position::Position,
|
||||
positional::Positional, recipe::Recipe, recipe_context::RecipeContext,
|
||||
recipe_resolver::RecipeResolver, runtime_error::RuntimeError, scope::Scope, search::Search,
|
||||
search_config::SearchConfig, search_error::SearchError, set::Set, setting::Setting,
|
||||
settings::Settings, shebang::Shebang, show_whitespace::ShowWhitespace, string_kind::StringKind,
|
||||
|
@ -697,7 +697,7 @@ impl Config {
|
||||
self.run(justfile, search, overrides, &recipes)
|
||||
}
|
||||
|
||||
fn dump(ast: Module) -> Result<(), i32> {
|
||||
fn dump(ast: Ast) -> Result<(), i32> {
|
||||
print!("{}", ast);
|
||||
Ok(())
|
||||
}
|
||||
@ -735,7 +735,7 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
fn format(&self, ast: Module, search: &Search) -> Result<(), i32> {
|
||||
fn format(&self, ast: Ast, search: &Search) -> Result<(), i32> {
|
||||
if !self.unstable {
|
||||
eprintln!(
|
||||
"The `--fmt` command is currently unstable. Pass the `--unstable` flag to enable it."
|
||||
|
@ -61,6 +61,7 @@ mod alias;
|
||||
mod analyzer;
|
||||
mod assignment;
|
||||
mod assignment_resolver;
|
||||
mod ast;
|
||||
mod binding;
|
||||
mod color;
|
||||
mod command_ext;
|
||||
@ -92,7 +93,6 @@ mod line;
|
||||
mod list;
|
||||
mod load_dotenv;
|
||||
mod load_error;
|
||||
mod module;
|
||||
mod name;
|
||||
mod ordinal;
|
||||
mod output;
|
||||
|
@ -7,7 +7,7 @@ pub(crate) trait Node<'src> {
|
||||
fn tree(&self) -> Tree<'src>;
|
||||
}
|
||||
|
||||
impl<'src> Node<'src> for Module<'src> {
|
||||
impl<'src> Node<'src> for Ast<'src> {
|
||||
fn tree(&self) -> Tree<'src> {
|
||||
Tree::atom("justfile")
|
||||
.extend(self.items.iter().map(|item| item.tree()))
|
||||
|
@ -35,9 +35,9 @@ pub(crate) struct Parser<'tokens, 'src> {
|
||||
}
|
||||
|
||||
impl<'tokens, 'src> Parser<'tokens, 'src> {
|
||||
/// Parse `tokens` into an `Module`
|
||||
pub(crate) fn parse(tokens: &'tokens [Token<'src>]) -> CompilationResult<'src, Module<'src>> {
|
||||
Self::new(tokens).parse_justfile()
|
||||
/// Parse `tokens` into an `Ast`
|
||||
pub(crate) fn parse(tokens: &'tokens [Token<'src>]) -> CompilationResult<'src, Ast<'src>> {
|
||||
Self::new(tokens).parse_ast()
|
||||
}
|
||||
|
||||
/// Construct a new Paser from a token stream
|
||||
@ -295,7 +295,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
|
||||
}
|
||||
|
||||
/// Parse a justfile, consumes self
|
||||
fn parse_justfile(mut self) -> CompilationResult<'src, Module<'src>> {
|
||||
fn parse_ast(mut self) -> CompilationResult<'src, Ast<'src>> {
|
||||
fn pop_doc_comment<'src>(
|
||||
items: &mut Vec<Item<'src>>,
|
||||
eol_since_last_comment: bool,
|
||||
@ -381,7 +381,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
|
||||
self.tokens.len() - self.next,
|
||||
))?)
|
||||
} else {
|
||||
Ok(Module {
|
||||
Ok(Ast {
|
||||
warnings: Vec::new(),
|
||||
items,
|
||||
})
|
||||
|
@ -65,9 +65,9 @@ pub(crate) fn analysis_error(
|
||||
) {
|
||||
let tokens = Lexer::lex(src).expect("Lexing failed in parse test...");
|
||||
|
||||
let module = Parser::parse(&tokens).expect("Parsing failed in analysis test...");
|
||||
let ast = Parser::parse(&tokens).expect("Parsing failed in analysis test...");
|
||||
|
||||
match Analyzer::analyze(module) {
|
||||
match Analyzer::analyze(ast) {
|
||||
Ok(_) => panic!("Analysis unexpectedly succeeded"),
|
||||
Err(have) => {
|
||||
let want = CompilationError {
|
||||
|
Loading…
Reference in New Issue
Block a user