Use pub(crate)
instead of pub
(#471)
Eventually, there will probably be a `crate` visibility specifier that does the same thing as `pub(crate)`. This commit replaces `pub` with `pub(crate)`, so when `crate` is available we can easily switch to it.
This commit is contained in:
parent
1521982891
commit
1cb90f4e65
10
src/alias.rs
10
src/alias.rs
@ -1,11 +1,11 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Alias<'a> {
|
pub(crate) struct Alias<'a> {
|
||||||
pub name: &'a str,
|
pub(crate) name: &'a str,
|
||||||
pub target: &'a str,
|
pub(crate) target: &'a str,
|
||||||
pub line_number: usize,
|
pub(crate) line_number: usize,
|
||||||
pub private: bool,
|
pub(crate) private: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Display for Alias<'a> {
|
impl<'a> Display for Alias<'a> {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
use CompilationErrorKind::*;
|
use CompilationErrorKind::*;
|
||||||
|
|
||||||
pub struct AliasResolver<'a, 'b>
|
pub(crate) struct AliasResolver<'a, 'b>
|
||||||
where
|
where
|
||||||
'a: 'b,
|
'a: 'b,
|
||||||
{
|
{
|
||||||
@ -11,7 +11,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a: 'b, 'b> AliasResolver<'a, 'b> {
|
impl<'a: 'b, 'b> AliasResolver<'a, 'b> {
|
||||||
pub fn resolve_aliases(
|
pub(crate) fn resolve_aliases(
|
||||||
aliases: &BTreeMap<&'a str, Alias<'a>>,
|
aliases: &BTreeMap<&'a str, Alias<'a>>,
|
||||||
recipes: &BTreeMap<&'a str, Recipe<'a>>,
|
recipes: &BTreeMap<&'a str, Recipe<'a>>,
|
||||||
alias_tokens: &BTreeMap<&'a str, Token<'a>>,
|
alias_tokens: &BTreeMap<&'a str, Token<'a>>,
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub struct AssignmentEvaluator<'a: 'b, 'b> {
|
pub(crate) struct AssignmentEvaluator<'a: 'b, 'b> {
|
||||||
pub assignments: &'b BTreeMap<&'a str, Expression<'a>>,
|
pub(crate) assignments: &'b BTreeMap<&'a str, Expression<'a>>,
|
||||||
pub invocation_directory: &'b Result<PathBuf, String>,
|
pub(crate) invocation_directory: &'b Result<PathBuf, String>,
|
||||||
pub dotenv: &'b BTreeMap<String, String>,
|
pub(crate) dotenv: &'b BTreeMap<String, String>,
|
||||||
pub dry_run: bool,
|
pub(crate) dry_run: bool,
|
||||||
pub evaluated: BTreeMap<&'a str, String>,
|
pub(crate) evaluated: BTreeMap<&'a str, String>,
|
||||||
pub exports: &'b BTreeSet<&'a str>,
|
pub(crate) exports: &'b BTreeSet<&'a str>,
|
||||||
pub overrides: &'b BTreeMap<&'b str, &'b str>,
|
pub(crate) overrides: &'b BTreeMap<&'b str, &'b str>,
|
||||||
pub quiet: bool,
|
pub(crate) quiet: bool,
|
||||||
pub scope: &'b BTreeMap<&'a str, String>,
|
pub(crate) scope: &'b BTreeMap<&'a str, String>,
|
||||||
pub shell: &'b str,
|
pub(crate) shell: &'b str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
|
impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
|
||||||
pub fn evaluate_assignments(
|
pub(crate) fn evaluate_assignments(
|
||||||
assignments: &BTreeMap<&'a str, Expression<'a>>,
|
assignments: &BTreeMap<&'a str, Expression<'a>>,
|
||||||
invocation_directory: &Result<PathBuf, String>,
|
invocation_directory: &Result<PathBuf, String>,
|
||||||
dotenv: &'b BTreeMap<String, String>,
|
dotenv: &'b BTreeMap<String, String>,
|
||||||
@ -43,7 +43,7 @@ impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
|
|||||||
Ok(evaluator.evaluated)
|
Ok(evaluator.evaluated)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn evaluate_line(
|
pub(crate) fn evaluate_line(
|
||||||
&mut self,
|
&mut self,
|
||||||
line: &[Fragment<'a>],
|
line: &[Fragment<'a>],
|
||||||
arguments: &BTreeMap<&str, Cow<str>>,
|
arguments: &BTreeMap<&str, Cow<str>>,
|
||||||
@ -81,7 +81,7 @@ impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn evaluate_expression(
|
pub(crate) fn evaluate_expression(
|
||||||
&mut self,
|
&mut self,
|
||||||
expression: &Expression<'a>,
|
expression: &Expression<'a>,
|
||||||
arguments: &BTreeMap<&str, Cow<str>>,
|
arguments: &BTreeMap<&str, Cow<str>>,
|
||||||
|
@ -2,7 +2,7 @@ use crate::common::*;
|
|||||||
|
|
||||||
use CompilationErrorKind::*;
|
use CompilationErrorKind::*;
|
||||||
|
|
||||||
pub struct AssignmentResolver<'a: 'b, 'b> {
|
pub(crate) struct AssignmentResolver<'a: 'b, 'b> {
|
||||||
assignments: &'b BTreeMap<&'a str, Expression<'a>>,
|
assignments: &'b BTreeMap<&'a str, Expression<'a>>,
|
||||||
assignment_tokens: &'b BTreeMap<&'a str, Token<'a>>,
|
assignment_tokens: &'b BTreeMap<&'a str, Token<'a>>,
|
||||||
stack: Vec<&'a str>,
|
stack: Vec<&'a str>,
|
||||||
@ -11,7 +11,7 @@ pub struct AssignmentResolver<'a: 'b, 'b> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a: 'b, 'b> AssignmentResolver<'a, 'b> {
|
impl<'a: 'b, 'b> AssignmentResolver<'a, 'b> {
|
||||||
pub fn resolve_assignments(
|
pub(crate) fn resolve_assignments(
|
||||||
assignments: &BTreeMap<&'a str, Expression<'a>>,
|
assignments: &BTreeMap<&'a str, Expression<'a>>,
|
||||||
assignment_tokens: &BTreeMap<&'a str, Token<'a>>,
|
assignment_tokens: &BTreeMap<&'a str, Token<'a>>,
|
||||||
) -> CompilationResult<'a, ()> {
|
) -> CompilationResult<'a, ()> {
|
||||||
|
40
src/color.rs
40
src/color.rs
@ -5,7 +5,7 @@ use ansi_term::{ANSIGenericString, Prefix, Style, Suffix};
|
|||||||
use atty::Stream;
|
use atty::Stream;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Color {
|
pub(crate) struct Color {
|
||||||
use_color: UseColor,
|
use_color: UseColor,
|
||||||
atty: bool,
|
atty: bool,
|
||||||
style: Style,
|
style: Style,
|
||||||
@ -31,7 +31,7 @@ impl Color {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fmt(fmt: &Formatter) -> Color {
|
pub(crate) fn fmt(fmt: &Formatter) -> Color {
|
||||||
if fmt.alternate() {
|
if fmt.alternate() {
|
||||||
Color::always()
|
Color::always()
|
||||||
} else {
|
} else {
|
||||||
@ -39,72 +39,72 @@ impl Color {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn auto() -> Color {
|
pub(crate) fn auto() -> Color {
|
||||||
Color {
|
Color {
|
||||||
use_color: UseColor::Auto,
|
use_color: UseColor::Auto,
|
||||||
..default()
|
..default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn always() -> Color {
|
pub(crate) fn always() -> Color {
|
||||||
Color {
|
Color {
|
||||||
use_color: UseColor::Always,
|
use_color: UseColor::Always,
|
||||||
..default()
|
..default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn never() -> Color {
|
pub(crate) fn never() -> Color {
|
||||||
Color {
|
Color {
|
||||||
use_color: UseColor::Never,
|
use_color: UseColor::Never,
|
||||||
..default()
|
..default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stderr(self) -> Color {
|
pub(crate) fn stderr(self) -> Color {
|
||||||
self.redirect(Stream::Stderr)
|
self.redirect(Stream::Stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stdout(self) -> Color {
|
pub(crate) fn stdout(self) -> Color {
|
||||||
self.redirect(Stream::Stdout)
|
self.redirect(Stream::Stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn doc(self) -> Color {
|
pub(crate) fn doc(self) -> Color {
|
||||||
self.restyle(Style::new().fg(Blue))
|
self.restyle(Style::new().fg(Blue))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error(self) -> Color {
|
pub(crate) fn error(self) -> Color {
|
||||||
self.restyle(Style::new().fg(Red).bold())
|
self.restyle(Style::new().fg(Red).bold())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn warning(self) -> Color {
|
pub(crate) fn warning(self) -> Color {
|
||||||
self.restyle(Style::new().fg(Yellow).bold())
|
self.restyle(Style::new().fg(Yellow).bold())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn banner(self) -> Color {
|
pub(crate) fn banner(self) -> Color {
|
||||||
self.restyle(Style::new().fg(Cyan).bold())
|
self.restyle(Style::new().fg(Cyan).bold())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn command(self) -> Color {
|
pub(crate) fn command(self) -> Color {
|
||||||
self.restyle(Style::new().bold())
|
self.restyle(Style::new().bold())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parameter(self) -> Color {
|
pub(crate) fn parameter(self) -> Color {
|
||||||
self.restyle(Style::new().fg(Cyan))
|
self.restyle(Style::new().fg(Cyan))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn message(self) -> Color {
|
pub(crate) fn message(self) -> Color {
|
||||||
self.restyle(Style::new().bold())
|
self.restyle(Style::new().bold())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn annotation(self) -> Color {
|
pub(crate) fn annotation(self) -> Color {
|
||||||
self.restyle(Style::new().fg(Purple))
|
self.restyle(Style::new().fg(Purple))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn string(self) -> Color {
|
pub(crate) fn string(self) -> Color {
|
||||||
self.restyle(Style::new().fg(Green))
|
self.restyle(Style::new().fg(Green))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn active(&self) -> bool {
|
pub(crate) fn active(&self) -> bool {
|
||||||
match self.use_color {
|
match self.use_color {
|
||||||
UseColor::Always => true,
|
UseColor::Always => true,
|
||||||
UseColor::Never => false,
|
UseColor::Never => false,
|
||||||
@ -112,15 +112,15 @@ impl Color {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn paint<'a>(&self, text: &'a str) -> ANSIGenericString<'a, str> {
|
pub(crate) fn paint<'a>(&self, text: &'a str) -> ANSIGenericString<'a, str> {
|
||||||
self.effective_style().paint(text)
|
self.effective_style().paint(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(&self) -> Prefix {
|
pub(crate) fn prefix(&self) -> Prefix {
|
||||||
self.effective_style().prefix()
|
self.effective_style().prefix()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(&self) -> Suffix {
|
pub(crate) fn suffix(&self) -> Suffix {
|
||||||
self.effective_style().suffix()
|
self.effective_style().suffix()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub trait CommandExt {
|
pub(crate) trait CommandExt {
|
||||||
fn export_environment_variables<'a>(
|
fn export_environment_variables<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
scope: &BTreeMap<&'a str, String>,
|
scope: &BTreeMap<&'a str, String>,
|
||||||
|
@ -49,9 +49,9 @@ pub(crate) use crate::{
|
|||||||
verbosity::Verbosity,
|
verbosity::Verbosity,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type CompilationResult<'a, T> = Result<T, CompilationError<'a>>;
|
pub(crate) type CompilationResult<'a, T> = Result<T, CompilationError<'a>>;
|
||||||
|
|
||||||
pub type RunResult<'a, T> = Result<T, RuntimeError<'a>>;
|
pub(crate) type RunResult<'a, T> = Result<T, RuntimeError<'a>>;
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
pub(crate) use std::io::prelude::*;
|
pub(crate) use std::io::prelude::*;
|
||||||
|
@ -3,13 +3,13 @@ use crate::common::*;
|
|||||||
use crate::misc::{maybe_s, show_whitespace, write_error_context, Or};
|
use crate::misc::{maybe_s, show_whitespace, write_error_context, Or};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct CompilationError<'a> {
|
pub(crate) struct CompilationError<'a> {
|
||||||
pub text: &'a str,
|
pub(crate) text: &'a str,
|
||||||
pub offset: usize,
|
pub(crate) offset: usize,
|
||||||
pub line: usize,
|
pub(crate) line: usize,
|
||||||
pub column: usize,
|
pub(crate) column: usize,
|
||||||
pub width: usize,
|
pub(crate) width: usize,
|
||||||
pub kind: CompilationErrorKind<'a>,
|
pub(crate) kind: CompilationErrorKind<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Display for CompilationError<'a> {
|
impl<'a> Display for CompilationError<'a> {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum CompilationErrorKind<'a> {
|
pub(crate) enum CompilationErrorKind<'a> {
|
||||||
AliasShadowsRecipe {
|
AliasShadowsRecipe {
|
||||||
alias: &'a str,
|
alias: &'a str,
|
||||||
recipe_line: usize,
|
recipe_line: usize,
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub const DEFAULT_SHELL: &str = "sh";
|
pub(crate) const DEFAULT_SHELL: &str = "sh";
|
||||||
|
|
||||||
pub struct Configuration<'a> {
|
pub(crate) struct Configuration<'a> {
|
||||||
pub dry_run: bool,
|
pub(crate) dry_run: bool,
|
||||||
pub evaluate: bool,
|
pub(crate) evaluate: bool,
|
||||||
pub highlight: bool,
|
pub(crate) highlight: bool,
|
||||||
pub overrides: BTreeMap<&'a str, &'a str>,
|
pub(crate) overrides: BTreeMap<&'a str, &'a str>,
|
||||||
pub quiet: bool,
|
pub(crate) quiet: bool,
|
||||||
pub shell: &'a str,
|
pub(crate) shell: &'a str,
|
||||||
pub color: Color,
|
pub(crate) color: Color,
|
||||||
pub verbosity: Verbosity,
|
pub(crate) verbosity: Verbosity,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Default for Configuration<'a> {
|
impl<'a> Default for Configuration<'a> {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub enum Expression<'a> {
|
pub(crate) enum Expression<'a> {
|
||||||
Backtick {
|
Backtick {
|
||||||
raw: &'a str,
|
raw: &'a str,
|
||||||
token: Token<'a>,
|
token: Token<'a>,
|
||||||
@ -28,11 +28,11 @@ pub enum Expression<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Expression<'a> {
|
impl<'a> Expression<'a> {
|
||||||
pub fn variables(&'a self) -> Variables<'a> {
|
pub(crate) fn variables(&'a self) -> Variables<'a> {
|
||||||
Variables::new(self)
|
Variables::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn functions(&'a self) -> Functions<'a> {
|
pub(crate) fn functions(&'a self) -> Functions<'a> {
|
||||||
Functions::new(self)
|
Functions::new(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub enum Fragment<'a> {
|
pub(crate) enum Fragment<'a> {
|
||||||
Text { text: Token<'a> },
|
Text { text: Token<'a> },
|
||||||
Expression { expression: Expression<'a> },
|
Expression { expression: Expression<'a> },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Fragment<'a> {
|
impl<'a> Fragment<'a> {
|
||||||
pub fn continuation(&self) -> bool {
|
pub(crate) fn continuation(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
Fragment::Text { ref text } => text.lexeme().ends_with('\\'),
|
Fragment::Text { ref text } => text.lexeme().ends_with('\\'),
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -18,7 +18,7 @@ lazy_static! {
|
|||||||
.collect();
|
.collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Function {
|
pub(crate) enum Function {
|
||||||
Nullary(fn(&FunctionContext) -> Result<String, String>),
|
Nullary(fn(&FunctionContext) -> Result<String, String>),
|
||||||
Unary(fn(&FunctionContext, &str) -> Result<String, String>),
|
Unary(fn(&FunctionContext, &str) -> Result<String, String>),
|
||||||
Binary(fn(&FunctionContext, &str, &str) -> Result<String, String>),
|
Binary(fn(&FunctionContext, &str, &str) -> Result<String, String>),
|
||||||
@ -34,7 +34,7 @@ impl Function {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve<'a>(token: &Token<'a>, argc: usize) -> CompilationResult<'a, ()> {
|
pub(crate) fn resolve<'a>(token: &Token<'a>, argc: usize) -> CompilationResult<'a, ()> {
|
||||||
let name = token.lexeme();
|
let name = token.lexeme();
|
||||||
if let Some(function) = FUNCTIONS.get(&name) {
|
if let Some(function) = FUNCTIONS.get(&name) {
|
||||||
use self::Function::*;
|
use self::Function::*;
|
||||||
@ -55,7 +55,7 @@ impl Function {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn evaluate<'a>(
|
pub(crate) fn evaluate<'a>(
|
||||||
token: &Token<'a>,
|
token: &Token<'a>,
|
||||||
name: &'a str,
|
name: &'a str,
|
||||||
context: &FunctionContext,
|
context: &FunctionContext,
|
||||||
@ -94,25 +94,25 @@ impl Function {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn arch(_context: &FunctionContext) -> Result<String, String> {
|
pub(crate) fn arch(_context: &FunctionContext) -> Result<String, String> {
|
||||||
Ok(target::arch().to_string())
|
Ok(target::arch().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn os(_context: &FunctionContext) -> Result<String, String> {
|
pub(crate) fn os(_context: &FunctionContext) -> Result<String, String> {
|
||||||
Ok(target::os().to_string())
|
Ok(target::os().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn os_family(_context: &FunctionContext) -> Result<String, String> {
|
pub(crate) fn os_family(_context: &FunctionContext) -> Result<String, String> {
|
||||||
Ok(target::os_family().to_string())
|
Ok(target::os_family().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn invocation_directory(context: &FunctionContext) -> Result<String, String> {
|
pub(crate) fn invocation_directory(context: &FunctionContext) -> Result<String, String> {
|
||||||
context.invocation_directory.clone().and_then(|s| {
|
context.invocation_directory.clone().and_then(|s| {
|
||||||
Platform::to_shell_path(&s).map_err(|e| format!("Error getting shell path: {}", e))
|
Platform::to_shell_path(&s).map_err(|e| format!("Error getting shell path: {}", e))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn env_var(context: &FunctionContext, key: &str) -> Result<String, String> {
|
pub(crate) fn env_var(context: &FunctionContext, key: &str) -> Result<String, String> {
|
||||||
use std::env::VarError::*;
|
use std::env::VarError::*;
|
||||||
|
|
||||||
if let Some(value) = context.dotenv.get(key) {
|
if let Some(value) = context.dotenv.get(key) {
|
||||||
@ -129,7 +129,7 @@ pub fn env_var(context: &FunctionContext, key: &str) -> Result<String, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn env_var_or_default(
|
pub(crate) fn env_var_or_default(
|
||||||
context: &FunctionContext,
|
context: &FunctionContext,
|
||||||
key: &str,
|
key: &str,
|
||||||
default: &str,
|
default: &str,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub struct FunctionContext<'a> {
|
pub(crate) struct FunctionContext<'a> {
|
||||||
pub invocation_directory: &'a Result<PathBuf, String>,
|
pub(crate) invocation_directory: &'a Result<PathBuf, String>,
|
||||||
pub dotenv: &'a BTreeMap<String, String>,
|
pub(crate) dotenv: &'a BTreeMap<String, String>,
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub struct Functions<'a> {
|
pub(crate) struct Functions<'a> {
|
||||||
stack: Vec<&'a Expression<'a>>,
|
stack: Vec<&'a Expression<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Functions<'a> {
|
impl<'a> Functions<'a> {
|
||||||
pub fn new(root: &'a Expression<'a>) -> Functions<'a> {
|
pub(crate) fn new(root: &'a Expression<'a>) -> Functions<'a> {
|
||||||
Functions { stack: vec![root] }
|
Functions { stack: vec![root] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub fn compile(text: &str) {
|
pub(crate) fn compile(text: &str) {
|
||||||
if let Err(error) = Parser::parse(text) {
|
if let Err(error) = Parser::parse(text) {
|
||||||
if let CompilationErrorKind::Internal { .. } = error.kind {
|
if let CompilationErrorKind::Internal { .. } = error.kind {
|
||||||
panic!("{}", error)
|
panic!("{}", error)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub struct InterruptGuard;
|
pub(crate) struct InterruptGuard;
|
||||||
|
|
||||||
impl InterruptGuard {
|
impl InterruptGuard {
|
||||||
pub fn new() -> InterruptGuard {
|
pub(crate) fn new() -> InterruptGuard {
|
||||||
InterruptHandler::instance().block();
|
InterruptHandler::instance().block();
|
||||||
InterruptGuard
|
InterruptGuard
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub struct InterruptHandler {
|
pub(crate) struct InterruptHandler {
|
||||||
blocks: u32,
|
blocks: u32,
|
||||||
interrupted: bool,
|
interrupted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InterruptHandler {
|
impl InterruptHandler {
|
||||||
pub fn install() -> Result<(), ctrlc::Error> {
|
pub(crate) fn install() -> Result<(), ctrlc::Error> {
|
||||||
ctrlc::set_handler(|| InterruptHandler::instance().interrupt())
|
ctrlc::set_handler(|| InterruptHandler::instance().interrupt())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn instance() -> MutexGuard<'static, InterruptHandler> {
|
pub(crate) fn instance() -> MutexGuard<'static, InterruptHandler> {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref INSTANCE: Mutex<InterruptHandler> = Mutex::new(InterruptHandler::new());
|
static ref INSTANCE: Mutex<InterruptHandler> = Mutex::new(InterruptHandler::new());
|
||||||
}
|
}
|
||||||
@ -47,11 +47,11 @@ impl InterruptHandler {
|
|||||||
process::exit(130);
|
process::exit(130);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn block(&mut self) {
|
pub(crate) fn block(&mut self) {
|
||||||
self.blocks += 1;
|
self.blocks += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unblock(&mut self) {
|
pub(crate) fn unblock(&mut self) {
|
||||||
if self.blocks == 0 {
|
if self.blocks == 0 {
|
||||||
die!(
|
die!(
|
||||||
"{}",
|
"{}",
|
||||||
@ -69,7 +69,7 @@ impl InterruptHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn guard<T, F: FnOnce() -> T>(function: F) -> T {
|
pub(crate) fn guard<T, F: FnOnce() -> T>(function: F) -> T {
|
||||||
let _guard = InterruptGuard::new();
|
let _guard = InterruptGuard::new();
|
||||||
function()
|
function()
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Justfile<'a> {
|
pub(crate) struct Justfile<'a> {
|
||||||
pub recipes: BTreeMap<&'a str, Recipe<'a>>,
|
pub(crate) recipes: BTreeMap<&'a str, Recipe<'a>>,
|
||||||
pub assignments: BTreeMap<&'a str, Expression<'a>>,
|
pub(crate) assignments: BTreeMap<&'a str, Expression<'a>>,
|
||||||
pub exports: BTreeSet<&'a str>,
|
pub(crate) exports: BTreeSet<&'a str>,
|
||||||
pub aliases: BTreeMap<&'a str, Alias<'a>>,
|
pub(crate) aliases: BTreeMap<&'a str, Alias<'a>>,
|
||||||
pub deprecated_equals: bool,
|
pub(crate) deprecated_equals: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Justfile<'a> where {
|
impl<'a> Justfile<'a> where {
|
||||||
pub fn first(&self) -> Option<&Recipe> {
|
pub(crate) fn first(&self) -> Option<&Recipe> {
|
||||||
let mut first: Option<&Recipe> = None;
|
let mut first: Option<&Recipe> = None;
|
||||||
for recipe in self.recipes.values() {
|
for recipe in self.recipes.values() {
|
||||||
if let Some(first_recipe) = first {
|
if let Some(first_recipe) = first {
|
||||||
@ -24,11 +24,11 @@ impl<'a> Justfile<'a> where {
|
|||||||
first
|
first
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn count(&self) -> usize {
|
pub(crate) fn count(&self) -> usize {
|
||||||
self.recipes.len()
|
self.recipes.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suggest(&self, name: &str) -> Option<&'a str> {
|
pub(crate) fn suggest(&self, name: &str) -> Option<&'a str> {
|
||||||
let mut suggestions = self
|
let mut suggestions = self
|
||||||
.recipes
|
.recipes
|
||||||
.keys()
|
.keys()
|
||||||
@ -43,7 +43,7 @@ impl<'a> Justfile<'a> where {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(
|
pub(crate) fn run(
|
||||||
&'a self,
|
&'a self,
|
||||||
invocation_directory: &'a Result<PathBuf, String>,
|
invocation_directory: &'a Result<PathBuf, String>,
|
||||||
arguments: &[&'a str],
|
arguments: &[&'a str],
|
||||||
@ -141,11 +141,11 @@ impl<'a> Justfile<'a> where {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_alias(&self, name: &str) -> Option<&Alias> {
|
pub(crate) fn get_alias(&self, name: &str) -> Option<&Alias> {
|
||||||
self.aliases.get(name)
|
self.aliases.get(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_recipe(&self, name: &str) -> Option<&Recipe<'a>> {
|
pub(crate) fn get_recipe(&self, name: &str) -> Option<&Recipe<'a>> {
|
||||||
if let Some(recipe) = self.recipes.get(name) {
|
if let Some(recipe) = self.recipes.get(name) {
|
||||||
Some(recipe)
|
Some(recipe)
|
||||||
} else if let Some(alias) = self.aliases.get(name) {
|
} else if let Some(alias) = self.aliases.get(name) {
|
||||||
|
@ -8,7 +8,7 @@ use TokenKind::*;
|
|||||||
/// `self.next` points to the next character to be lexed, and
|
/// `self.next` points to the next character to be lexed, and
|
||||||
/// the text between `self.token_start` and `self.token_end` contains
|
/// the text between `self.token_start` and `self.token_end` contains
|
||||||
/// the current token being lexed.
|
/// the current token being lexed.
|
||||||
pub struct Lexer<'a> {
|
pub(crate) struct Lexer<'a> {
|
||||||
/// Source text
|
/// Source text
|
||||||
text: &'a str,
|
text: &'a str,
|
||||||
/// Char iterator
|
/// Char iterator
|
||||||
@ -27,7 +27,7 @@ pub struct Lexer<'a> {
|
|||||||
|
|
||||||
impl<'a> Lexer<'a> {
|
impl<'a> Lexer<'a> {
|
||||||
/// Lex `text`
|
/// Lex `text`
|
||||||
pub fn lex(text: &str) -> CompilationResult<Vec<Token>> {
|
pub(crate) fn lex(text: &str) -> CompilationResult<Vec<Token>> {
|
||||||
Lexer::new(text).tokenize()
|
Lexer::new(text).tokenize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ extern crate lazy_static;
|
|||||||
mod testing;
|
mod testing;
|
||||||
|
|
||||||
#[cfg(fuzzing)]
|
#[cfg(fuzzing)]
|
||||||
pub mod fuzzing;
|
pub(crate) mod fuzzing;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod die;
|
mod die;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub fn load_dotenv() -> RunResult<'static, BTreeMap<String, String>> {
|
pub(crate) fn load_dotenv() -> RunResult<'static, BTreeMap<String, String>> {
|
||||||
match dotenv::dotenv_iter() {
|
match dotenv::dotenv_iter() {
|
||||||
Ok(iter) => {
|
Ok(iter) => {
|
||||||
let result: dotenv::Result<BTreeMap<String, String>> = iter.collect();
|
let result: dotenv::Result<BTreeMap<String, String>> = iter.collect();
|
||||||
|
20
src/misc.rs
20
src/misc.rs
@ -1,6 +1,6 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub fn show_whitespace(text: &str) -> String {
|
pub(crate) fn show_whitespace(text: &str) -> String {
|
||||||
text
|
text
|
||||||
.chars()
|
.chars()
|
||||||
.map(|c| match c {
|
.map(|c| match c {
|
||||||
@ -11,19 +11,19 @@ pub fn show_whitespace(text: &str) -> String {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default<T: Default>() -> T {
|
pub(crate) fn default<T: Default>() -> T {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn empty<T, C: iter::FromIterator<T>>() -> C {
|
pub(crate) fn empty<T, C: iter::FromIterator<T>>() -> C {
|
||||||
iter::empty().collect()
|
iter::empty().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ticks<T: Display>(ts: &[T]) -> Vec<Tick<T>> {
|
pub(crate) fn ticks<T: Display>(ts: &[T]) -> Vec<Tick<T>> {
|
||||||
ts.iter().map(Tick).collect()
|
ts.iter().map(Tick).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_s(n: usize) -> &'static str {
|
pub(crate) fn maybe_s(n: usize) -> &'static str {
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
""
|
""
|
||||||
} else {
|
} else {
|
||||||
@ -31,7 +31,7 @@ pub fn maybe_s(n: usize) -> &'static str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn conjoin<T: Display>(
|
pub(crate) fn conjoin<T: Display>(
|
||||||
f: &mut Formatter,
|
f: &mut Formatter,
|
||||||
values: &[T],
|
values: &[T],
|
||||||
conjunction: &str,
|
conjunction: &str,
|
||||||
@ -55,7 +55,7 @@ pub fn conjoin<T: Display>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_error_context(
|
pub(crate) fn write_error_context(
|
||||||
f: &mut Formatter,
|
f: &mut Formatter,
|
||||||
text: &str,
|
text: &str,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
@ -121,7 +121,7 @@ pub fn write_error_context(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct And<'a, T: 'a + Display>(pub &'a [T]);
|
pub(crate) struct And<'a, T: 'a + Display>(pub(crate) &'a [T]);
|
||||||
|
|
||||||
impl<'a, T: Display> Display for And<'a, T> {
|
impl<'a, T: Display> Display for And<'a, T> {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||||
@ -129,7 +129,7 @@ impl<'a, T: Display> Display for And<'a, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Or<'a, T: 'a + Display>(pub &'a [T]);
|
pub(crate) struct Or<'a, T: 'a + Display>(pub(crate) &'a [T]);
|
||||||
|
|
||||||
impl<'a, T: Display> Display for Or<'a, T> {
|
impl<'a, T: Display> Display for Or<'a, T> {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||||
@ -137,7 +137,7 @@ impl<'a, T: Display> Display for Or<'a, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Tick<'a, T: 'a + Display>(pub &'a T);
|
pub(crate) struct Tick<'a, T: 'a + Display>(pub(crate) &'a T);
|
||||||
|
|
||||||
impl<'a, T: Display> Display for Tick<'a, T> {
|
impl<'a, T: Display> Display for Tick<'a, T> {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pub trait Ordinal {
|
pub(crate) trait Ordinal {
|
||||||
/// Convert an index starting at 0 to an ordinal starting at 1
|
/// Convert an index starting at 0 to an ordinal starting at 1
|
||||||
fn ordinal(self) -> Self;
|
fn ordinal(self) -> Self;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
/// Run a command and return the data it wrote to stdout as a string
|
/// Run a command and return the data it wrote to stdout as a string
|
||||||
pub fn output(mut command: Command) -> Result<String, OutputError> {
|
pub(crate) fn output(mut command: Command) -> Result<String, OutputError> {
|
||||||
match command.output() {
|
match command.output() {
|
||||||
Ok(output) => {
|
Ok(output) => {
|
||||||
if let Some(code) = output.status.code() {
|
if let Some(code) = output.status.code() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum OutputError {
|
pub(crate) enum OutputError {
|
||||||
/// Non-zero exit code
|
/// Non-zero exit code
|
||||||
Code(i32),
|
Code(i32),
|
||||||
/// IO error
|
/// IO error
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct Parameter<'a> {
|
pub(crate) struct Parameter<'a> {
|
||||||
pub default: Option<Expression<'a>>,
|
pub(crate) default: Option<Expression<'a>>,
|
||||||
pub name: &'a str,
|
pub(crate) name: &'a str,
|
||||||
pub token: Token<'a>,
|
pub(crate) token: Token<'a>,
|
||||||
pub variadic: bool,
|
pub(crate) variadic: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Display for Parameter<'a> {
|
impl<'a> Display for Parameter<'a> {
|
||||||
|
@ -3,7 +3,7 @@ use crate::common::*;
|
|||||||
use CompilationErrorKind::*;
|
use CompilationErrorKind::*;
|
||||||
use TokenKind::*;
|
use TokenKind::*;
|
||||||
|
|
||||||
pub struct Parser<'a> {
|
pub(crate) struct Parser<'a> {
|
||||||
text: &'a str,
|
text: &'a str,
|
||||||
tokens: itertools::PutBackN<vec::IntoIter<Token<'a>>>,
|
tokens: itertools::PutBackN<vec::IntoIter<Token<'a>>>,
|
||||||
recipes: BTreeMap<&'a str, Recipe<'a>>,
|
recipes: BTreeMap<&'a str, Recipe<'a>>,
|
||||||
@ -16,14 +16,14 @@ pub struct Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Parser<'a> {
|
impl<'a> Parser<'a> {
|
||||||
pub fn parse(text: &'a str) -> CompilationResult<'a, Justfile> {
|
pub(crate) fn parse(text: &'a str) -> CompilationResult<'a, Justfile> {
|
||||||
let mut tokens = Lexer::lex(text)?;
|
let mut tokens = Lexer::lex(text)?;
|
||||||
tokens.retain(|token| token.kind != Whitespace);
|
tokens.retain(|token| token.kind != Whitespace);
|
||||||
let parser = Parser::new(text, tokens);
|
let parser = Parser::new(text, tokens);
|
||||||
parser.justfile()
|
parser.justfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(text: &'a str, tokens: Vec<Token<'a>>) -> Parser<'a> {
|
pub(crate) fn new(text: &'a str, tokens: Vec<Token<'a>>) -> Parser<'a> {
|
||||||
Parser {
|
Parser {
|
||||||
tokens: itertools::put_back_n(tokens),
|
tokens: itertools::put_back_n(tokens),
|
||||||
recipes: empty(),
|
recipes: empty(),
|
||||||
@ -391,7 +391,7 @@ impl<'a> Parser<'a> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn justfile(mut self) -> CompilationResult<'a, Justfile<'a>> {
|
pub(crate) fn justfile(mut self) -> CompilationResult<'a, Justfile<'a>> {
|
||||||
let mut doc = None;
|
let mut doc = None;
|
||||||
loop {
|
loop {
|
||||||
match self.tokens.next() {
|
match self.tokens.next() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub struct Platform;
|
pub(crate) struct Platform;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
impl PlatformInterface for Platform {
|
impl PlatformInterface for Platform {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub trait PlatformInterface {
|
pub(crate) trait PlatformInterface {
|
||||||
/// Construct a command equivalent to running the script at `path` with the
|
/// Construct a command equivalent to running the script at `path` with the
|
||||||
/// shebang line `shebang`
|
/// shebang line `shebang`
|
||||||
fn make_shebang_command(
|
fn make_shebang_command(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/// Source position
|
/// Source position
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||||
pub struct Position {
|
pub(crate) struct Position {
|
||||||
pub offset: usize,
|
pub(crate) offset: usize,
|
||||||
pub column: usize,
|
pub(crate) column: usize,
|
||||||
pub line: usize,
|
pub(crate) line: usize,
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub trait RangeExt<T> {
|
pub(crate) trait RangeExt<T> {
|
||||||
fn range_contains(&self, i: &T) -> bool;
|
fn range_contains(&self, i: &T) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,25 +23,25 @@ fn error_from_signal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct Recipe<'a> {
|
pub(crate) struct Recipe<'a> {
|
||||||
pub dependencies: Vec<&'a str>,
|
pub(crate) dependencies: Vec<&'a str>,
|
||||||
pub dependency_tokens: Vec<Token<'a>>,
|
pub(crate) dependency_tokens: Vec<Token<'a>>,
|
||||||
pub doc: Option<&'a str>,
|
pub(crate) doc: Option<&'a str>,
|
||||||
pub line_number: usize,
|
pub(crate) line_number: usize,
|
||||||
pub lines: Vec<Vec<Fragment<'a>>>,
|
pub(crate) lines: Vec<Vec<Fragment<'a>>>,
|
||||||
pub name: &'a str,
|
pub(crate) name: &'a str,
|
||||||
pub parameters: Vec<Parameter<'a>>,
|
pub(crate) parameters: Vec<Parameter<'a>>,
|
||||||
pub private: bool,
|
pub(crate) private: bool,
|
||||||
pub quiet: bool,
|
pub(crate) quiet: bool,
|
||||||
pub shebang: bool,
|
pub(crate) shebang: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Recipe<'a> {
|
impl<'a> Recipe<'a> {
|
||||||
pub fn argument_range(&self) -> RangeInclusive<usize> {
|
pub(crate) fn argument_range(&self) -> RangeInclusive<usize> {
|
||||||
self.min_arguments()..=self.max_arguments()
|
self.min_arguments()..=self.max_arguments()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn min_arguments(&self) -> usize {
|
pub(crate) fn min_arguments(&self) -> usize {
|
||||||
self
|
self
|
||||||
.parameters
|
.parameters
|
||||||
.iter()
|
.iter()
|
||||||
@ -49,7 +49,7 @@ impl<'a> Recipe<'a> {
|
|||||||
.count()
|
.count()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max_arguments(&self) -> usize {
|
pub(crate) fn max_arguments(&self) -> usize {
|
||||||
if self.parameters.iter().any(|p| p.variadic) {
|
if self.parameters.iter().any(|p| p.variadic) {
|
||||||
usize::MAX - 1
|
usize::MAX - 1
|
||||||
} else {
|
} else {
|
||||||
@ -57,7 +57,7 @@ impl<'a> Recipe<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(
|
pub(crate) fn run(
|
||||||
&self,
|
&self,
|
||||||
context: &RecipeContext<'a>,
|
context: &RecipeContext<'a>,
|
||||||
arguments: &[&'a str],
|
arguments: &[&'a str],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub struct RecipeContext<'a> {
|
pub(crate) struct RecipeContext<'a> {
|
||||||
pub invocation_directory: &'a Result<PathBuf, String>,
|
pub(crate) invocation_directory: &'a Result<PathBuf, String>,
|
||||||
pub configuration: &'a Configuration<'a>,
|
pub(crate) configuration: &'a Configuration<'a>,
|
||||||
pub scope: BTreeMap<&'a str, String>,
|
pub(crate) scope: BTreeMap<&'a str, String>,
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ use CompilationErrorKind::*;
|
|||||||
// of the struct, and the second being the lifetime of the tokens
|
// of the struct, and the second being the lifetime of the tokens
|
||||||
// that it contains.
|
// that it contains.
|
||||||
|
|
||||||
pub struct RecipeResolver<'a: 'b, 'b> {
|
pub(crate) struct RecipeResolver<'a: 'b, 'b> {
|
||||||
stack: Vec<&'a str>,
|
stack: Vec<&'a str>,
|
||||||
seen: BTreeSet<&'a str>,
|
seen: BTreeSet<&'a str>,
|
||||||
resolved: BTreeSet<&'a str>,
|
resolved: BTreeSet<&'a str>,
|
||||||
@ -22,7 +22,7 @@ pub struct RecipeResolver<'a: 'b, 'b> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> RecipeResolver<'a, 'b> {
|
impl<'a, 'b> RecipeResolver<'a, 'b> {
|
||||||
pub fn resolve_recipes(
|
pub(crate) fn resolve_recipes(
|
||||||
recipes: &BTreeMap<&'a str, Recipe<'a>>,
|
recipes: &BTreeMap<&'a str, Recipe<'a>>,
|
||||||
assignments: &BTreeMap<&'a str, Expression<'a>>,
|
assignments: &BTreeMap<&'a str, Expression<'a>>,
|
||||||
text: &'a str,
|
text: &'a str,
|
||||||
|
@ -3,7 +3,7 @@ use crate::common::*;
|
|||||||
use crate::misc::{maybe_s, ticks, write_error_context, And, Or, Tick};
|
use crate::misc::{maybe_s, ticks, write_error_context, And, Or, Tick};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum RuntimeError<'a> {
|
pub(crate) enum RuntimeError<'a> {
|
||||||
ArgumentCountMismatch {
|
ArgumentCountMismatch {
|
||||||
recipe: &'a str,
|
recipe: &'a str,
|
||||||
parameters: Vec<&'a Parameter<'a>>,
|
parameters: Vec<&'a Parameter<'a>>,
|
||||||
@ -67,7 +67,7 @@ pub enum RuntimeError<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> RuntimeError<'a> {
|
impl<'a> RuntimeError<'a> {
|
||||||
pub fn code(&self) -> Option<i32> {
|
pub(crate) fn code(&self) -> Option<i32> {
|
||||||
use RuntimeError::*;
|
use RuntimeError::*;
|
||||||
match *self {
|
match *self {
|
||||||
Code { code, .. }
|
Code { code, .. }
|
||||||
|
@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
|
|||||||
|
|
||||||
const FILENAME: &str = "justfile";
|
const FILENAME: &str = "justfile";
|
||||||
|
|
||||||
pub fn justfile(directory: &Path) -> Result<PathBuf, SearchError> {
|
pub(crate) fn justfile(directory: &Path) -> Result<PathBuf, SearchError> {
|
||||||
let mut candidates = Vec::new();
|
let mut candidates = Vec::new();
|
||||||
let dir = fs::read_dir(directory).map_err(|io_error| SearchError::Io {
|
let dir = fs::read_dir(directory).map_err(|io_error| SearchError::Io {
|
||||||
io_error,
|
io_error,
|
||||||
|
@ -2,7 +2,7 @@ use std::{fmt, io, path::PathBuf};
|
|||||||
|
|
||||||
use crate::misc::And;
|
use crate::misc::And;
|
||||||
|
|
||||||
pub enum SearchError {
|
pub(crate) enum SearchError {
|
||||||
MultipleCandidates {
|
MultipleCandidates {
|
||||||
candidates: Vec<PathBuf>,
|
candidates: Vec<PathBuf>,
|
||||||
},
|
},
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
pub struct Shebang<'a> {
|
pub(crate) struct Shebang<'a> {
|
||||||
pub interpreter: &'a str,
|
pub(crate) interpreter: &'a str,
|
||||||
pub argument: Option<&'a str>,
|
pub(crate) argument: Option<&'a str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Shebang<'a> {
|
impl<'a> Shebang<'a> {
|
||||||
pub fn new(text: &'a str) -> Option<Shebang<'a>> {
|
pub(crate) fn new(text: &'a str) -> Option<Shebang<'a>> {
|
||||||
if !text.starts_with("#!") {
|
if !text.starts_with("#!") {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||||
pub enum State<'a> {
|
pub(crate) enum State<'a> {
|
||||||
Normal,
|
Normal,
|
||||||
Indented { indentation: &'a str },
|
Indented { indentation: &'a str },
|
||||||
Text,
|
Text,
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct StringLiteral<'a> {
|
pub(crate) struct StringLiteral<'a> {
|
||||||
pub raw: &'a str,
|
pub(crate) raw: &'a str,
|
||||||
pub cooked: Cow<'a, str>,
|
pub(crate) cooked: Cow<'a, str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> StringLiteral<'a> {
|
impl<'a> StringLiteral<'a> {
|
||||||
pub fn new(token: &Token<'a>) -> CompilationResult<'a, StringLiteral<'a>> {
|
pub(crate) fn new(token: &Token<'a>) -> CompilationResult<'a, StringLiteral<'a>> {
|
||||||
let raw = &token.lexeme()[1..token.lexeme().len() - 1];
|
let raw = &token.lexeme()[1..token.lexeme().len() - 1];
|
||||||
|
|
||||||
if let TokenKind::StringRaw = token.kind {
|
if let TokenKind::StringRaw = token.kind {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub fn parse(text: &str) -> Justfile {
|
pub(crate) fn parse(text: &str) -> Justfile {
|
||||||
match Parser::parse(text) {
|
match Parser::parse(text) {
|
||||||
Ok(justfile) => justfile,
|
Ok(justfile) => justfile,
|
||||||
Err(error) => panic!("Expected successful parse but got error:\n {}", error),
|
Err(error) => panic!("Expected successful parse but got error:\n {}", error),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tempdir() -> tempfile::TempDir {
|
pub(crate) fn tempdir() -> tempfile::TempDir {
|
||||||
tempfile::Builder::new()
|
tempfile::Builder::new()
|
||||||
.prefix("just-test-tempdir")
|
.prefix("just-test-tempdir")
|
||||||
.tempdir()
|
.tempdir()
|
||||||
|
18
src/token.rs
18
src/token.rs
@ -1,21 +1,21 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct Token<'a> {
|
pub(crate) struct Token<'a> {
|
||||||
pub offset: usize,
|
pub(crate) offset: usize,
|
||||||
pub length: usize,
|
pub(crate) length: usize,
|
||||||
pub line: usize,
|
pub(crate) line: usize,
|
||||||
pub column: usize,
|
pub(crate) column: usize,
|
||||||
pub text: &'a str,
|
pub(crate) text: &'a str,
|
||||||
pub kind: TokenKind,
|
pub(crate) kind: TokenKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Token<'a> {
|
impl<'a> Token<'a> {
|
||||||
pub fn lexeme(&self) -> &'a str {
|
pub(crate) fn lexeme(&self) -> &'a str {
|
||||||
&self.text[self.offset..self.offset + self.length]
|
&self.text[self.offset..self.offset + self.length]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error(&self, kind: CompilationErrorKind<'a>) -> CompilationError<'a> {
|
pub(crate) fn error(&self, kind: CompilationErrorKind<'a>) -> CompilationError<'a> {
|
||||||
CompilationError {
|
CompilationError {
|
||||||
column: self.column,
|
column: self.column,
|
||||||
offset: self.offset,
|
offset: self.offset,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
pub enum TokenKind {
|
pub(crate) enum TokenKind {
|
||||||
At,
|
At,
|
||||||
Backtick,
|
Backtick,
|
||||||
Colon,
|
Colon,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum UseColor {
|
pub(crate) enum UseColor {
|
||||||
Auto,
|
Auto,
|
||||||
Always,
|
Always,
|
||||||
Never,
|
Never,
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
|
|
||||||
pub struct Variables<'a> {
|
pub(crate) struct Variables<'a> {
|
||||||
stack: Vec<&'a Expression<'a>>,
|
stack: Vec<&'a Expression<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Variables<'a> {
|
impl<'a> Variables<'a> {
|
||||||
pub fn new(root: &'a Expression<'a>) -> Variables<'a> {
|
pub(crate) fn new(root: &'a Expression<'a>) -> Variables<'a> {
|
||||||
Variables { stack: vec![root] }
|
Variables { stack: vec![root] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
use Verbosity::*;
|
use Verbosity::*;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum Verbosity {
|
pub(crate) enum Verbosity {
|
||||||
Taciturn,
|
Taciturn,
|
||||||
Loquacious,
|
Loquacious,
|
||||||
Grandiloquent,
|
Grandiloquent,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Verbosity {
|
impl Verbosity {
|
||||||
pub fn from_flag_occurrences(flag_occurences: u64) -> Verbosity {
|
pub(crate) fn from_flag_occurrences(flag_occurences: u64) -> Verbosity {
|
||||||
match flag_occurences {
|
match flag_occurences {
|
||||||
0 => Taciturn,
|
0 => Taciturn,
|
||||||
1 => Loquacious,
|
1 => Loquacious,
|
||||||
@ -16,7 +16,7 @@ impl Verbosity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn loquacious(self) -> bool {
|
pub(crate) fn loquacious(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Taciturn => false,
|
Taciturn => false,
|
||||||
Loquacious => true,
|
Loquacious => true,
|
||||||
@ -24,7 +24,7 @@ impl Verbosity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn grandiloquent(self) -> bool {
|
pub(crate) fn grandiloquent(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Taciturn => false,
|
Taciturn => false,
|
||||||
Loquacious => false,
|
Loquacious => false,
|
||||||
|
Loading…
Reference in New Issue
Block a user