diff --git a/README.md b/README.md index d4c5164..d814016 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@
-
+

A Web Crawling Programming Language

+GitHub Actions Workflow Status GitHub Actions Workflow Status

diff --git a/scout-interpreter/src/builtin.rs b/scout-interpreter/src/builtin.rs index 56c93b5..ad404a7 100644 --- a/scout-interpreter/src/builtin.rs +++ b/scout-interpreter/src/builtin.rs @@ -20,7 +20,8 @@ pub enum BuiltinKind { Href, Trim, Click, - PrintResults, + Results, + Len, } impl BuiltinKind { @@ -32,7 +33,8 @@ impl BuiltinKind { "trim" => Some(Trim), "href" => Some(Href), "click" => Some(Click), - "printResults" => Some(PrintResults), + "results" => Some(Results), + "len" => Some(Len), _ => None, } } @@ -85,11 +87,21 @@ impl BuiltinKind { Err(EvalError::InvalidFnParams) } } - PrintResults => { + Results => { let json = results.lock().await.to_json(); println!("{}", json); Ok(Arc::new(Object::Null)) } + Len => { + assert_param_len!(args, 1); + let len = match &*args[0] { + Object::List(v) => Ok(v.len() as f64), + Object::Str(s) => Ok(s.len() as f64), + _ => Err(EvalError::InvalidFnParams), + }?; + + Ok(Arc::new(Object::Number(len))) + } } } } diff --git a/scout-interpreter/src/object.rs b/scout-interpreter/src/object.rs index 76af740..8ef7dca 100644 --- a/scout-interpreter/src/object.rs +++ b/scout-interpreter/src/object.rs @@ -45,7 +45,13 @@ impl Display for Object { } Str(s) => write!(f, "\"{}\"", s), Node(_) => write!(f, "Node"), - List(objs) => write!(f, "[Object; {}]", objs.len()), + List(objs) => { + write!(f, "[")?; + for obj in objs { + write!(f, "{}, ", obj)?; + } + write!(f, "]") + } Boolean(b) => write!(f, "{}", b), Number(n) => write!(f, "{}", n), }