Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmindlin committed Jun 13, 2024
1 parent a6b9368 commit 6d52e5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div align="center">
<img src="./assets/Scout.png" width="200"><br>
<img src="./assets/Scout.png" width="300"><br>
<p style="font-size:0.5em;color:#d4d4d4">A Web Crawling Programming Language</p>
<img alt="GitHub Actions Workflow Status" src="https://img.shields.io/badge/license-MIT%2FApache-blue.svg?style=for-the-badge&label=License">
<img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/maxmindlin/scout-lang/ci.yml?style=for-the-badge&label=CI">
</div>
<hr>
Expand Down
18 changes: 15 additions & 3 deletions scout-interpreter/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub enum BuiltinKind {
Href,
Trim,
Click,
PrintResults,
Results,
Len,
}

impl BuiltinKind {
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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)))
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion scout-interpreter/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down

0 comments on commit 6d52e5e

Please sign in to comment.