mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-06-23 11:11:23 +02:00
Split it up into two parts: library and cli binary
This commit is contained in:
parent
e30fdf9cc1
commit
36ae7a0b90
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/target
|
||||
*/target
|
||||
lek/Cargo.lock
|
||||
|
@ -11,8 +11,5 @@ panic = "abort"
|
||||
#incremental = false
|
||||
|
||||
[dependencies]
|
||||
rustyline = "6.1.2"
|
||||
phf = { version = "0.8", features = ["macros"] }
|
||||
ansi_term = "0.12"
|
||||
bigdecimal = "0.1.2"
|
||||
rug = "1.9.0"
|
@ -1,4 +1,5 @@
|
||||
use crate::lexer::TokenKind;
|
||||
use crate::parser::Unit;
|
||||
use std::mem;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -19,12 +20,6 @@ pub enum Expr {
|
||||
Literal(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Unit {
|
||||
Radians,
|
||||
Degrees,
|
||||
}
|
||||
|
||||
impl TokenKind {
|
||||
pub fn is_unit(&self) -> bool {
|
||||
match self {
|
@ -1,5 +1,6 @@
|
||||
use crate::ast::{compare_enums, Expr, Stmt, Unit};
|
||||
use crate::ast::{compare_enums, Expr, Stmt};
|
||||
use crate::lexer::TokenKind;
|
||||
use crate::parser::Unit;
|
||||
use crate::prelude;
|
||||
use crate::symbol_table::SymbolTable;
|
||||
use rug::ops::Pow;
|
6
lek/src/lib.rs
Normal file
6
lek/src/lib.rs
Normal file
@ -0,0 +1,6 @@
|
||||
mod ast;
|
||||
mod interpreter;
|
||||
mod lexer;
|
||||
pub mod parser;
|
||||
mod prelude;
|
||||
mod symbol_table;
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
ast::{compare_enums, Expr, Stmt, Unit},
|
||||
ast::{compare_enums, Expr, Stmt},
|
||||
interpreter,
|
||||
lexer::{Lexer, Token, TokenKind},
|
||||
symbol_table::SymbolTable,
|
||||
@ -12,6 +12,11 @@ pub struct Context {
|
||||
pos: usize,
|
||||
symbol_table: SymbolTable,
|
||||
}
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Unit {
|
||||
Radians,
|
||||
Degrees,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new() -> Self {
|
@ -11,7 +11,7 @@ pub const CONSTANTS: phf::Map<&'static str, &'static str> = phf::phf_map! {
|
||||
"ϕ" => "1.61803398",
|
||||
};
|
||||
|
||||
use crate::ast::Unit;
|
||||
use crate::parser::Unit;
|
||||
use funcs::*;
|
||||
pub const UNARY_FUNCS: phf::Map<&'static str, UnaryFuncInfo> = phf::phf_map! {
|
||||
"cos" => UnaryFuncInfo(cos, Trig),
|
||||
@ -161,6 +161,7 @@ mod funcs {
|
||||
pub fn acot(x: Float) -> Float {
|
||||
(1f64 / x).atan()
|
||||
}
|
||||
|
||||
pub fn acoth(x: Float) -> Float {
|
||||
(1f64 / x).atanh()
|
||||
}
|
59
Cargo.lock → lek_cli/Cargo.lock
generated
59
Cargo.lock → lek_cli/Cargo.lock
generated
@ -39,17 +39,6 @@ version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
|
||||
|
||||
[[package]]
|
||||
name = "bigdecimal"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1374191e2dd25f9ae02e3aa95041ed5d747fc77b3c102b49fe2dd9a8117a6244"
|
||||
dependencies = [
|
||||
"num-bigint",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
@ -149,10 +138,16 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
name = "lek"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"bigdecimal",
|
||||
"phf",
|
||||
"rug",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lek_cli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"lek",
|
||||
"rustyline",
|
||||
]
|
||||
|
||||
@ -190,36 +185,6 @@ dependencies = [
|
||||
"void",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf"
|
||||
version = "0.8.0"
|
||||
@ -278,9 +243,9 @@ checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.17"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1502d12e458c49a4c9cbff560d0fe0060c252bc29799ed94ca2ed4bb665a0101"
|
||||
checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
@ -418,9 +383,9 @@ checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.28"
|
||||
version = "1.0.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7e33a62f20d3dc02a1bc9c1d385f92b459bbf35e4dc325eed20c53db5b90c03"
|
||||
checksum = "93a56fabc59dce20fe48b6c832cc249c713e7ed88fa28b0ee0a3bfcaae5fe4e2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
13
lek_cli/Cargo.toml
Normal file
13
lek_cli/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "lek_cli"
|
||||
version = "0.1.0"
|
||||
authors = ["PaddiM8 <paddim8@pm.me>"]
|
||||
edition = "2018"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
|
||||
[dependencies]
|
||||
lek = { path = "../lek" }
|
||||
rustyline = "6.1.2"
|
||||
ansi_term = "0.12"
|
@ -1,16 +1,8 @@
|
||||
use std::{env, process};
|
||||
|
||||
mod ast;
|
||||
mod interpreter;
|
||||
mod lexer;
|
||||
mod parser;
|
||||
mod prelude;
|
||||
mod symbol_table;
|
||||
|
||||
use ansi_term::Colour::{Cyan, Red};
|
||||
use ast::Unit;
|
||||
use lek::parser::{self, Unit};
|
||||
use rustyline::error::ReadlineError;
|
||||
use rustyline::Editor;
|
||||
use std::{env, process};
|
||||
|
||||
fn main() {
|
||||
let mut parser = parser::Context::new();
|
Loading…
x
Reference in New Issue
Block a user