-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from andrewbaxter/expose-ast
Expose AST in Rust library
- Loading branch information
Showing
17 changed files
with
397 additions
and
220 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "cozo-core-examples" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
cozo = { version = "0.7.6", path = "../cozo-core", default-features = false, features = [ | ||
"rayon", | ||
] } |
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,10 @@ | ||
use cozo::{DbInstance, ScriptMutability}; | ||
|
||
fn main() { | ||
let db = DbInstance::new("mem", "", Default::default()).unwrap(); | ||
let script = "?[a] := a in [1, 2, 3]"; | ||
let result = db | ||
.run_script(script, Default::default(), ScriptMutability::Immutable) | ||
.unwrap(); | ||
println!("{:?}", result); | ||
} |
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,58 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use cozo::{ | ||
data::{ | ||
functions::current_validity, | ||
program::{InputAtom, InputInlineRule, InputInlineRulesOrFixed, InputProgram, Unification}, | ||
symb::PROG_ENTRY, | ||
}, | ||
parse::{CozoScript, ImperativeStmt, ImperativeStmtClause}, | ||
DataValue, DbInstance, Num, ScriptMutability, Symbol, | ||
}; | ||
|
||
fn main() { | ||
let db = DbInstance::new("mem", "", Default::default()).unwrap(); | ||
let sym_a = Symbol::new("a", Default::default()); | ||
let script = CozoScript::Imperative(vec![ImperativeStmt::Program { | ||
prog: ImperativeStmtClause { | ||
prog: InputProgram { | ||
prog: { | ||
let mut p = BTreeMap::new(); | ||
p.insert( | ||
Symbol::new(PROG_ENTRY, Default::default()), | ||
InputInlineRulesOrFixed::Rules { | ||
rules: vec![InputInlineRule { | ||
head: vec![sym_a.clone()], | ||
aggr: vec![None], | ||
body: vec![InputAtom::Unification { | ||
inner: Unification { | ||
binding: sym_a, | ||
expr: cozo::Expr::Const { | ||
val: DataValue::List(vec![ | ||
DataValue::Num(Num::Int(1)), | ||
DataValue::Num(Num::Int(2)), | ||
DataValue::Num(Num::Int(3)), | ||
]), | ||
span: Default::default(), | ||
}, | ||
one_many_unif: true, | ||
span: Default::default(), | ||
}, | ||
}], | ||
span: Default::default(), | ||
}], | ||
}, | ||
); | ||
p | ||
}, | ||
out_opts: Default::default(), | ||
disable_magic_rewrite: false, | ||
}, | ||
store_as: None, | ||
}, | ||
}]); | ||
let result = db | ||
.run_script_ast(script, current_validity(), ScriptMutability::Immutable) | ||
.unwrap(); | ||
println!("{:?}", result); | ||
} |
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,14 @@ | ||
use cozo::{data::functions::current_validity, parse::parse_script, DbInstance, ScriptMutability}; | ||
|
||
fn main() { | ||
let db = DbInstance::new("mem", "", Default::default()).unwrap(); | ||
let script = "?[a] := a in [1, 2, 3]"; | ||
let cur_vld = current_validity(); | ||
let script_ast = | ||
parse_script(script, &Default::default(), &db.get_fixed_rules(), cur_vld).unwrap(); | ||
println!("AST: {:?}", script_ast); | ||
let result = db | ||
.run_script_ast(script_ast, cur_vld, ScriptMutability::Immutable) | ||
.unwrap(); | ||
println!("Result: {:?}", result); | ||
} |
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
Oops, something went wrong.