diff --git a/src/analyzer.rs b/src/analyzer.rs index fbf32d9..001412b 100644 --- a/src/analyzer.rs +++ b/src/analyzer.rs @@ -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, diff --git a/src/module.rs b/src/ast.rs similarity index 56% rename from src/module.rs rename to src/ast.rs index d83a2b5..632110a 100644 --- a/src/module.rs +++ b/src/ast.rs @@ -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>, /// Non-fatal warnings encountered during parsing pub(crate) warnings: Vec, } -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(); diff --git a/src/common.rs b/src/common.rs index 441024a..6609eb8 100644 --- a/src/common.rs +++ b/src/common.rs @@ -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, diff --git a/src/config.rs b/src/config.rs index 2bd7315..e68d981 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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." diff --git a/src/lib.rs b/src/lib.rs index e9a1503..b6bed73 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/node.rs b/src/node.rs index 897da9a..2c4114c 100644 --- a/src/node.rs +++ b/src/node.rs @@ -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())) diff --git a/src/parser.rs b/src/parser.rs index 66d62cc..ac3264b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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>, 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, }) diff --git a/src/testing.rs b/src/testing.rs index 0bb9253..14d8c30 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -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 {