Implement download tool
This commit is contained in:
parent
bd83ccd301
commit
ecdac6fab5
@ -7,6 +7,7 @@ use std::{
|
||||
};
|
||||
|
||||
use rand::{random, thread_rng, Rng};
|
||||
use reqwest::blocking::get;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tree_sitter::Node;
|
||||
|
||||
@ -17,6 +18,7 @@ pub enum Tool {
|
||||
// General
|
||||
Assert(Vec<Expression>),
|
||||
AssertEqual(Vec<Expression>),
|
||||
Download(Expression),
|
||||
Help(Option<Expression>),
|
||||
Length(Expression),
|
||||
Output(Vec<Expression>),
|
||||
@ -87,6 +89,12 @@ impl AbstractTree for Tool {
|
||||
|
||||
Tool::AssertEqual(expressions)
|
||||
}
|
||||
"download" => {
|
||||
let expression_node = node.child(2).unwrap();
|
||||
let expression = Expression::from_syntax_node(source, expression_node)?;
|
||||
|
||||
Tool::Download(expression)
|
||||
}
|
||||
"help" => {
|
||||
let child_node = node.child(2).unwrap();
|
||||
let expression = if child_node.is_named() {
|
||||
@ -271,6 +279,13 @@ impl AbstractTree for Tool {
|
||||
|
||||
Ok(Value::Empty)
|
||||
}
|
||||
Tool::Download(expression) => {
|
||||
let value = expression.run(source, context)?;
|
||||
let url = value.as_string()?;
|
||||
let data = get(url)?.text()?;
|
||||
|
||||
Ok(Value::String(data))
|
||||
}
|
||||
Tool::Length(expression) => {
|
||||
let length = expression.run(source, context)?.as_list()?.len();
|
||||
|
||||
|
@ -262,6 +262,7 @@ module.exports = grammar({
|
||||
// General
|
||||
'assert',
|
||||
'assert_equal',
|
||||
'download',
|
||||
'help',
|
||||
'length',
|
||||
'output',
|
||||
|
@ -1074,6 +1074,10 @@
|
||||
"type": "STRING",
|
||||
"value": "assert_equal"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "download"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "help"
|
||||
|
@ -733,6 +733,10 @@
|
||||
"type": "columns",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "download",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "else",
|
||||
"named": false
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user