Skip to content

Commit

Permalink
feat: Separate CLI and liblykia
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Jan 27, 2024
1 parent b0f3bf1 commit 9209028
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "1"
members = ["server"]
members = ["server", "liblykia", "cli"]

[profile.release]
opt-level = 3
Expand Down
9 changes: 9 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
authors = ["Vedat Can Keklik <[email protected]>"]
name = "lykiadb-shell"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.4.6", features = ["derive"] }
liblykia = { path = "../liblykia" }
13 changes: 13 additions & 0 deletions cli/examples/fib.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Define recursive Fibonacci function
function fib($n) {
if ($n < 2) return $n;
return fib($n - 2) + fib($n - 1);
};

var $start_ly = Time.clock();
print(fib(35) == 9227465);
print("elapsed (user defined):", Time.clock() - $start_ly);

var $start_rs = Time.clock();
print(Benchmark.fib(35) == 9227465);
print("elapsed (native):", Time.clock() - $start_rs);
13 changes: 13 additions & 0 deletions cli/examples/first_sql.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var $i = 5;

var $p = SELECT *, $i as five FROM some_collection
UNION
SELECT *, 6 as six FROM some_other_collection;

var $q = SELECT * FROM users where id != 5;

var $r = SELECT "darkness" as my_old_friend;

print($p);
print($q);
print($r);
20 changes: 20 additions & 0 deletions cli/examples/fn.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function helloWorld ($message) {
print("Hello world!", $message);
{
{
return "and returning from here.";
{
print("inner");
print("inner");
print("inner");
}
print("outer");
print("outer");
print("outer");
}
}
};

for (var $i = 0; $i < 10; $i = $i + 1) {
print(helloWorld("My name is Lykia."));
}
7 changes: 7 additions & 0 deletions cli/examples/scan_err.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Define recursive Fibonacci function
function fib($n) {
if ($n < 2) return $n;
return fib($n - 2) + fib($n - 1);
};

117E
54 changes: 54 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::{fs::File, io::{BufReader, Read}};

use clap::Parser;
use liblykia::Request;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Path to the script to be executed
filename: Option<String>,

#[clap(short, long, default_value = "false")]
print_ast: bool,
}

pub fn init() {
let args = Args::parse();
match args.filename {
Some(filename) => run_file(&filename, args.print_ast),
None => run_repl(),
}
}

fn run_file(filename: &str, print_ast: bool) {
let file = File::open(filename).expect("File couldn't be opened.");

let mut content: String = String::new();

BufReader::new(file)
.read_to_string(&mut content)
.expect("File couldn't be read.");

// send file to server
println!("{:?}", Request::Execute(content));
}

fn run_repl() {
/*println!("REPL mode");
let mut line = String::new();
let mut runtime = Runtime::new(RuntimeMode::Repl);
loop {
print!("lykia > ");
let _ = stdout().flush();
stdin().read_line(&mut line).expect("Invalid input");
if line.is_empty() || line.trim() == ".exit" {
break;
}
// send line to server
line.clear();
}*/
}

fn main() {
init();
}
8 changes: 8 additions & 0 deletions liblykia/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
authors = ["Vedat Can Keklik <[email protected]>"]
name = "liblykia"
version = "0.1.0"
edition = "2021"

[dependencies]
bson = "2.9.0"
11 changes: 11 additions & 0 deletions liblykia/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use bson::Bson;

#[derive(Debug, Clone)]
pub enum Request {
Execute(String),
}

#[derive(Debug, Clone)]
pub enum Response {
Execute(Bson),
}
15 changes: 12 additions & 3 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ name = "lykiadb-server"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
liblykia = { path = "../liblykia" }
bumpalo = "3.12.2"
clap = { version = "4.4.6", features = ["derive"] }
phf = { version = "0.11", default-features = false, features = ["macros"] }
rustc-hash = "1.1.0"
serde = { version = "1.0.188", features=["derive", "rc"] }
serde_json = "1.0.105"
ariadne = { features = ["auto-color"] }
assert-json-diff = "2.0.2"
tokio = { version = "~1.35.1", features = [
"macros",
"rt",
"rt-multi-thread",
"net",
"io-util",
"time",
"sync",
] }

tokio-stream = { version = "~0.1.6", features = ["net"] }

[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }
Expand Down

0 comments on commit 9209028

Please sign in to comment.