1
0

Implement download tool

This commit is contained in:
Jeff 2023-10-22 16:50:09 -04:00
parent bd83ccd301
commit ecdac6fab5
5 changed files with 1022 additions and 962 deletions

View File

@ -7,6 +7,7 @@ use std::{
}; };
use rand::{random, thread_rng, Rng}; use rand::{random, thread_rng, Rng};
use reqwest::blocking::get;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tree_sitter::Node; use tree_sitter::Node;
@ -17,6 +18,7 @@ pub enum Tool {
// General // General
Assert(Vec<Expression>), Assert(Vec<Expression>),
AssertEqual(Vec<Expression>), AssertEqual(Vec<Expression>),
Download(Expression),
Help(Option<Expression>), Help(Option<Expression>),
Length(Expression), Length(Expression),
Output(Vec<Expression>), Output(Vec<Expression>),
@ -87,6 +89,12 @@ impl AbstractTree for Tool {
Tool::AssertEqual(expressions) Tool::AssertEqual(expressions)
} }
"download" => {
let expression_node = node.child(2).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?;
Tool::Download(expression)
}
"help" => { "help" => {
let child_node = node.child(2).unwrap(); let child_node = node.child(2).unwrap();
let expression = if child_node.is_named() { let expression = if child_node.is_named() {
@ -271,6 +279,13 @@ impl AbstractTree for Tool {
Ok(Value::Empty) 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) => { Tool::Length(expression) => {
let length = expression.run(source, context)?.as_list()?.len(); let length = expression.run(source, context)?.as_list()?.len();

View File

@ -262,6 +262,7 @@ module.exports = grammar({
// General // General
'assert', 'assert',
'assert_equal', 'assert_equal',
'download',
'help', 'help',
'length', 'length',
'output', 'output',

View File

@ -1074,6 +1074,10 @@
"type": "STRING", "type": "STRING",
"value": "assert_equal" "value": "assert_equal"
}, },
{
"type": "STRING",
"value": "download"
},
{ {
"type": "STRING", "type": "STRING",
"value": "help" "value": "help"

View File

@ -733,6 +733,10 @@
"type": "columns", "type": "columns",
"named": false "named": false
}, },
{
"type": "download",
"named": false
},
{ {
"type": "else", "type": "else",
"named": false "named": false

File diff suppressed because it is too large Load Diff