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