-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0f3bf1
commit 9209028
Showing
10 changed files
with
148 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters