Skip to content

Commit

Permalink
Reduce all visibilities to be as small as they can be
Browse files Browse the repository at this point in the history
  • Loading branch information
lunacookies committed Oct 7, 2020
1 parent 05bacf4 commit 71a4aba
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/binding_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use crate::expr::Expr;
use crate::utils;

#[derive(Debug, PartialEq)]
pub struct BindingDef {
pub name: String,
pub val: Expr,
pub(crate) struct BindingDef {
pub(crate) name: String,
pub(crate) val: Expr,
}

impl BindingDef {
pub fn new(s: &str) -> Result<(&str, Self), String> {
pub(crate) fn new(s: &str) -> Result<(&str, Self), String> {
let s = utils::tag("let", s)?;
let (s, _) = utils::extract_whitespace1(s)?;

Expand Down
16 changes: 8 additions & 8 deletions src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod binding_usage;
pub mod block;
mod binding_usage;
mod block;

use crate::env::Env;
use crate::utils;
Expand All @@ -8,25 +8,25 @@ use binding_usage::BindingUsage;
use block::Block;

#[derive(Debug, PartialEq)]
pub struct Number(pub i32);
pub(crate) struct Number(pub(crate) i32);

impl Number {
pub fn new(s: &str) -> Result<(&str, Self), String> {
fn new(s: &str) -> Result<(&str, Self), String> {
let (s, number) = utils::extract_digits(s)?;
Ok((s, Self(number.parse().unwrap())))
}
}

#[derive(Debug, PartialEq)]
pub enum Op {
pub(crate) enum Op {
Add,
Sub,
Mul,
Div,
}

impl Op {
pub fn new(s: &str) -> Result<(&str, Self), String> {
fn new(s: &str) -> Result<(&str, Self), String> {
utils::tag("+", s)
.map(|s| (s, Self::Add))
.or_else(|_| utils::tag("-", s).map(|s| (s, Self::Sub)))
Expand All @@ -36,15 +36,15 @@ impl Op {
}

#[derive(Debug, PartialEq)]
pub enum Expr {
pub(crate) enum Expr {
Number(Number),
Operation { lhs: Number, rhs: Number, op: Op },
BindingUsage(BindingUsage),
Block(Block),
}

impl Expr {
pub fn new(s: &str) -> Result<(&str, Self), String> {
pub(crate) fn new(s: &str) -> Result<(&str, Self), String> {
Self::new_operation(s)
.or_else(|_| Self::new_number(s))
.or_else(|_| {
Expand Down
8 changes: 4 additions & 4 deletions src/expr/binding_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use crate::utils;
use crate::val::Val;

#[derive(Debug, PartialEq)]
pub struct BindingUsage {
pub name: String,
pub(crate) struct BindingUsage {
pub(super) name: String,
}

impl BindingUsage {
pub fn new(s: &str) -> Result<(&str, Self), String> {
pub(super) fn new(s: &str) -> Result<(&str, Self), String> {
let (s, name) = utils::extract_ident(s)?;

Ok((
Expand All @@ -19,7 +19,7 @@ impl BindingUsage {
))
}

pub(crate) fn eval(&self, env: &Env) -> Result<Val, String> {
pub(super) fn eval(&self, env: &Env) -> Result<Val, String> {
env.get_binding_value(&self.name)
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/expr/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use crate::utils;
use crate::val::Val;

#[derive(Debug, PartialEq)]
pub struct Block {
pub stmts: Vec<Stmt>,
pub(crate) struct Block {
pub(super) stmts: Vec<Stmt>,
}

impl Block {
pub fn new(s: &str) -> Result<(&str, Self), String> {
pub(super) fn new(s: &str) -> Result<(&str, Self), String> {
let s = utils::tag("{", s)?;
let (s, _) = utils::extract_whitespace(s);

Expand All @@ -30,7 +30,7 @@ impl Block {
Ok((s, Block { stmts }))
}

pub(crate) fn eval(&self, env: &Env) -> Result<Val, String> {
pub(super) fn eval(&self, env: &Env) -> Result<Val, String> {
if self.stmts.is_empty() {
return Ok(Val::Unit);
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod binding_def;
pub mod expr;
pub mod stmt;
pub mod val;
mod binding_def;
mod expr;
mod stmt;
mod val;

mod env;
mod utils;
Expand Down
4 changes: 2 additions & 2 deletions src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use crate::expr::Expr;
use crate::val::Val;

#[derive(Debug, PartialEq)]
pub enum Stmt {
pub(crate) enum Stmt {
BindingDef(BindingDef),
Expr(Expr),
}

impl Stmt {
pub fn new(s: &str) -> Result<(&str, Self), String> {
pub(crate) fn new(s: &str) -> Result<(&str, Self), String> {
BindingDef::new(s)
.map(|(s, binding_def)| (s, Self::BindingDef(binding_def)))
.or_else(|_| Expr::new(s).map(|(s, expr)| (s, Self::Expr(expr))))
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub(crate) fn take_while(accept: impl Fn(char) -> bool, s: &str) -> (&str, &str) {
fn take_while(accept: impl Fn(char) -> bool, s: &str) -> (&str, &str) {
let extracted_end = s
.char_indices()
.find_map(|(idx, c)| if accept(c) { None } else { Some(idx) })
Expand All @@ -9,7 +9,7 @@ pub(crate) fn take_while(accept: impl Fn(char) -> bool, s: &str) -> (&str, &str)
(remainder, extracted)
}

pub(crate) fn take_while1(
fn take_while1(
accept: impl Fn(char) -> bool,
s: &str,
error_msg: String,
Expand Down
2 changes: 1 addition & 1 deletion src/val.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[derive(Debug, Clone, PartialEq)]
pub enum Val {
pub(crate) enum Val {
Number(i32),
Unit,
}

0 comments on commit 71a4aba

Please sign in to comment.