Commit d797d415 by dongshufeng

chore: Bump

parent c67d0a0d
...@@ -7,7 +7,7 @@ rust-version.workspace = true ...@@ -7,7 +7,7 @@ rust-version.workspace = true
[dependencies] [dependencies]
fnv = "1.0" fnv = "1.0"
nom = "7.1" nom = "8.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
num-traits = "0.2" num-traits = "0.2"
num-complex = "0.4" num-complex = "0.4"
......
...@@ -3,7 +3,7 @@ use fnv::FnvHashMap; ...@@ -3,7 +3,7 @@ use fnv::FnvHashMap;
use ndarray::{Array, Ix1, Ix2, IxDyn}; use ndarray::{Array, Ix1, Ix2, IxDyn};
use num_complex::Complex64; use num_complex::Complex64;
use crate::{CtxProvider, Expr, Operation, Token::*}; use crate::{CtxMaps, Expr, Operation, Token::*};
use crate::{ContextProvider, Error, factorial, FuncEvalError, MyCx, MyF}; use crate::{ContextProvider, Error, factorial, FuncEvalError, MyCx, MyF};
use crate::expr::Context; use crate::expr::Context;
use crate::expr_complex::ContextCx; use crate::expr_complex::ContextCx;
...@@ -13,7 +13,7 @@ use crate::tsfn_basic::*; ...@@ -13,7 +13,7 @@ use crate::tsfn_basic::*;
thread_local!(static DEFAULT_CONTEXT: Context<'static> = Context::new()); thread_local!(static DEFAULT_CONTEXT: Context<'static> = Context::new());
thread_local!(pub static DEFAULT_CONTEXT_TENSOR: ContextTensor<'static> = ContextTensor::new()); thread_local!(pub static DEFAULT_CONTEXT_TENSOR: ContextTensor<'static> = ContextTensor::new());
impl ContextProvider for CtxProvider { impl ContextProvider for CtxMaps {
fn get_var(&self, name: &str) -> Option<f64> { fn get_var(&self, name: &str) -> Option<f64> {
self.var_values.get(name).cloned() self.var_values.get(name).cloned()
} }
......
...@@ -33,7 +33,7 @@ pub enum MyCx { ...@@ -33,7 +33,7 @@ pub enum MyCx {
pub enum ParseError { pub enum ParseError {
/// A token that is not allowed at the given location (contains the location of the offending /// A token that is not allowed at the given location (contains the location of the offending
/// character in the source string). /// character in the source string).
UnexpectedToken(usize), UnexpectedToken(usize, usize),
/// Missing right parentheses at the end of the source string (contains the number of missing /// Missing right parentheses at the end of the source string (contains the number of missing
/// parens). /// parens).
MissingRParen(i32), MissingRParen(i32),
...@@ -44,13 +44,9 @@ pub enum ParseError { ...@@ -44,13 +44,9 @@ pub enum ParseError {
impl Display for ParseError { impl Display for ParseError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self { match *self {
ParseError::UnexpectedToken(i) => write!(f, "Unexpected token at byte {}.", i), ParseError::UnexpectedToken(row, col) => write!(f, "Unexpected char at line: {row} column: {col}"),
ParseError::MissingRParen(i) => write!( ParseError::MissingRParen(i) => write!(f, "Missing {i} right parenthes{}.",
f, if i == 1 { "is" } else { "es" }),
"Missing {} right parenthes{}.",
i,
if i == 1 { "is" } else { "es" }
),
ParseError::MissingArgument => write!(f, "Missing argument at the end of expression."), ParseError::MissingArgument => write!(f, "Missing argument at the end of expression."),
} }
} }
...@@ -59,7 +55,7 @@ impl Display for ParseError { ...@@ -59,7 +55,7 @@ impl Display for ParseError {
impl std::error::Error for ParseError { impl std::error::Error for ParseError {
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
ParseError::UnexpectedToken(_) => "unexpected token", ParseError::UnexpectedToken(_, _) => "unexpected token",
ParseError::MissingRParen(_) => "missing right parenthesis", ParseError::MissingRParen(_) => "missing right parenthesis",
ParseError::MissingArgument => "missing argument", ParseError::MissingArgument => "missing argument",
} }
...@@ -79,7 +75,7 @@ impl Display for FuncEvalError { ...@@ -79,7 +75,7 @@ impl Display for FuncEvalError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self { match *self {
FuncEvalError::UnknownFunction => write!(f, "Unknown function"), FuncEvalError::UnknownFunction => write!(f, "Unknown function"),
FuncEvalError::NumberArgs(i) => write!(f, "Expected {} arguments", i), FuncEvalError::NumberArgs(i) => write!(f, "Expected {i} arguments"),
FuncEvalError::TooFewArguments => write!(f, "Too few arguments"), FuncEvalError::TooFewArguments => write!(f, "Too few arguments"),
FuncEvalError::TooManyArguments => write!(f, "Too many arguments"), FuncEvalError::TooManyArguments => write!(f, "Too many arguments"),
} }
...@@ -134,19 +130,19 @@ impl Display for RPNError { ...@@ -134,19 +130,19 @@ impl Display for RPNError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self { match *self {
RPNError::MismatchedLParen(i) => { RPNError::MismatchedLParen(i) => {
write!(f, "Mismatched left parenthesis at token {}.", i) write!(f, "Mismatched left parenthesis at token {i}.")
} }
RPNError::MismatchedRParen(i) => { RPNError::MismatchedRParen(i) => {
write!(f, "Mismatched right parenthesis at token {}.", i) write!(f, "Mismatched right parenthesis at token {i}.")
} }
RPNError::MismatchedLBracket(i) => { RPNError::MismatchedLBracket(i) => {
write!(f, "Mismatched left blackets at token {}.", i) write!(f, "Mismatched left blackets at token {i}.")
} }
RPNError::MismatchedRBracket(i) => { RPNError::MismatchedRBracket(i) => {
write!(f, "Mismatched right blackets at token {}.", i) write!(f, "Mismatched right blackets at token {i}.")
} }
RPNError::UnexpectedComma(i) => write!(f, "Unexpected comma at token {}", i), RPNError::UnexpectedComma(i) => write!(f, "Unexpected comma at token {i}"),
RPNError::NotEnoughOperands(i) => write!(f, "Missing operands at token {}", i), RPNError::NotEnoughOperands(i) => write!(f, "Missing operands at token {i}"),
RPNError::TooManyOperands => { RPNError::TooManyOperands => {
write!(f, "Too many operands left at the end of expression.") write!(f, "Too many operands left at the end of expression.")
} }
...@@ -306,7 +302,7 @@ pub struct Expr { ...@@ -306,7 +302,7 @@ pub struct Expr {
} }
impl Display for Expr { impl Display for Expr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{:?}", self) write!(f, "{:?}", self)
} }
} }
...@@ -344,22 +340,22 @@ pub trait ContextProvider { ...@@ -344,22 +340,22 @@ pub trait ContextProvider {
} }
} }
pub struct CtxProvider { pub struct CtxMaps {
var_values: HashMap<String, f64>, var_values: HashMap<String, f64>,
var_values_cx: HashMap<String, Complex64>, var_values_cx: HashMap<String, Complex64>,
var_values_tensor: HashMap<String, Array<f64, IxDyn>>, var_values_tensor: HashMap<String, Array<f64, IxDyn>>,
var_values_tensor_cx: HashMap<String, Array<Complex64, IxDyn>>, var_values_tensor_cx: HashMap<String, Array<Complex64, IxDyn>>,
} }
impl Default for CtxProvider { impl Default for CtxMaps {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()
} }
} }
impl CtxProvider { impl CtxMaps {
pub fn new() -> Self { pub fn new() -> Self {
CtxProvider { CtxMaps {
var_values: Default::default(), var_values: Default::default(),
var_values_cx: Default::default(), var_values_cx: Default::default(),
var_values_tensor: Default::default(), var_values_tensor: Default::default(),
...@@ -427,3 +423,4 @@ pub fn parse_exprs(s: &str) -> Option<Vec<(String, Expr)>> { ...@@ -427,3 +423,4 @@ pub fn parse_exprs(s: &str) -> Option<Vec<(String, Expr)>> {
} }
Some(exprs) Some(exprs)
} }
// above should as same as in sparrowzz
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论