pub struct Program { /* private fields */ }Implementations§
Source§impl Program
impl Program
pub fn new(details: ProgramDetails, bytecode: CelByteCode) -> Program
Sourcepub fn from_source(source: &str) -> CelResult<Program>
pub fn from_source(source: &str) -> CelResult<Program>
Examples found in repository?
examples/dumps_bc.rs (line 11)
4fn main() {
5 let args = env::args().collect::<Vec<_>>();
6
7 if args.len() < 2 {
8 panic!("No program passed")
9 }
10
11 let p = Program::from_source(&args[1]).expect("Failed to compile program");
12 for bc in p.bytecode().iter() {
13 println!("{:?}", bc);
14 }
15}More examples
examples/dumps_ast.rs (line 14)
6fn main() {
7 let args: Vec<_> = std::env::args().collect();
8
9 if args.len() < 2 {
10 eprintln!("Usage: {} <prog>", args[0]);
11 return;
12 }
13
14 let prog = rscel::Program::from_source(&args[1]).expect("Failed to compile");
15 let ast = prog.details().ast().unwrap();
16
17 AstDumper::with_source(&args[1]).dump_expr_node(ast, 0);
18}examples/explain.rs (line 51)
37fn main() {
38 let args: Vec<_> = std::env::args().collect();
39
40 if args.len() < 2 {
41 eprintln!("Usage: {} <prog> [bindings]", args[0]);
42 return;
43 }
44
45 let bindings: serde_json::Value = if args.len() == 3 {
46 serde_json::from_str(&args[2]).expect("Failed to parse bindings")
47 } else {
48 serde_json::from_str::<serde_json::Value>("{}").unwrap()
49 };
50
51 let prog = rscel::Program::from_source(&args[1]).expect("Failed to compile");
52 let ast = prog.details().ast().unwrap();
53
54 let dumper = AstDumper::new();
55 let tree = dumper.dump_expr_node(ast);
56
57 let mut queue = Vec::new();
58 queue.push((tree, 0));
59
60 while !queue.is_empty() {
61 let (curr_node, depth) = queue.pop().expect("wut");
62
63 // for now only handle one line
64 let range = curr_node.range();
65
66 let start = range.start().col();
67 let end = range.end().col();
68
69 let src = &args[1][start..end];
70
71 print!("{}{} => ", " ".to_owned().repeat(depth), src);
72 match eval(src, &bindings) {
73 Ok(val) => println!("{}", val),
74 Err(err) => println!("err: {}", err),
75 }
76
77 for node in curr_node.into_children().into_iter().rev() {
78 if node.range() != range {
79 queue.push((node, depth + 1));
80 }
81 }
82 }
83}pub fn params<'a>(&'a self) -> Vec<&'a str>
pub fn source<'a>(&'a self) -> Option<&'a str>
pub fn into_details(self) -> ProgramDetails
Sourcepub fn details<'a>(&'a self) -> &'a ProgramDetails
pub fn details<'a>(&'a self) -> &'a ProgramDetails
Examples found in repository?
examples/dumps_ast.rs (line 15)
6fn main() {
7 let args: Vec<_> = std::env::args().collect();
8
9 if args.len() < 2 {
10 eprintln!("Usage: {} <prog>", args[0]);
11 return;
12 }
13
14 let prog = rscel::Program::from_source(&args[1]).expect("Failed to compile");
15 let ast = prog.details().ast().unwrap();
16
17 AstDumper::with_source(&args[1]).dump_expr_node(ast, 0);
18}More examples
examples/explain.rs (line 52)
37fn main() {
38 let args: Vec<_> = std::env::args().collect();
39
40 if args.len() < 2 {
41 eprintln!("Usage: {} <prog> [bindings]", args[0]);
42 return;
43 }
44
45 let bindings: serde_json::Value = if args.len() == 3 {
46 serde_json::from_str(&args[2]).expect("Failed to parse bindings")
47 } else {
48 serde_json::from_str::<serde_json::Value>("{}").unwrap()
49 };
50
51 let prog = rscel::Program::from_source(&args[1]).expect("Failed to compile");
52 let ast = prog.details().ast().unwrap();
53
54 let dumper = AstDumper::new();
55 let tree = dumper.dump_expr_node(ast);
56
57 let mut queue = Vec::new();
58 queue.push((tree, 0));
59
60 while !queue.is_empty() {
61 let (curr_node, depth) = queue.pop().expect("wut");
62
63 // for now only handle one line
64 let range = curr_node.range();
65
66 let start = range.start().col();
67 let end = range.end().col();
68
69 let src = &args[1][start..end];
70
71 print!("{}{} => ", " ".to_owned().repeat(depth), src);
72 match eval(src, &bindings) {
73 Ok(val) => println!("{}", val),
74 Err(err) => println!("err: {}", err),
75 }
76
77 for node in curr_node.into_children().into_iter().rev() {
78 if node.range() != range {
79 queue.push((node, depth + 1));
80 }
81 }
82 }
83}pub fn details_mut<'a>(&'a mut self) -> &'a mut ProgramDetails
Sourcepub fn bytecode<'a>(&'a self) -> &'a CelByteCode
pub fn bytecode<'a>(&'a self) -> &'a CelByteCode
Examples found in repository?
examples/dumps_bc.rs (line 12)
4fn main() {
5 let args = env::args().collect::<Vec<_>>();
6
7 if args.len() < 2 {
8 panic!("No program passed")
9 }
10
11 let p = Program::from_source(&args[1]).expect("Failed to compile program");
12 for bc in p.bytecode().iter() {
13 println!("{:?}", bc);
14 }
15}pub fn dumps_bc(&self) -> String
pub fn ast<'a>(&'a self) -> Option<&'a AstNode<Expr>>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Program
impl<'de> Deserialize<'de> for Program
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Program
impl !RefUnwindSafe for Program
impl Send for Program
impl Sync for Program
impl Unpin for Program
impl !UnwindSafe for Program
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more