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:
Casey Rodarmor 2019-09-21 15:35:03 -07:00 committed by GitHub
parent 1521982891
commit 1cb90f4e65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 190 additions and 190 deletions

View File

@ -1,11 +1,11 @@
use crate::common::*;
#[derive(Debug)]
pub struct Alias<'a> {
pub name: &'a str,
pub target: &'a str,
pub line_number: usize,
pub private: bool,
pub(crate) struct Alias<'a> {
pub(crate) name: &'a str,
pub(crate) target: &'a str,
pub(crate) line_number: usize,
pub(crate) private: bool,
}
impl<'a> Display for Alias<'a> {

View File

@ -1,7 +1,7 @@
use crate::common::*;
use CompilationErrorKind::*;
pub struct AliasResolver<'a, 'b>
pub(crate) struct AliasResolver<'a, 'b>
where
'a: 'b,
{
@ -11,7 +11,7 @@ where
}
impl<'a: 'b, 'b> AliasResolver<'a, 'b> {
pub fn resolve_aliases(
pub(crate) fn resolve_aliases(
aliases: &BTreeMap<&'a str, Alias<'a>>,
recipes: &BTreeMap<&'a str, Recipe<'a>>,
alias_tokens: &BTreeMap<&'a str, Token<'a>>,

View File

@ -1,20 +1,20 @@
use crate::common::*;
pub struct AssignmentEvaluator<'a: 'b, 'b> {
pub assignments: &'b BTreeMap<&'a str, Expression<'a>>,
pub invocation_directory: &'b Result<PathBuf, String>,
pub dotenv: &'b BTreeMap<String, String>,
pub dry_run: bool,
pub evaluated: BTreeMap<&'a str, String>,
pub exports: &'b BTreeSet<&'a str>,
pub overrides: &'b BTreeMap<&'b str, &'b str>,
pub quiet: bool,
pub scope: &'b BTreeMap<&'a str, String>,
pub shell: &'b str,
pub(crate) struct AssignmentEvaluator<'a: 'b, 'b> {
pub(crate) assignments: &'b BTreeMap<&'a str, Expression<'a>>,
pub(crate) invocation_directory: &'b Result<PathBuf, String>,
pub(crate) dotenv: &'b BTreeMap<String, String>,
pub(crate) dry_run: bool,
pub(crate) evaluated: BTreeMap<&'a str, String>,
pub(crate) exports: &'b BTreeSet<&'a str>,
pub(crate) overrides: &'b BTreeMap<&'b str, &'b str>,
pub(crate) quiet: bool,
pub(crate) scope: &'b BTreeMap<&'a str, String>,
pub(crate) shell: &'b str,
}
impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
pub fn evaluate_assignments(
pub(crate) fn evaluate_assignments(
assignments: &BTreeMap<&'a str, Expression<'a>>,
invocation_directory: &Result<PathBuf, String>,
dotenv: &'b BTreeMap<String, String>,
@ -43,7 +43,7 @@ impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
Ok(evaluator.evaluated)
}
pub fn evaluate_line(
pub(crate) fn evaluate_line(
&mut self,
line: &[Fragment<'a>],
arguments: &BTreeMap<&str, Cow<str>>,
@ -81,7 +81,7 @@ impl<'a, 'b> AssignmentEvaluator<'a, 'b> {
Ok(())
}
pub fn evaluate_expression(
pub(crate) fn evaluate_expression(
&mut self,
expression: &Expression<'a>,
arguments: &BTreeMap<&str, Cow<str>>,

View File

@ -2,7 +2,7 @@ use crate::common::*;
use CompilationErrorKind::*;
pub struct AssignmentResolver<'a: 'b, 'b> {
pub(crate) struct AssignmentResolver<'a: 'b, 'b> {
assignments: &'b BTreeMap<&'a str, Expression<'a>>,
assignment_tokens: &'b BTreeMap<&'a str, Token<'a>>,
stack: Vec<&'a str>,
@ -11,7 +11,7 @@ pub struct AssignmentResolver<'a: 'b, 'b> {
}
impl<'a: 'b, 'b> AssignmentResolver<'a, 'b> {
pub fn resolve_assignments(
pub(crate) fn resolve_assignments(
assignments: &BTreeMap<&'a str, Expression<'a>>,
assignment_tokens: &BTreeMap<&'a str, Token<'a>>,
) -> CompilationResult<'a, ()> {

View File

@ -5,7 +5,7 @@ use ansi_term::{ANSIGenericString, Prefix, Style, Suffix};
use atty::Stream;
#[derive(Copy, Clone)]
pub struct Color {
pub(crate) struct Color {
use_color: UseColor,
atty: bool,
style: Style,
@ -31,7 +31,7 @@ impl Color {
}
}
pub fn fmt(fmt: &Formatter) -> Color {
pub(crate) fn fmt(fmt: &Formatter) -> Color {
if fmt.alternate() {
Color::always()
} else {
@ -39,72 +39,72 @@ impl Color {
}
}
pub fn auto() -> Color {
pub(crate) fn auto() -> Color {
Color {
use_color: UseColor::Auto,
..default()
}
}
pub fn always() -> Color {
pub(crate) fn always() -> Color {
Color {
use_color: UseColor::Always,
..default()
}
}
pub fn never() -> Color {
pub(crate) fn never() -> Color {
Color {
use_color: UseColor::Never,
..default()
}
}
pub fn stderr(self) -> Color {
pub(crate) fn stderr(self) -> Color {
self.redirect(Stream::Stderr)
}
pub fn stdout(self) -> Color {
pub(crate) fn stdout(self) -> Color {
self.redirect(Stream::Stdout)
}
pub fn doc(self) -> Color {
pub(crate) fn doc(self) -> Color {
self.restyle(Style::new().fg(Blue))
}
pub fn error(self) -> Color {
pub(crate) fn error(self) -> Color {
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())
}
pub fn banner(self) -> Color {
pub(crate) fn banner(self) -> Color {
self.restyle(Style::new().fg(Cyan).bold())
}
pub fn command(self) -> Color {
pub(crate) fn command(self) -> Color {
self.restyle(Style::new().bold())
}
pub fn parameter(self) -> Color {
pub(crate) fn parameter(self) -> Color {
self.restyle(Style::new().fg(Cyan))
}
pub fn message(self) -> Color {
pub(crate) fn message(self) -> Color {
self.restyle(Style::new().bold())
}
pub fn annotation(self) -> Color {
pub(crate) fn annotation(self) -> Color {
self.restyle(Style::new().fg(Purple))
}
pub fn string(self) -> Color {
pub(crate) fn string(self) -> Color {
self.restyle(Style::new().fg(Green))
}
pub fn active(&self) -> bool {
pub(crate) fn active(&self) -> bool {
match self.use_color {
UseColor::Always => true,
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)
}
pub fn prefix(&self) -> Prefix {
pub(crate) fn prefix(&self) -> Prefix {
self.effective_style().prefix()
}
pub fn suffix(&self) -> Suffix {
pub(crate) fn suffix(&self) -> Suffix {
self.effective_style().suffix()
}
}

View File

@ -1,6 +1,6 @@
use crate::common::*;
pub trait CommandExt {
pub(crate) trait CommandExt {
fn export_environment_variables<'a>(
&mut self,
scope: &BTreeMap<&'a str, String>,

View File

@ -49,9 +49,9 @@ pub(crate) use crate::{
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)]
pub(crate) use std::io::prelude::*;

View File

@ -3,13 +3,13 @@ use crate::common::*;
use crate::misc::{maybe_s, show_whitespace, write_error_context, Or};
#[derive(Debug, PartialEq)]
pub struct CompilationError<'a> {
pub text: &'a str,
pub offset: usize,
pub line: usize,
pub column: usize,
pub width: usize,
pub kind: CompilationErrorKind<'a>,
pub(crate) struct CompilationError<'a> {
pub(crate) text: &'a str,
pub(crate) offset: usize,
pub(crate) line: usize,
pub(crate) column: usize,
pub(crate) width: usize,
pub(crate) kind: CompilationErrorKind<'a>,
}
impl<'a> Display for CompilationError<'a> {

View File

@ -1,7 +1,7 @@
use crate::common::*;
#[derive(Debug, PartialEq)]
pub enum CompilationErrorKind<'a> {
pub(crate) enum CompilationErrorKind<'a> {
AliasShadowsRecipe {
alias: &'a str,
recipe_line: usize,

View File

@ -1,16 +1,16 @@
use crate::common::*;
pub const DEFAULT_SHELL: &str = "sh";
pub(crate) const DEFAULT_SHELL: &str = "sh";
pub struct Configuration<'a> {
pub dry_run: bool,
pub evaluate: bool,
pub highlight: bool,
pub overrides: BTreeMap<&'a str, &'a str>,
pub quiet: bool,
pub shell: &'a str,
pub color: Color,
pub verbosity: Verbosity,
pub(crate) struct Configuration<'a> {
pub(crate) dry_run: bool,
pub(crate) evaluate: bool,
pub(crate) highlight: bool,
pub(crate) overrides: BTreeMap<&'a str, &'a str>,
pub(crate) quiet: bool,
pub(crate) shell: &'a str,
pub(crate) color: Color,
pub(crate) verbosity: Verbosity,
}
impl<'a> Default for Configuration<'a> {

View File

@ -1,7 +1,7 @@
use crate::common::*;
#[derive(PartialEq, Debug)]
pub enum Expression<'a> {
pub(crate) enum Expression<'a> {
Backtick {
raw: &'a str,
token: Token<'a>,
@ -28,11 +28,11 @@ pub enum Expression<'a> {
}
impl<'a> Expression<'a> {
pub fn variables(&'a self) -> Variables<'a> {
pub(crate) fn variables(&'a self) -> Variables<'a> {
Variables::new(self)
}
pub fn functions(&'a self) -> Functions<'a> {
pub(crate) fn functions(&'a self) -> Functions<'a> {
Functions::new(self)
}
}

View File

@ -1,13 +1,13 @@
use crate::common::*;
#[derive(PartialEq, Debug)]
pub enum Fragment<'a> {
pub(crate) enum Fragment<'a> {
Text { text: Token<'a> },
Expression { expression: Expression<'a> },
}
impl<'a> Fragment<'a> {
pub fn continuation(&self) -> bool {
pub(crate) fn continuation(&self) -> bool {
match *self {
Fragment::Text { ref text } => text.lexeme().ends_with('\\'),
_ => false,

View File

@ -18,7 +18,7 @@ lazy_static! {
.collect();
}
pub enum Function {
pub(crate) enum Function {
Nullary(fn(&FunctionContext) -> Result<String, String>),
Unary(fn(&FunctionContext, &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();
if let Some(function) = FUNCTIONS.get(&name) {
use self::Function::*;
@ -55,7 +55,7 @@ impl Function {
}
}
pub fn evaluate<'a>(
pub(crate) fn evaluate<'a>(
token: &Token<'a>,
name: &'a str,
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())
}
pub fn os(_context: &FunctionContext) -> Result<String, String> {
pub(crate) fn os(_context: &FunctionContext) -> Result<String, 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())
}
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| {
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::*;
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,
key: &str,
default: &str,

View File

@ -1,6 +1,6 @@
use crate::common::*;
pub struct FunctionContext<'a> {
pub invocation_directory: &'a Result<PathBuf, String>,
pub dotenv: &'a BTreeMap<String, String>,
pub(crate) struct FunctionContext<'a> {
pub(crate) invocation_directory: &'a Result<PathBuf, String>,
pub(crate) dotenv: &'a BTreeMap<String, String>,
}

View File

@ -1,11 +1,11 @@
use crate::common::*;
pub struct Functions<'a> {
pub(crate) struct Functions<'a> {
stack: Vec<&'a Expression<'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] }
}
}

View File

@ -1,6 +1,6 @@
use crate::common::*;
pub fn compile(text: &str) {
pub(crate) fn compile(text: &str) {
if let Err(error) = Parser::parse(text) {
if let CompilationErrorKind::Internal { .. } = error.kind {
panic!("{}", error)

View File

@ -1,9 +1,9 @@
use crate::common::*;
pub struct InterruptGuard;
pub(crate) struct InterruptGuard;
impl InterruptGuard {
pub fn new() -> InterruptGuard {
pub(crate) fn new() -> InterruptGuard {
InterruptHandler::instance().block();
InterruptGuard
}

View File

@ -1,16 +1,16 @@
use crate::common::*;
pub struct InterruptHandler {
pub(crate) struct InterruptHandler {
blocks: u32,
interrupted: bool,
}
impl InterruptHandler {
pub fn install() -> Result<(), ctrlc::Error> {
pub(crate) fn install() -> Result<(), ctrlc::Error> {
ctrlc::set_handler(|| InterruptHandler::instance().interrupt())
}
pub fn instance() -> MutexGuard<'static, InterruptHandler> {
pub(crate) fn instance() -> MutexGuard<'static, InterruptHandler> {
lazy_static! {
static ref INSTANCE: Mutex<InterruptHandler> = Mutex::new(InterruptHandler::new());
}
@ -47,11 +47,11 @@ impl InterruptHandler {
process::exit(130);
}
pub fn block(&mut self) {
pub(crate) fn block(&mut self) {
self.blocks += 1;
}
pub fn unblock(&mut self) {
pub(crate) fn unblock(&mut self) {
if self.blocks == 0 {
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();
function()
}

View File

@ -1,16 +1,16 @@
use crate::common::*;
#[derive(Debug)]
pub struct Justfile<'a> {
pub recipes: BTreeMap<&'a str, Recipe<'a>>,
pub assignments: BTreeMap<&'a str, Expression<'a>>,
pub exports: BTreeSet<&'a str>,
pub aliases: BTreeMap<&'a str, Alias<'a>>,
pub deprecated_equals: bool,
pub(crate) struct Justfile<'a> {
pub(crate) recipes: BTreeMap<&'a str, Recipe<'a>>,
pub(crate) assignments: BTreeMap<&'a str, Expression<'a>>,
pub(crate) exports: BTreeSet<&'a str>,
pub(crate) aliases: BTreeMap<&'a str, Alias<'a>>,
pub(crate) deprecated_equals: bool,
}
impl<'a> Justfile<'a> where {
pub fn first(&self) -> Option<&Recipe> {
pub(crate) fn first(&self) -> Option<&Recipe> {
let mut first: Option<&Recipe> = None;
for recipe in self.recipes.values() {
if let Some(first_recipe) = first {
@ -24,11 +24,11 @@ impl<'a> Justfile<'a> where {
first
}
pub fn count(&self) -> usize {
pub(crate) fn count(&self) -> usize {
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
.recipes
.keys()
@ -43,7 +43,7 @@ impl<'a> Justfile<'a> where {
None
}
pub fn run(
pub(crate) fn run(
&'a self,
invocation_directory: &'a Result<PathBuf, String>,
arguments: &[&'a str],
@ -141,11 +141,11 @@ impl<'a> Justfile<'a> where {
Ok(())
}
pub fn get_alias(&self, name: &str) -> Option<&Alias> {
pub(crate) fn get_alias(&self, name: &str) -> Option<&Alias> {
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) {
Some(recipe)
} else if let Some(alias) = self.aliases.get(name) {

View File

@ -8,7 +8,7 @@ use TokenKind::*;
/// `self.next` points to the next character to be lexed, and
/// the text between `self.token_start` and `self.token_end` contains
/// the current token being lexed.
pub struct Lexer<'a> {
pub(crate) struct Lexer<'a> {
/// Source text
text: &'a str,
/// Char iterator
@ -27,7 +27,7 @@ pub struct Lexer<'a> {
impl<'a> Lexer<'a> {
/// Lex `text`
pub fn lex(text: &str) -> CompilationResult<Vec<Token>> {
pub(crate) fn lex(text: &str) -> CompilationResult<Vec<Token>> {
Lexer::new(text).tokenize()
}

View File

@ -6,7 +6,7 @@ extern crate lazy_static;
mod testing;
#[cfg(fuzzing)]
pub mod fuzzing;
pub(crate) mod fuzzing;
#[macro_use]
mod die;

View File

@ -1,6 +1,6 @@
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() {
Ok(iter) => {
let result: dotenv::Result<BTreeMap<String, String>> = iter.collect();

View File

@ -1,6 +1,6 @@
use crate::common::*;
pub fn show_whitespace(text: &str) -> String {
pub(crate) fn show_whitespace(text: &str) -> String {
text
.chars()
.map(|c| match c {
@ -11,19 +11,19 @@ pub fn show_whitespace(text: &str) -> String {
.collect()
}
pub fn default<T: Default>() -> T {
pub(crate) fn default<T: Default>() -> T {
Default::default()
}
pub fn empty<T, C: iter::FromIterator<T>>() -> C {
pub(crate) fn empty<T, C: iter::FromIterator<T>>() -> C {
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()
}
pub fn maybe_s(n: usize) -> &'static str {
pub(crate) fn maybe_s(n: usize) -> &'static str {
if n == 1 {
""
} 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,
values: &[T],
conjunction: &str,
@ -55,7 +55,7 @@ pub fn conjoin<T: Display>(
Ok(())
}
pub fn write_error_context(
pub(crate) fn write_error_context(
f: &mut Formatter,
text: &str,
offset: usize,
@ -121,7 +121,7 @@ pub fn write_error_context(
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> {
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> {
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> {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {

View File

@ -1,4 +1,4 @@
pub trait Ordinal {
pub(crate) trait Ordinal {
/// Convert an index starting at 0 to an ordinal starting at 1
fn ordinal(self) -> Self;
}

View File

@ -1,7 +1,7 @@
use crate::common::*;
/// 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() {
Ok(output) => {
if let Some(code) = output.status.code() {

View File

@ -1,7 +1,7 @@
use crate::common::*;
#[derive(Debug)]
pub enum OutputError {
pub(crate) enum OutputError {
/// Non-zero exit code
Code(i32),
/// IO error

View File

@ -1,11 +1,11 @@
use crate::common::*;
#[derive(PartialEq, Debug)]
pub struct Parameter<'a> {
pub default: Option<Expression<'a>>,
pub name: &'a str,
pub token: Token<'a>,
pub variadic: bool,
pub(crate) struct Parameter<'a> {
pub(crate) default: Option<Expression<'a>>,
pub(crate) name: &'a str,
pub(crate) token: Token<'a>,
pub(crate) variadic: bool,
}
impl<'a> Display for Parameter<'a> {

View File

@ -3,7 +3,7 @@ use crate::common::*;
use CompilationErrorKind::*;
use TokenKind::*;
pub struct Parser<'a> {
pub(crate) struct Parser<'a> {
text: &'a str,
tokens: itertools::PutBackN<vec::IntoIter<Token<'a>>>,
recipes: BTreeMap<&'a str, Recipe<'a>>,
@ -16,14 +16,14 @@ pub struct 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)?;
tokens.retain(|token| token.kind != Whitespace);
let parser = Parser::new(text, tokens);
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 {
tokens: itertools::put_back_n(tokens),
recipes: empty(),
@ -391,7 +391,7 @@ impl<'a> Parser<'a> {
Ok(())
}
pub fn justfile(mut self) -> CompilationResult<'a, Justfile<'a>> {
pub(crate) fn justfile(mut self) -> CompilationResult<'a, Justfile<'a>> {
let mut doc = None;
loop {
match self.tokens.next() {

View File

@ -1,6 +1,6 @@
use crate::common::*;
pub struct Platform;
pub(crate) struct Platform;
#[cfg(unix)]
impl PlatformInterface for Platform {

View File

@ -1,6 +1,6 @@
use crate::common::*;
pub trait PlatformInterface {
pub(crate) trait PlatformInterface {
/// Construct a command equivalent to running the script at `path` with the
/// shebang line `shebang`
fn make_shebang_command(

View File

@ -1,7 +1,7 @@
/// Source position
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct Position {
pub offset: usize,
pub column: usize,
pub line: usize,
pub(crate) struct Position {
pub(crate) offset: usize,
pub(crate) column: usize,
pub(crate) line: usize,
}

View File

@ -1,6 +1,6 @@
use crate::common::*;
pub trait RangeExt<T> {
pub(crate) trait RangeExt<T> {
fn range_contains(&self, i: &T) -> bool;
}

View File

@ -23,25 +23,25 @@ fn error_from_signal(
}
#[derive(PartialEq, Debug)]
pub struct Recipe<'a> {
pub dependencies: Vec<&'a str>,
pub dependency_tokens: Vec<Token<'a>>,
pub doc: Option<&'a str>,
pub line_number: usize,
pub lines: Vec<Vec<Fragment<'a>>>,
pub name: &'a str,
pub parameters: Vec<Parameter<'a>>,
pub private: bool,
pub quiet: bool,
pub shebang: bool,
pub(crate) struct Recipe<'a> {
pub(crate) dependencies: Vec<&'a str>,
pub(crate) dependency_tokens: Vec<Token<'a>>,
pub(crate) doc: Option<&'a str>,
pub(crate) line_number: usize,
pub(crate) lines: Vec<Vec<Fragment<'a>>>,
pub(crate) name: &'a str,
pub(crate) parameters: Vec<Parameter<'a>>,
pub(crate) private: bool,
pub(crate) quiet: bool,
pub(crate) shebang: bool,
}
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()
}
pub fn min_arguments(&self) -> usize {
pub(crate) fn min_arguments(&self) -> usize {
self
.parameters
.iter()
@ -49,7 +49,7 @@ impl<'a> Recipe<'a> {
.count()
}
pub fn max_arguments(&self) -> usize {
pub(crate) fn max_arguments(&self) -> usize {
if self.parameters.iter().any(|p| p.variadic) {
usize::MAX - 1
} else {
@ -57,7 +57,7 @@ impl<'a> Recipe<'a> {
}
}
pub fn run(
pub(crate) fn run(
&self,
context: &RecipeContext<'a>,
arguments: &[&'a str],

View File

@ -1,7 +1,7 @@
use crate::common::*;
pub struct RecipeContext<'a> {
pub invocation_directory: &'a Result<PathBuf, String>,
pub configuration: &'a Configuration<'a>,
pub scope: BTreeMap<&'a str, String>,
pub(crate) struct RecipeContext<'a> {
pub(crate) invocation_directory: &'a Result<PathBuf, String>,
pub(crate) configuration: &'a Configuration<'a>,
pub(crate) scope: BTreeMap<&'a str, String>,
}

View File

@ -12,7 +12,7 @@ use CompilationErrorKind::*;
// of the struct, and the second being the lifetime of the tokens
// that it contains.
pub struct RecipeResolver<'a: 'b, 'b> {
pub(crate) struct RecipeResolver<'a: 'b, 'b> {
stack: Vec<&'a str>,
seen: BTreeSet<&'a str>,
resolved: BTreeSet<&'a str>,
@ -22,7 +22,7 @@ pub struct RecipeResolver<'a: 'b, 'b> {
}
impl<'a, 'b> RecipeResolver<'a, 'b> {
pub fn resolve_recipes(
pub(crate) fn resolve_recipes(
recipes: &BTreeMap<&'a str, Recipe<'a>>,
assignments: &BTreeMap<&'a str, Expression<'a>>,
text: &'a str,

View File

@ -3,7 +3,7 @@ use crate::common::*;
use crate::misc::{maybe_s, ticks, write_error_context, And, Or, Tick};
#[derive(Debug)]
pub enum RuntimeError<'a> {
pub(crate) enum RuntimeError<'a> {
ArgumentCountMismatch {
recipe: &'a str,
parameters: Vec<&'a Parameter<'a>>,
@ -67,7 +67,7 @@ pub enum RuntimeError<'a> {
}
impl<'a> RuntimeError<'a> {
pub fn code(&self) -> Option<i32> {
pub(crate) fn code(&self) -> Option<i32> {
use RuntimeError::*;
match *self {
Code { code, .. }

View File

@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
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 dir = fs::read_dir(directory).map_err(|io_error| SearchError::Io {
io_error,

View File

@ -2,7 +2,7 @@ use std::{fmt, io, path::PathBuf};
use crate::misc::And;
pub enum SearchError {
pub(crate) enum SearchError {
MultipleCandidates {
candidates: Vec<PathBuf>,
},

View File

@ -1,10 +1,10 @@
pub struct Shebang<'a> {
pub interpreter: &'a str,
pub argument: Option<&'a str>,
pub(crate) struct Shebang<'a> {
pub(crate) interpreter: &'a str,
pub(crate) argument: Option<&'a str>,
}
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("#!") {
return None;
}

View File

@ -1,7 +1,7 @@
use crate::common::*;
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum State<'a> {
pub(crate) enum State<'a> {
Normal,
Indented { indentation: &'a str },
Text,

View File

@ -1,13 +1,13 @@
use crate::common::*;
#[derive(PartialEq, Debug)]
pub struct StringLiteral<'a> {
pub raw: &'a str,
pub cooked: Cow<'a, str>,
pub(crate) struct StringLiteral<'a> {
pub(crate) raw: &'a str,
pub(crate) cooked: Cow<'a, str>,
}
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];
if let TokenKind::StringRaw = token.kind {

View File

@ -1,13 +1,13 @@
use crate::common::*;
pub fn parse(text: &str) -> Justfile {
pub(crate) fn parse(text: &str) -> Justfile {
match Parser::parse(text) {
Ok(justfile) => justfile,
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()
.prefix("just-test-tempdir")
.tempdir()

View File

@ -1,21 +1,21 @@
use crate::common::*;
#[derive(Debug, PartialEq, Clone)]
pub struct Token<'a> {
pub offset: usize,
pub length: usize,
pub line: usize,
pub column: usize,
pub text: &'a str,
pub kind: TokenKind,
pub(crate) struct Token<'a> {
pub(crate) offset: usize,
pub(crate) length: usize,
pub(crate) line: usize,
pub(crate) column: usize,
pub(crate) text: &'a str,
pub(crate) kind: TokenKind,
}
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]
}
pub fn error(&self, kind: CompilationErrorKind<'a>) -> CompilationError<'a> {
pub(crate) fn error(&self, kind: CompilationErrorKind<'a>) -> CompilationError<'a> {
CompilationError {
column: self.column,
offset: self.offset,

View File

@ -1,7 +1,7 @@
use crate::common::*;
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum TokenKind {
pub(crate) enum TokenKind {
At,
Backtick,
Colon,

View File

@ -1,5 +1,5 @@
#[derive(Copy, Clone)]
pub enum UseColor {
pub(crate) enum UseColor {
Auto,
Always,
Never,

View File

@ -1,11 +1,11 @@
use crate::common::*;
pub struct Variables<'a> {
pub(crate) struct Variables<'a> {
stack: Vec<&'a Expression<'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] }
}
}

View File

@ -1,14 +1,14 @@
use Verbosity::*;
#[derive(Copy, Clone)]
pub enum Verbosity {
pub(crate) enum Verbosity {
Taciturn,
Loquacious,
Grandiloquent,
}
impl Verbosity {
pub fn from_flag_occurrences(flag_occurences: u64) -> Verbosity {
pub(crate) fn from_flag_occurrences(flag_occurences: u64) -> Verbosity {
match flag_occurences {
0 => Taciturn,
1 => Loquacious,
@ -16,7 +16,7 @@ impl Verbosity {
}
}
pub fn loquacious(self) -> bool {
pub(crate) fn loquacious(self) -> bool {
match self {
Taciturn => false,
Loquacious => true,
@ -24,7 +24,7 @@ impl Verbosity {
}
}
pub fn grandiloquent(self) -> bool {
pub(crate) fn grandiloquent(self) -> bool {
match self {
Taciturn => false,
Loquacious => false,