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: DSL parser + AST implementation #23

Merged
merged 66 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
e15907e
add logical side of schema
yliang412 Jan 30, 2025
a15bff4
add and impl RelationChildren and ScalarChildren traits
yliang412 Jan 30, 2025
e30b2c9
create sequence
yliang412 Jan 31, 2025
c5ec6cb
Merge branch 'main' into yuchen/initial-storage
yliang412 Feb 1, 2025
5aaeefc
Add doc of rule engine
AlSchlo Feb 2, 2025
e49b7a6
Be more specific about rule application WITH
AlSchlo Feb 2, 2025
92a3546
Fix indentation error
AlSchlo Feb 2, 2025
639c6f3
Fix again
AlSchlo Feb 2, 2025
134dd04
Add new IR and update doc
AlSchlo Feb 2, 2025
893ae2d
Add more details to doc and refine IR
AlSchlo Feb 2, 2025
66b43d7
Refine IR
AlSchlo Feb 2, 2025
69ca1a0
Update docs
AlSchlo Feb 2, 2025
5d22cde
Remove mention of tree
AlSchlo Feb 2, 2025
df9e9db
Make doc consistent again
AlSchlo Feb 2, 2025
54b47fb
Reorg dir
AlSchlo Feb 2, 2025
b3156eb
Add missing fules
AlSchlo Feb 2, 2025
2f00009
add basic apis
yliang412 Feb 3, 2025
3eff602
Reorg more code
AlSchlo Feb 3, 2025
4d6e33d
Add missing files
AlSchlo Feb 3, 2025
5c7a5cd
Add transformers
AlSchlo Feb 3, 2025
0caffcc
Add actions doc
AlSchlo Feb 3, 2025
00be567
use trigger to merge groups
yliang412 Feb 3, 2025
e999f62
Add analyzer doc
AlSchlo Feb 3, 2025
d49cb8b
Add more docs
AlSchlo Feb 3, 2025
9a88281
Rename cascades into alexis_stuff to allow for cascades subdir
AlSchlo Feb 3, 2025
eaf06c9
Reorg repo structure
AlSchlo Feb 3, 2025
abc0397
Add missing files
AlSchlo Feb 3, 2025
b9578a1
Refactor types
AlSchlo Feb 3, 2025
fc9b050
add scalar stuff
yliang412 Feb 3, 2025
8bad99c
fix projects operator
yliang412 Feb 3, 2025
d8e228e
Partial merge
AlSchlo Feb 3, 2025
b069d2e
The mother of merges
AlSchlo Feb 4, 2025
0ca88dd
Fix horrible Json bug
AlSchlo Feb 4, 2025
f160dce
Update migration
AlSchlo Feb 4, 2025
7e2663d
Start implementation of engine interpreter
AlSchlo Feb 4, 2025
d9a4cd1
add test utilities
yliang412 Feb 4, 2025
178fb97
fix scalar_adds foreign key
yliang412 Feb 4, 2025
64c852b
Latest demo test
AlSchlo Feb 4, 2025
fc36f2f
Refactor and comment operators dir
AlSchlo Feb 5, 2025
92a3c65
Refactor and comment plans dir
AlSchlo Feb 5, 2025
e75fc9b
Refactor and comment values dir
AlSchlo Feb 5, 2025
270d61a
Fix engine/actions & engine/patterns dirs
AlSchlo Feb 5, 2025
f24c089
Add missing files
AlSchlo Feb 5, 2025
59f7a6b
Cleanup ingestion function
AlSchlo Feb 5, 2025
c10166e
First grammar versions
AlSchlo Feb 8, 2025
dca2537
Fix grammar a bit
AlSchlo Feb 8, 2025
f8e777a
Fix more bugs
AlSchlo Feb 8, 2025
0d370ad
First version of grammar
AlSchlo Feb 8, 2025
e76e573
Finish grammar
AlSchlo Feb 8, 2025
027de75
Remove old code
AlSchlo Feb 8, 2025
26227d7
Make braces optional in def
AlSchlo Feb 8, 2025
c75e6bb
Substantially improve the grammar for operators
AlSchlo Feb 8, 2025
db078c6
Fix missing newline
AlSchlo Feb 8, 2025
06a7075
Fix matching and constructor grammar
AlSchlo Feb 8, 2025
1caa03e
Add missing files
AlSchlo Feb 8, 2025
b899699
Finish parser
AlSchlo Feb 9, 2025
3173aed
Heavy refactor & add tests
AlSchlo Feb 10, 2025
3d87b42
Merge with main
AlSchlo Feb 10, 2025
22e7197
Remove dangling print statement
AlSchlo Feb 10, 2025
591f4c3
Fix clippy
AlSchlo Feb 10, 2025
c5bcfa5
Remove duplicate literal
AlSchlo Feb 10, 2025
52d4157
Add comment
AlSchlo Feb 10, 2025
14348e4
Fix flaky cascades test to run in memory
AlSchlo Feb 10, 2025
9b66b85
Fix some grammar bugs and start semantic analysis
AlSchlo Feb 11, 2025
b45654d
Fix clippy
AlSchlo Feb 11, 2025
cfb02bd
Remove analyzer
AlSchlo Feb 11, 2025
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
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions optd-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1", features = ["raw_value"] }
dotenvy = "0.15"
async-recursion = "1.1.1"
pest = "2.7.15"
pest_derive = "2.7.15"
2 changes: 1 addition & 1 deletion optd-core/src/cascades/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mod tests {

#[tokio::test]
async fn test_ingest_partial_logical_plan() -> anyhow::Result<()> {
let memo = SqliteMemo::new("sqlite://memo.db").await?;
let memo = SqliteMemo::new_in_memory().await?;
// select * from t1, t2 where t1.id = t2.id and t2.name = 'Memo' and t2.v1 = 1 + 1
let partial_logical_plan = filter(
join(
Expand Down
1 change: 1 addition & 0 deletions optd-core/src/dsl/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod parser;
151 changes: 151 additions & 0 deletions optd-core/src/dsl/parser/ast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
use std::collections::HashMap;

/// Types supported by the language
#[derive(Debug, Clone, PartialEq)]
pub enum Type {
Int64,
String,
Bool,
Float64,
Array(Box<Type>), // Array types like [T]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remember to change these to rust comments.

Map(Box<Type>, Box<Type>), // Map types like map[K->V]
Tuple(Vec<Type>), // Tuple types like (T1, T2)
Function(Box<Type>, Box<Type>), // Function types like (T1)->T2
Operator(OperatorKind), // Operator types (scalar/logical)
}

/// Kinds of operators supported in the language
#[derive(Debug, Clone, PartialEq)]
pub enum OperatorKind {
Scalar, // Scalar operators
Logical, // Logical operators with derivable properties
}

/// A field in an operator or properties block
#[derive(Debug, Clone)]
pub struct Field {
pub name: String,
pub ty: Type,
}

/// Logical properties block that must appear exactly once per file
#[derive(Debug, Clone)]
pub struct Properties {
pub fields: Vec<Field>,
}

/// Top-level operator definition
#[derive(Debug, Clone)]
pub enum Operator {
Scalar(ScalarOp),
Logical(LogicalOp),
}

/// Scalar operator definition
#[derive(Debug, Clone)]
pub struct ScalarOp {
pub name: String,
pub fields: Vec<Field>,
}

/// Logical operator definition with derived properties
#[derive(Debug, Clone)]
pub struct LogicalOp {
pub name: String,
pub fields: Vec<Field>,
pub derived_props: HashMap<String, Expr>, // Maps property names to their derivation expressions
}

/// Patterns used in match expressions
#[derive(Debug, Clone)]
pub enum Pattern {
Bind(String, Box<Pattern>), // Binding patterns like x@p or x:p
Constructor(
String, // Constructor name
Vec<Pattern>, // Subpatterns, can be named (x:p) or positional
),
Literal(Literal), // Literal patterns like 42 or "hello"
Wildcard, // Wildcard pattern _
Var(String), // Variable binding pattern
}

/// Literal values
#[derive(Debug, Clone)]
pub enum Literal {
Int64(i64),
String(String),
Bool(bool),
Float64(f64),
Array(Vec<Expr>), // Array literals [e1, e2, ...]
Tuple(Vec<Expr>), // Tuple literals (e1, e2, ...)
}

/// Expressions - the core of the language
#[derive(Debug, Clone)]
pub enum Expr {
Match(Box<Expr>, Vec<MatchArm>), // Pattern matching
If(Box<Expr>, Box<Expr>, Box<Expr>), // If-then-else
Val(String, Box<Expr>, Box<Expr>), // Local binding (val x = e1; e2)
Constructor(String, Vec<Expr>), // Constructor application (currently only operators)
Binary(Box<Expr>, BinOp, Box<Expr>), // Binary operations
Unary(UnaryOp, Box<Expr>), // Unary operations
Call(Box<Expr>, Vec<Expr>), // Function application
Member(Box<Expr>, String), // Field access (e.f)
MemberCall(Box<Expr>, String, Vec<Expr>), // Method call (e.f(args))
ArrayIndex(Box<Expr>, Box<Expr>), // Array indexing (e[i])
Var(String), // Variable reference
Literal(Literal), // Literal values
Fail(String), // Failure with message
Closure(Vec<String>, Box<Expr>), // Anonymous functions v = (x, y) => x + y;
}

/// A case in a match expression
#[derive(Debug, Clone)]
pub struct MatchArm {
pub pattern: Pattern,
pub expr: Expr,
}

/// Binary operators with fixed precedence
#[derive(Debug, Clone)]
pub enum BinOp {
Add, // +
Sub, // -
Mul, // *
Div, // /
Concat, // ++
Eq, // ==
Neq, // !=
Gt, // >
Lt, // <
Ge, // >=
Le, // <=
And, // &&
Or, // ||
Range, // ..
}

/// Unary operators
#[derive(Debug, Clone)]
pub enum UnaryOp {
Neg, // -
Not, // !
}

/// Function definition
#[derive(Debug, Clone)]
pub struct Function {
pub name: String,
pub params: Vec<(String, Type)>, // Parameter name and type pairs
pub return_type: Type,
pub body: Expr,
pub rule_type: Option<OperatorKind>, // Some if this is a rule, indicating what kind
}

/// A complete source file
#[derive(Debug, Clone)]
pub struct File {
pub properties: Properties, // The single logical properties block
pub operators: Vec<Operator>, // All operator definitions
pub functions: Vec<Function>, // All function definitions
}
Loading