Split it up into two parts: library and cli binary

This commit is contained in:
PaddiM8 2020-06-04 18:19:48 +02:00
parent e30fdf9cc1
commit 36ae7a0b90
12 changed files with 46 additions and 70 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
/target */target
lek/Cargo.lock

View File

@ -11,8 +11,5 @@ panic = "abort"
#incremental = false #incremental = false
[dependencies] [dependencies]
rustyline = "6.1.2"
phf = { version = "0.8", features = ["macros"] } phf = { version = "0.8", features = ["macros"] }
ansi_term = "0.12"
bigdecimal = "0.1.2"
rug = "1.9.0" rug = "1.9.0"

View File

@ -1,4 +1,5 @@
use crate::lexer::TokenKind; use crate::lexer::TokenKind;
use crate::parser::Unit;
use std::mem; use std::mem;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -19,12 +20,6 @@ pub enum Expr {
Literal(String), Literal(String),
} }
#[derive(Debug, Clone)]
pub enum Unit {
Radians,
Degrees,
}
impl TokenKind { impl TokenKind {
pub fn is_unit(&self) -> bool { pub fn is_unit(&self) -> bool {
match self { match self {

View File

@ -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::lexer::TokenKind;
use crate::parser::Unit;
use crate::prelude; use crate::prelude;
use crate::symbol_table::SymbolTable; use crate::symbol_table::SymbolTable;
use rug::ops::Pow; use rug::ops::Pow;

6
lek/src/lib.rs Normal file
View File

@ -0,0 +1,6 @@
mod ast;
mod interpreter;
mod lexer;
pub mod parser;
mod prelude;
mod symbol_table;

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
ast::{compare_enums, Expr, Stmt, Unit}, ast::{compare_enums, Expr, Stmt},
interpreter, interpreter,
lexer::{Lexer, Token, TokenKind}, lexer::{Lexer, Token, TokenKind},
symbol_table::SymbolTable, symbol_table::SymbolTable,
@ -12,6 +12,11 @@ pub struct Context {
pos: usize, pos: usize,
symbol_table: SymbolTable, symbol_table: SymbolTable,
} }
#[derive(Debug, Clone)]
pub enum Unit {
Radians,
Degrees,
}
impl Context { impl Context {
pub fn new() -> Self { pub fn new() -> Self {

View File

@ -11,7 +11,7 @@ pub const CONSTANTS: phf::Map<&'static str, &'static str> = phf::phf_map! {
"ϕ" => "1.61803398", "ϕ" => "1.61803398",
}; };
use crate::ast::Unit; use crate::parser::Unit;
use funcs::*; use funcs::*;
pub const UNARY_FUNCS: phf::Map<&'static str, UnaryFuncInfo> = phf::phf_map! { pub const UNARY_FUNCS: phf::Map<&'static str, UnaryFuncInfo> = phf::phf_map! {
"cos" => UnaryFuncInfo(cos, Trig), "cos" => UnaryFuncInfo(cos, Trig),
@ -161,6 +161,7 @@ mod funcs {
pub fn acot(x: Float) -> Float { pub fn acot(x: Float) -> Float {
(1f64 / x).atan() (1f64 / x).atan()
} }
pub fn acoth(x: Float) -> Float { pub fn acoth(x: Float) -> Float {
(1f64 / x).atanh() (1f64 / x).atanh()
} }

View File

@ -39,17 +39,6 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" 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]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.2.1" version = "1.2.1"
@ -149,10 +138,16 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
name = "lek" name = "lek"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ansi_term",
"bigdecimal",
"phf", "phf",
"rug", "rug",
]
[[package]]
name = "lek_cli"
version = "0.1.0"
dependencies = [
"ansi_term",
"lek",
"rustyline", "rustyline",
] ]
@ -190,36 +185,6 @@ dependencies = [
"void", "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]] [[package]]
name = "phf" name = "phf"
version = "0.8.0" version = "0.8.0"
@ -278,9 +243,9 @@ checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.17" version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1502d12e458c49a4c9cbff560d0fe0060c252bc29799ed94ca2ed4bb665a0101" checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid",
] ]
@ -418,9 +383,9 @@ checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.28" version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7e33a62f20d3dc02a1bc9c1d385f92b459bbf35e4dc325eed20c53db5b90c03" checksum = "93a56fabc59dce20fe48b6c832cc249c713e7ed88fa28b0ee0a3bfcaae5fe4e2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

13
lek_cli/Cargo.toml Normal file
View 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"

View File

@ -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 ansi_term::Colour::{Cyan, Red};
use ast::Unit; use lek::parser::{self, Unit};
use rustyline::error::ReadlineError; use rustyline::error::ReadlineError;
use rustyline::Editor; use rustyline::Editor;
use std::{env, process};
fn main() { fn main() {
let mut parser = parser::Context::new(); let mut parser = parser::Context::new();