Skip to content

Commit

Permalink
switch from a1_notation to a1
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickomatic committed Oct 25, 2024
1 parent f15fa9c commit 87f8394
Show file tree
Hide file tree
Showing 29 changed files with 92 additions and 120 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version = "0.7.0"
edition = "2021"

[dependencies]
a1_notation = { version = "0.6.2", features = ["serde"] }
a1 = { version = "1.0.1", features = ["serde"] }
chrono = { version = "^0.4.31", features = ["serde"] }
clap = { version = "^4", features = ["derive"] }
colored = "^2.0"
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- i686-unknown-linux-musl
- i686-pc-windows-gnu
- x86\_64-unknown-linux-musl
* Switch from `a1_notation` crate to `a1`

### Bugfixes

Expand Down
5 changes: 2 additions & 3 deletions src/ast/display.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{Ast, Node, NumberSign, VariableValue};
use a1_notation::A1;
use std::fmt;

impl fmt::Display for NumberSign {
Expand Down Expand Up @@ -93,14 +92,14 @@ impl fmt::Display for VariableValue {
Self::Ast(ast) => write!(f, "{ast}"),

Self::ColumnRelative { fill, column } => {
let row_range: A1 = (*fill).into();
let row_range: a1::A1 = (*fill).into();
write!(f, "{}", row_range.with_x(column.x))
}

Self::Row(row) => write!(f, "{row}"),

Self::RowRelative { fill, .. } => {
let row_range: A1 = (*fill).into();
let row_range: a1::A1 = (*fill).into();
write!(f, "{row_range}")
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/ast/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ impl Ast {
/// The idea here is just to keep looping as long as we are making progress eval()ing. Where
/// progress means that `.extract_references()` returns a different, non-empty result each
/// time.
pub(crate) fn eval(
self,
scope: &Scope,
position: Option<a1_notation::Address>,
) -> EvalResult<Self> {
pub(crate) fn eval(self, scope: &Scope, position: Option<a1::Address>) -> EvalResult<Self> {
let mut evaled_ast = self;
let mut last_round_refs = AstReferences::default();

Expand Down Expand Up @@ -43,7 +39,7 @@ impl Ast {
fn resolve_variables(
scope: &Scope,
var_names: ReferencesIter,
position: Option<a1_notation::Address>,
position: Option<a1::Address>,
) -> collections::HashMap<String, Self> {
let mut resolved_vars: Variables = collections::HashMap::default();
for var_name in var_names {
Expand Down
28 changes: 14 additions & 14 deletions src/ast/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ impl From<i32> for Ast {
}
}

impl From<a1_notation::A1> for Ast {
fn from(value: a1_notation::A1) -> Self {
impl From<a1::A1> for Ast {
fn from(value: a1::A1) -> Self {
Node::Reference(value.to_string()).into()
}
}

impl From<a1_notation::Address> for Ast {
fn from(value: a1_notation::Address) -> Self {
impl From<a1::Address> for Ast {
fn from(value: a1::Address) -> Self {
Node::Reference(value.to_string()).into()
}
}

impl From<a1_notation::RangeOrCell> for Ast {
fn from(value: a1_notation::RangeOrCell) -> Self {
impl From<a1::RangeOrCell> for Ast {
fn from(value: a1::RangeOrCell) -> Self {
Node::Reference(value.to_string()).into()
}
}
Expand Down Expand Up @@ -133,20 +133,20 @@ impl From<i32> for Node {
}
}

impl From<a1_notation::A1> for Node {
fn from(value: a1_notation::A1) -> Self {
impl From<a1::A1> for Node {
fn from(value: a1::A1) -> Self {
Self::Reference(value.to_string())
}
}

impl From<a1_notation::Address> for Node {
fn from(value: a1_notation::Address) -> Self {
impl From<a1::Address> for Node {
fn from(value: a1::Address) -> Self {
Self::Reference(value.to_string())
}
}

impl From<a1_notation::RangeOrCell> for Node {
fn from(value: a1_notation::RangeOrCell) -> Self {
impl From<a1::RangeOrCell> for Node {
fn from(value: a1::RangeOrCell) -> Self {
Self::Reference(value.to_string())
}
}
Expand All @@ -156,8 +156,8 @@ mod tests {
use super::*;

#[test]
fn node_from_a1_notation() {
let a1 = a1_notation::new("A1").unwrap();
fn node_from_a1() {
let a1 = a1::new("A1").unwrap();
assert_eq!(Node::reference("A1"), a1.into());
}
}
37 changes: 17 additions & 20 deletions src/ast/variable_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub enum VariableValue {
/// ---
/// foo,[[var=bar]],baz
/// ```
Absolute(a1_notation::Address),
Absolute(a1::Address),

/// If a variable is defined in the code section it will have an AST as a value.
///
Expand All @@ -27,30 +27,27 @@ pub enum VariableValue {
/// ---
/// ![[fill]]foo,[[var=foo]],baz
/// ```
ColumnRelative {
column: a1_notation::Column,
fill: Fill,
},
ColumnRelative { column: a1::Column, fill: Fill },

/// References a row (outside of a fill)
///
/// ```csvpp
/// ---
/// ![[var=foo]]foo,bar,baz
/// ```
Row(a1_notation::Row),
Row(a1::Row),

/// A row within a fill.
///
/// ```csvpp
/// ---
/// ![[var=foo / fill=20]]foo,bar,baz
/// ```
RowRelative { row: a1_notation::Row, fill: Fill },
RowRelative { row: a1::Row, fill: Fill },
}

impl VariableValue {
pub(crate) fn into_ast(self, position: Option<a1_notation::Address>) -> Ast {
pub(crate) fn into_ast(self, position: Option<a1::Address>) -> Ast {
if let Some(position) = position {
match self {
// absolute value, just turn it into a Ast
Expand All @@ -63,32 +60,32 @@ impl VariableValue {
// fill, it's the value at that location. If it's outside the fill
// it's the range that it represents
VariableValue::ColumnRelative { fill, column } => {
let fill_a1: a1_notation::A1 = fill.into();
let fill_a1: a1::A1 = fill.into();

Ast::new(if fill_a1.contains(&position.into()) {
position.with_x(column.x).into()
} else {
let row_range: a1_notation::A1 = fill.into();
let row_range: a1::A1 = fill.into();
row_range.with_x(column.x).into()
})
}

VariableValue::Row(row) => {
let a1: a1_notation::A1 = row.into();
let a1: a1::A1 = row.into();
Ast::new(a1.into())
}

VariableValue::RowRelative { fill, .. } => {
let fill_a1: a1_notation::A1 = fill.into();
let fill_a1: a1::A1 = fill.into();

Ast::new(if fill_a1.contains(&position.into()) {
// we're within the scope (fill) so it's the row we're on
let row_a1: a1_notation::A1 = position.row.into();
let row_a1: a1::A1 = position.row.into();
row_a1.into()
} else {
// we're outside the scope (fill), so it represents the entire
// range contained by it (the scope)
let row_range: a1_notation::A1 = fill.into();
let row_range: a1::A1 = fill.into();
row_range.into()
})
}
Expand All @@ -98,7 +95,7 @@ impl VariableValue {
VariableValue::Absolute(address) => Ast::new(address.into()),
VariableValue::Ast(ast) => ast,
VariableValue::Row(row) => {
let a1: a1_notation::A1 = row.into();
let a1: a1::A1 = row.into();
Ast::new(a1.into())
}
_ => compiler_error(
Expand All @@ -116,23 +113,23 @@ mod tests {
use crate::*;
use std::panic;

fn build_position() -> a1_notation::Address {
a1_notation::Address::new(0, 0)
fn build_position() -> a1::Address {
a1::Address::new(0, 0)
}

#[test]
fn into_ast_absolute_some_position() {
assert_eq!(
VariableValue::Absolute(build_position()).into_ast(Some(build_position())),
a1_notation::cell(0, 0).into()
a1::cell(0, 0).into()
);
}

#[test]
fn into_ast_absolute_none_position() {
assert_eq!(
VariableValue::Absolute(a1_notation::Address::new(0, 0)).into_ast(None),
a1_notation::cell(0, 0).into()
VariableValue::Absolute(a1::Address::new(0, 0)).into_ast(None),
a1::cell(0, 0).into()
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/cell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct Cell {

fn parse_ast(
input: &str,
position: a1_notation::Address,
position: a1::Address,
source_code: &ArcSourceCode,
) -> Result<Option<Ast>> {
Ok(if let Some(without_equals) = input.strip_prefix('=') {
Expand All @@ -50,7 +50,7 @@ fn parse_ast(
impl Cell {
pub(crate) fn parse(
input: &str,
position: a1_notation::Address,
position: a1::Address,
row: &mut Row,
source_code: &ArcSourceCode,
) -> Result<Self> {
Expand Down
2 changes: 1 addition & 1 deletion src/data_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ pub enum DataValidation {
TextIsValidEmail,
TextIsValidUrl,
ValueInList(Vec<Ast>),
ValueInRange(a1_notation::A1),
ValueInRange(a1::A1),
}
4 changes: 2 additions & 2 deletions src/error/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod tests {
fn display_cell_syntax_error() {
let message = Error::CellSyntaxError {
filename: path::PathBuf::from("a_file.csvpp"),
position: a1_notation::Address::new(1, 5),
position: a1::Address::new(1, 5),
parse_error: Box::new(build_parse_error()),
};

Expand Down Expand Up @@ -157,7 +157,7 @@ baz
message: "Error".to_string(),
bad_input: "foo".to_string(),
}),
position: Some(a1_notation::Address::new(2, 2)),
position: Some(a1::Address::new(2, 2)),
};

assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub enum Error {
/// A syntax error in a formula in a cell.
CellSyntaxError {
filename: path::PathBuf,
position: a1_notation::Address,
position: a1::Address,
parse_error: Box<ParseError>,
},

Expand All @@ -47,7 +47,7 @@ pub enum Error {
EvalError {
eval_error: Box<EvalError>,
filename: path::PathBuf,
position: Option<a1_notation::Address>,
position: Option<a1::Address>,
},

/// Google Sheets requires that the `gcloud` CLI tools are installed and configured. If we
Expand Down
4 changes: 2 additions & 2 deletions src/fill/into.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::Fill;
use a1_notation::A1;
use a1::A1;

#[allow(clippy::from_over_into)]
impl Into<A1> for Fill {
fn into(self) -> A1 {
a1_notation::row_range(self.start_row, self.end_row().shift_up(1))
a1::row_range(self.start_row, self.end_row().shift_up(1))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/fill/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! # Fill
//!
use a1_notation::Row;
use a1::Row;
use serde::{Deserialize, Serialize};
use std::cmp;

Expand Down
4 changes: 2 additions & 2 deletions src/parser/ast_lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) struct AstLexer<'a> {
lines: LineNumber,
eof_position: CharOffset,
source_code: ArcSourceCode,
position: Option<a1_notation::Address>,
position: Option<a1::Address>,
}

/// For better or worse the tokens are not mutually exclusive - some of them are subsets of another
Expand Down Expand Up @@ -54,7 +54,7 @@ fn matchers_ordered(tl: &TokenLibrary) -> [&TokenMatcher<Token>; 16] {
impl<'a> AstLexer<'a> {
pub(crate) fn new(
input: &'a str,
position: Option<a1_notation::Address>,
position: Option<a1::Address>,
source_code: ArcSourceCode,
) -> ParseResult<AstLexer<'a>> {
let token_library = TokenLibrary::library();
Expand Down
2 changes: 1 addition & 1 deletion src/parser/ast_lexer/token_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct TokenMatch<'a> {
pub(crate) line_number: LineNumber,
pub(crate) line_offset: CharOffset,
pub(crate) source_code: ArcSourceCode,
pub(crate) position: Option<a1_notation::Address>,
pub(crate) position: Option<a1::Address>,
}

impl TokenMatch<'_> {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/ast_lexer/unknown_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) struct UnknownToken {
pub(crate) line_number: LineNumber,
pub(crate) line_offset: CharOffset,
pub(crate) source_code: ArcSourceCode,
pub(crate) position: Option<a1_notation::Address>,
pub(crate) position: Option<a1::Address>,
}

impl fmt::Display for UnknownToken {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/ast_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'a> AstParser<'a> {
pub(crate) fn parse(
input: &'a str,
single_expr: bool,
position: Option<a1_notation::Address>,
position: Option<a1::Address>,
source_code: ArcSourceCode,
) -> ParseResult<Ast> {
AstParser::new(&AstLexer::new(input, position, source_code)?, single_expr).expr_bp(0)
Expand Down
Loading

0 comments on commit 87f8394

Please sign in to comment.