Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Major changes to AST, parsing, SQL parsing, module structure #14

Merged
merged 30 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8c07dd6
fix: JSON for visualization
can-keklik Dec 4, 2023
91d55ee
fix: Parser tests
can-keklik Dec 4, 2023
c3a8b92
fix: More test cases
can-keklik Dec 4, 2023
d795c73
Merge branch 'main' of https://github.com/lykia-rs/lang into feature/…
can-keklik Dec 5, 2023
1f281a8
fix: Revised AST
can-keklik Dec 5, 2023
daea92c
fix: Bugs
can-keklik Dec 5, 2023
eca1eb9
fix: Error range
can-keklik Dec 5, 2023
dc8ea59
fix: Default fn for Span
can-keklik Dec 6, 2023
405f721
fix: Refactored Spans
can-keklik Dec 7, 2023
364206f
Merge branch 'main' of https://github.com/lykia-rs/lang into feature/…
can-keklik Dec 7, 2023
66d1889
feat: Merged spans
can-keklik Dec 7, 2023
49add2b
feat: SQL order by
can-keklik Dec 7, 2023
79dcaa0
feat: Separate Literal enum
can-keklik Dec 7, 2023
e42da8a
feat: Workspace structure
can-keklik Dec 8, 2023
76ecc17
feat: GROUP BY + HAVING clauses
can-keklik Dec 9, 2023
927c252
feat: LIMIT and OFFSET
can-keklik Dec 9, 2023
47f4389
chor: Roadmap changed
can-keklik Dec 10, 2023
a08babd
chore: Roadmap changed
can-keklik Dec 10, 2023
a41411a
Merge branch 'feature/parsing-tests' of https://github.com/lykia-rs/l…
can-keklik Dec 10, 2023
76ce193
feat: Object literals
can-keklik Dec 10, 2023
7a16b04
feat: Array literals
can-keklik Dec 10, 2023
750c8ae
fix: Table -> Collection
can-keklik Dec 10, 2023
d4f16a0
feat: Minimal standard library
can-keklik Dec 10, 2023
4677039
chore: README change
can-keklik Dec 11, 2023
9eaefe7
chore: README change
can-keklik Dec 11, 2023
8f6c680
fix: Set expressions
can-keklik Dec 13, 2023
23e5eca
Merge branch 'feature/parsing-tests' of https://github.com/lykia-rs/l…
can-keklik Dec 13, 2023
018f64d
fix: More idiomatic scanning
can-keklik Dec 16, 2023
13a6e35
fix: Tests passing
can-keklik Dec 16, 2023
972b612
fix: Lint
can-keklik Dec 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 5 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
[package]
name = "lykia"
version = "0.1.0"
edition = "2021"

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

[dependencies]
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"] }
serde_json = "1.0.105"
ariadne = { features = ["auto-color"] }
[workspace]
resolver = "1"
members = ["server"]

[profile.release]
debug = true

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

[[bench]]
name = "interpreter"
harness = false
opt-level = 3
strip = "debuginfo"
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Lykia is a toy document database basically written for educational purposes. It

## Overview
- Written in Rust
- A weird scripting and query language, combination of PHP and SQL. Built based on the language "Lox" which is explained in the famous book, Crafting Interpreters.
- A weird scripting and query language, combination of JavaScript and SQL. Built based on the language "Lox" which is explained in the famous book, Crafting Interpreters.
- A subset of JSON data types in both scripting language itself and storage
- In-disk and in-memory storage
- ACID compliance
Expand All @@ -19,9 +19,11 @@ Lykia is a toy document database basically written for educational purposes. It
## Roadmap

- [x] Core scripting language
- [ ] A minimal standard library (in progress)
- [ ] SQL parsing (in progress)
- [x] A minimal standard library
- [x] SQL "SELECT" statements parsing
- [ ] Rest of the SQL syntax
- [ ] Query planning
- [ ] Plan optimization
- [ ] Async runtime/event loop
- [ ] In-memory storage engine
- [ ] Persistent storage engine (Bitcask)
Expand All @@ -40,7 +42,7 @@ $ cargo run
Alternatively, you can run a Lykia script by passing its name as the first argument.

```shell
$ cargo run examples/fib.ly
$ cargo run server/examples/fib.ly
```

## License
Expand Down
13 changes: 0 additions & 13 deletions examples/fib.ly

This file was deleted.

24 changes: 24 additions & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
authors = ["Vedat Can Keklik <[email protected]>"]
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]
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"] }
serde_json = "1.0.105"
ariadne = { features = ["auto-color"] }
assert-json-diff = "2.0.2"

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

[[bench]]
name = "interpreter"
harness = false
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions server/examples/fib.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Define recursive Fibonacci function
fun 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);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
132 changes: 132 additions & 0 deletions server/src/lang/ast/expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
use std::rc::Rc;

use super::{sql::SqlSelect, stmt::StmtId, Literal};
use crate::lang::token::{Span, Spanned, Token, TokenType};

#[derive(Debug, Eq, PartialEq)]
pub enum Expr {
Select {
query: SqlSelect,
span: Span,
},
Variable {
name: Token,
span: Span,
},
Grouping {
expr: ExprId,
span: Span,
},
Literal {
value: Literal,
raw: String,
span: Span,
},
Function {
name: Option<Token>,
parameters: Vec<Token>,
body: Rc<Vec<StmtId>>,
span: Span,
},
Binary {
left: ExprId,
symbol: TokenType,
right: ExprId,
span: Span,
},
Unary {
symbol: TokenType,
expr: ExprId,
span: Span,
},
Assignment {
dst: Token,
expr: ExprId,
span: Span,
},
Logical {
left: ExprId,
symbol: TokenType,
right: ExprId,
span: Span,
},
Call {
callee: ExprId,
args: Vec<ExprId>,
span: Span,
},
Get {
object: ExprId,
name: Token,
span: Span,
},
Set {
object: ExprId,
name: Token,
value: ExprId,
span: Span,
},
}

impl Spanned for Expr {
fn get_span(&self) -> Span {
match self {
Expr::Select { query: _, span }
| Expr::Variable { name: _, span }
| Expr::Grouping { expr: _, span }
| Expr::Literal {
value: _,
raw: _,
span,
}
| Expr::Function {
name: _,
parameters: _,
body: _,
span,
}
| Expr::Binary {
left: _,
symbol: _,
right: _,
span,
}
| Expr::Unary {
symbol: _,
expr: _,
span,
}
| Expr::Assignment {
dst: _,
expr: _,
span,
}
| Expr::Logical {
left: _,
symbol: _,
right: _,
span,
}
| Expr::Call {
callee: _,
args: _,
span,
}
| Expr::Get {
object: _,
name: _,
span,
}
| Expr::Set {
object: _,
name: _,
value: _,
span,
} => *span,
}
}
}

#[repr(transparent)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct ExprId(pub usize);
19 changes: 18 additions & 1 deletion src/lang/ast/mod.rs → server/src/lang/ast/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
use std::rc::Rc;

use rustc_hash::FxHashMap;

use self::{
expr::{Expr, ExprId},
stmt::{Stmt, StmtId},
};

pub mod expr;
pub mod sql;
pub mod stmt;

#[derive(Debug, Clone, PartialEq)]
pub enum Literal {
Str(Rc<String>),
Num(f64),
Bool(bool),
Undefined,
Object(FxHashMap<String, ExprId>),
Array(Vec<ExprId>),
NaN,
Null,
}

impl Eq for Literal {}

pub trait Visitor<T, Q> {
fn visit_expr(&mut self, e: ExprId) -> Result<T, Q>;
fn visit_stmt(&mut self, e: StmtId) -> Result<T, Q>;
Expand Down
Loading
Loading