-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 63 commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
e15907e
add logical side of schema
yliang412 a15bff4
add and impl RelationChildren and ScalarChildren traits
yliang412 e30b2c9
create sequence
yliang412 c5ec6cb
Merge branch 'main' into yuchen/initial-storage
yliang412 5aaeefc
Add doc of rule engine
AlSchlo e49b7a6
Be more specific about rule application WITH
AlSchlo 92a3546
Fix indentation error
AlSchlo 639c6f3
Fix again
AlSchlo 134dd04
Add new IR and update doc
AlSchlo 893ae2d
Add more details to doc and refine IR
AlSchlo 66b43d7
Refine IR
AlSchlo 69ca1a0
Update docs
AlSchlo 5d22cde
Remove mention of tree
AlSchlo df9e9db
Make doc consistent again
AlSchlo 54b47fb
Reorg dir
AlSchlo b3156eb
Add missing fules
AlSchlo 2f00009
add basic apis
yliang412 3eff602
Reorg more code
AlSchlo 4d6e33d
Add missing files
AlSchlo 5c7a5cd
Add transformers
AlSchlo 0caffcc
Add actions doc
AlSchlo 00be567
use trigger to merge groups
yliang412 e999f62
Add analyzer doc
AlSchlo d49cb8b
Add more docs
AlSchlo 9a88281
Rename cascades into alexis_stuff to allow for cascades subdir
AlSchlo eaf06c9
Reorg repo structure
AlSchlo abc0397
Add missing files
AlSchlo b9578a1
Refactor types
AlSchlo fc9b050
add scalar stuff
yliang412 8bad99c
fix projects operator
yliang412 d8e228e
Partial merge
AlSchlo b069d2e
The mother of merges
AlSchlo 0ca88dd
Fix horrible Json bug
AlSchlo f160dce
Update migration
AlSchlo 7e2663d
Start implementation of engine interpreter
AlSchlo d9a4cd1
add test utilities
yliang412 178fb97
fix scalar_adds foreign key
yliang412 64c852b
Latest demo test
AlSchlo fc36f2f
Refactor and comment operators dir
AlSchlo 92a3c65
Refactor and comment plans dir
AlSchlo e75fc9b
Refactor and comment values dir
AlSchlo 270d61a
Fix engine/actions & engine/patterns dirs
AlSchlo f24c089
Add missing files
AlSchlo 59f7a6b
Cleanup ingestion function
AlSchlo c10166e
First grammar versions
AlSchlo dca2537
Fix grammar a bit
AlSchlo f8e777a
Fix more bugs
AlSchlo 0d370ad
First version of grammar
AlSchlo e76e573
Finish grammar
AlSchlo 027de75
Remove old code
AlSchlo 26227d7
Make braces optional in def
AlSchlo c75e6bb
Substantially improve the grammar for operators
AlSchlo db078c6
Fix missing newline
AlSchlo 06a7075
Fix matching and constructor grammar
AlSchlo 1caa03e
Add missing files
AlSchlo b899699
Finish parser
AlSchlo 3173aed
Heavy refactor & add tests
AlSchlo 3d87b42
Merge with main
AlSchlo 22e7197
Remove dangling print statement
AlSchlo 591f4c3
Fix clippy
AlSchlo c5bcfa5
Remove duplicate literal
AlSchlo 52d4157
Add comment
AlSchlo 14348e4
Fix flaky cascades test to run in memory
AlSchlo 9b66b85
Fix some grammar bugs and start semantic analysis
AlSchlo b45654d
Fix clippy
AlSchlo cfb02bd
Remove analyzer
AlSchlo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 @@ | ||
pub mod parser; |
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,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] | ||
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.