Skip to content

Commit

Permalink
Merge branch 'release/v1.1.0-stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
NXVZBGBFBEN committed Mar 31, 2023
2 parents 79fb0e7 + 6c12ccd commit 6263e41
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

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

8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

20 changes: 13 additions & 7 deletions docs/src/manual.tex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
\usepackage{amsmath}
\usepackage{listings}
\usepackage{keystroke}
\usepackage{pagecolor}
\usepackage{graphicx}
\usepackage{geometry}

% Defnitions
\definecolor{MedB}{HTML}{0074f0}
Expand All @@ -23,7 +26,7 @@
% Macros
\newcommand{\MedleyB}[1]{{\textcolor{MedB}{#1}}}
\newcommand{\MedleyLB}[1]{{\textcolor{MedLB}{#1}}}
\newcommand{\medleyver}{1.1.0{-}beta2}
\newcommand{\medleyver}{1.1.0{-}stable}

% Settings
\hypersetup{
Expand All @@ -47,14 +50,17 @@
% Document
\begin{document}
\begin{titlepage}
\ttfamily{{\fontsize{35pt}{0pt}\selectfont
\MedleyB{>} \MedleyLB{Medley}\par\vspace{12pt}
\ \MedleyB{=} \MedleyLB{Calc With \LaTeX{} Syntax}
}}
\pagecolor{black}
\newgeometry{left=0mm, right=0mm}
\begin{figure}[h]
\centering
\includegraphics[scale=1.6]{../../images/repo-card}
\end{figure}
\vfill
\centerline{\rmfamily{{\fontsize{25pt}{0pt}\selectfont
Manual for Version \medleyver}}}
\color{white}{\centerline{\rmfamily{\bfseries{\huge
Manual for Version \medleyver}}}}
\end{titlepage}
\pagecolor{white}
\title{{\Huge\bfseries{Medley}}\\
\LaTeX{}の構文を用いたCLI電卓}
\author{NXVZBGBFBEN\\
Expand Down
Binary file added images/Medley-NX.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Medley-NX.xcf
Binary file not shown.
Binary file added images/Medley.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Medley.xcf
Binary file not shown.
Binary file added images/repo-card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/repo-card.xcf
Binary file not shown.
7 changes: 5 additions & 2 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ impl Lexer {
self.next();
number.push(*self.curr().unwrap());
}
Ok(String::from_iter(number).parse::<f64>().ok().map(Token::Number))
Ok(String::from_iter(number)
.parse::<f64>()
.ok()
.map(Token::Number))
} else if self.curr() == Some(&'\\') {
//コマンドを読み込んだ場合
let mut command = vec![*self.curr().unwrap()];
Expand Down Expand Up @@ -80,4 +83,4 @@ impl Lexer {
fn is_number(c: &char) -> bool {
c.is_ascii_digit() || c == &'.'
}
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod lexer;
pub mod parser;
pub mod parser;
28 changes: 15 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use medley::lexer;
use medley::parser;
use std::borrow::Borrow;
use std::io;
use std::io::Write;
use medley::lexer;
use medley::parser;

fn main() {
println!("This is Medley, Version 1.1.0-beta2 (2023-03-02)");
println!("This is Medley, Version 1.1.0-stable (2023-04-01)");
loop {
print!("> ");
io::stdout().flush().unwrap();
Expand All @@ -22,11 +22,11 @@ fn main() {
if let Some(expr) = parser.parse() {
match eval(expr.borrow()) {
Ok(result) => println!(" = {result}"),
Err(calc_err) => println!(" = [CALC_ERR] {calc_err}")
Err(calc_err) => println!(" = [CALC_ERR] {calc_err}"),
}
}
}
Err(syntax_err) => println!(" = [SYNTAX_ERR] {syntax_err}")
Err(syntax_err) => println!(" = [SYNTAX_ERR] {syntax_err}"),
}
}
Err(input_err) => {
Expand All @@ -52,14 +52,16 @@ fn eval(expr: &parser::Expr) -> Result<f64, String> {
"Plus" => Ok(left + right),
"Minus" => Ok(left - right),
"Times" => Ok(left * right),
"Div" => if left == 0 as f64 && right == 0 as f64 {
Err(String::from("indeterminate (divided by 0)"))
} else if right == 0 as f64 {
Err(String::from("incompatible (divided by 0)"))
} else {
Ok(left / right)
"Div" => {
if left == 0 as f64 && right == 0 as f64 {
Err(String::from("indeterminate (divided by 0)"))
} else if right == 0 as f64 {
Err(String::from("incompatible (divided by 0)"))
} else {
Ok(left / right)
}
}
_ => Err(String::from("invalid operator"))
_ => Err(String::from("invalid operator")),
}
}
parser::Expr::Fraction {
Expand All @@ -77,4 +79,4 @@ fn eval(expr: &parser::Expr) -> Result<f64, String> {
}
}
}
}
}
12 changes: 5 additions & 7 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::mem;
use crate::lexer;
use std::mem;

/*構文木の定義*/
pub enum Expr {
Expand Down Expand Up @@ -164,16 +164,14 @@ impl Parser {
fn peek_precedence(&mut self) -> Precedence {
return match self.peek() {
Some(x) => Self::token_precedence(x.as_ref().unwrap()),
None => Precedence::Lowest
None => Precedence::Lowest,
};
}
//次のトークンが引数として与えられたトークンかどうか判別する
fn discriminant(&mut self, token: &lexer::Token) -> bool {
match self.peek() {
Some(x) => {
mem::discriminant(x.as_ref().unwrap()) == mem::discriminant(token)
}
None => false
Some(x) => mem::discriminant(x.as_ref().unwrap()) == mem::discriminant(token),
None => false,
}
}
fn next(&mut self) {
Expand All @@ -185,4 +183,4 @@ impl Parser {
fn peek(&mut self) -> Option<&Option<lexer::Token>> {
self.token.get(self.position + 1)
}
}
}

0 comments on commit 6263e41

Please sign in to comment.