Repair command implementation
This commit is contained in:
parent
c2fc3362c8
commit
f6a1e641c9
@ -6,16 +6,20 @@ use crate::{AbstractTree, Error, Format, Map, Result, Type, Value};
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
|
||||||
pub struct Command {
|
pub struct Command {
|
||||||
command_texts: Vec<String>,
|
command_text: String,
|
||||||
|
command_arguments: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AbstractTree for Command {
|
impl AbstractTree for Command {
|
||||||
fn from_syntax(node: tree_sitter::Node, source: &str, _context: &crate::Map) -> Result<Self> {
|
fn from_syntax(node: tree_sitter::Node, source: &str, _context: &crate::Map) -> Result<Self> {
|
||||||
Error::expect_syntax_node(source, "command", node)?;
|
Error::expect_syntax_node(source, "command", node)?;
|
||||||
|
|
||||||
let mut command_texts = Vec::new();
|
let command_text_node = node.child(1).unwrap();
|
||||||
|
let command_text = source[command_text_node.byte_range()].to_string();
|
||||||
|
|
||||||
for index in 1..node.child_count() {
|
let mut command_arguments = Vec::new();
|
||||||
|
|
||||||
|
for index in 2..node.child_count() {
|
||||||
let text_node = node.child(index).unwrap();
|
let text_node = node.child(index).unwrap();
|
||||||
let mut text = source[text_node.byte_range()].to_string();
|
let mut text = source[text_node.byte_range()].to_string();
|
||||||
|
|
||||||
@ -26,15 +30,18 @@ impl AbstractTree for Command {
|
|||||||
text = text[1..text.len() - 1].to_string();
|
text = text[1..text.len() - 1].to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
command_texts.push(text);
|
command_arguments.push(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Command { command_texts })
|
Ok(Command {
|
||||||
|
command_text,
|
||||||
|
command_arguments,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, _source: &str, _context: &Map) -> Result<Value> {
|
fn run(&self, _source: &str, _context: &Map) -> Result<Value> {
|
||||||
let output = process::Command::new(self.command_texts.first().unwrap())
|
let output = process::Command::new(&self.command_text)
|
||||||
.args(&self.command_texts[1..])
|
.args(&self.command_arguments)
|
||||||
.spawn()?
|
.spawn()?
|
||||||
.wait_with_output()?
|
.wait_with_output()?
|
||||||
.stdout;
|
.stdout;
|
||||||
|
@ -9,7 +9,8 @@ Simple Command
|
|||||||
(root
|
(root
|
||||||
(statement
|
(statement
|
||||||
(expression
|
(expression
|
||||||
(command))))
|
(command
|
||||||
|
(command_text)))))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Command Sequence
|
Command Sequence
|
||||||
@ -22,10 +23,12 @@ Command Sequence
|
|||||||
(root
|
(root
|
||||||
(statement
|
(statement
|
||||||
(expression
|
(expression
|
||||||
(command)))
|
(command
|
||||||
|
(command_text))))
|
||||||
(statement
|
(statement
|
||||||
(expression
|
(expression
|
||||||
(command))))
|
(command
|
||||||
|
(command_text)))))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Command with Arguments
|
Command with Arguments
|
||||||
@ -39,6 +42,7 @@ Command with Arguments
|
|||||||
(statement
|
(statement
|
||||||
(expression
|
(expression
|
||||||
(command
|
(command
|
||||||
|
(command_text)
|
||||||
(command_argument)
|
(command_argument)
|
||||||
(command_argument)))))
|
(command_argument)))))
|
||||||
|
|
||||||
@ -55,6 +59,7 @@ Command Sequence with Arguments
|
|||||||
(statement
|
(statement
|
||||||
(expression
|
(expression
|
||||||
(command
|
(command
|
||||||
|
(command_text)
|
||||||
(command_argument)
|
(command_argument)
|
||||||
(command_argument)
|
(command_argument)
|
||||||
(command_argument)
|
(command_argument)
|
||||||
@ -62,5 +67,6 @@ Command Sequence with Arguments
|
|||||||
(statement
|
(statement
|
||||||
(expression
|
(expression
|
||||||
(command
|
(command
|
||||||
|
(command_text)
|
||||||
(command_argument)
|
(command_argument)
|
||||||
(command_argument)))))
|
(command_argument)))))
|
||||||
|
@ -9,8 +9,10 @@ Simple Command Pipe
|
|||||||
(root
|
(root
|
||||||
(statement
|
(statement
|
||||||
(pipe
|
(pipe
|
||||||
(command)
|
(command
|
||||||
(command))))
|
(command_text))
|
||||||
|
(command
|
||||||
|
(command_text)))))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Simple Function Pipe
|
Simple Function Pipe
|
||||||
|
@ -86,11 +86,13 @@ module.exports = grammar({
|
|||||||
prec.right(
|
prec.right(
|
||||||
seq(
|
seq(
|
||||||
'*',
|
'*',
|
||||||
/\S+/,
|
$.command_text,
|
||||||
repeat($.command_argument),
|
repeat($.command_argument),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
command_text: $ => /\S+/,
|
||||||
|
|
||||||
command_argument: $ =>
|
command_argument: $ =>
|
||||||
choice(
|
choice(
|
||||||
/[^*\s]+/,
|
/[^*\s]+/,
|
||||||
|
@ -236,8 +236,8 @@
|
|||||||
"value": "*"
|
"value": "*"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "PATTERN",
|
"type": "SYMBOL",
|
||||||
"value": "\\S+"
|
"name": "command_text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "REPEAT",
|
"type": "REPEAT",
|
||||||
@ -249,6 +249,10 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"command_text": {
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "\\S+"
|
||||||
|
},
|
||||||
"command_argument": {
|
"command_argument": {
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
|
@ -62,11 +62,15 @@
|
|||||||
"fields": {},
|
"fields": {},
|
||||||
"children": {
|
"children": {
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": false,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
"type": "command_argument",
|
"type": "command_argument",
|
||||||
"named": true
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "command_text",
|
||||||
|
"named": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -909,6 +913,10 @@
|
|||||||
"type": "collection",
|
"type": "collection",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "command_text",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "else",
|
"type": "else",
|
||||||
"named": false
|
"named": false
|
||||||
|
@ -25,7 +25,7 @@ enum {
|
|||||||
anon_sym_COMMA = 6,
|
anon_sym_COMMA = 6,
|
||||||
anon_sym_PIPE = 7,
|
anon_sym_PIPE = 7,
|
||||||
anon_sym_STAR = 8,
|
anon_sym_STAR = 8,
|
||||||
aux_sym_command_token1 = 9,
|
sym_command_text = 9,
|
||||||
aux_sym_command_argument_token1 = 10,
|
aux_sym_command_argument_token1 = 10,
|
||||||
aux_sym_command_argument_token2 = 11,
|
aux_sym_command_argument_token2 = 11,
|
||||||
anon_sym_async = 12,
|
anon_sym_async = 12,
|
||||||
@ -152,7 +152,7 @@ static const char * const ts_symbol_names[] = {
|
|||||||
[anon_sym_COMMA] = ",",
|
[anon_sym_COMMA] = ",",
|
||||||
[anon_sym_PIPE] = "|",
|
[anon_sym_PIPE] = "|",
|
||||||
[anon_sym_STAR] = "*",
|
[anon_sym_STAR] = "*",
|
||||||
[aux_sym_command_token1] = "command_token1",
|
[sym_command_text] = "command_text",
|
||||||
[aux_sym_command_argument_token1] = "command_argument_token1",
|
[aux_sym_command_argument_token1] = "command_argument_token1",
|
||||||
[aux_sym_command_argument_token2] = "command_argument_token2",
|
[aux_sym_command_argument_token2] = "command_argument_token2",
|
||||||
[anon_sym_async] = "async",
|
[anon_sym_async] = "async",
|
||||||
@ -279,7 +279,7 @@ static const TSSymbol ts_symbol_map[] = {
|
|||||||
[anon_sym_COMMA] = anon_sym_COMMA,
|
[anon_sym_COMMA] = anon_sym_COMMA,
|
||||||
[anon_sym_PIPE] = anon_sym_PIPE,
|
[anon_sym_PIPE] = anon_sym_PIPE,
|
||||||
[anon_sym_STAR] = anon_sym_STAR,
|
[anon_sym_STAR] = anon_sym_STAR,
|
||||||
[aux_sym_command_token1] = aux_sym_command_token1,
|
[sym_command_text] = sym_command_text,
|
||||||
[aux_sym_command_argument_token1] = aux_sym_command_argument_token1,
|
[aux_sym_command_argument_token1] = aux_sym_command_argument_token1,
|
||||||
[aux_sym_command_argument_token2] = aux_sym_command_argument_token2,
|
[aux_sym_command_argument_token2] = aux_sym_command_argument_token2,
|
||||||
[anon_sym_async] = anon_sym_async,
|
[anon_sym_async] = anon_sym_async,
|
||||||
@ -433,9 +433,9 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
|
|||||||
.visible = true,
|
.visible = true,
|
||||||
.named = false,
|
.named = false,
|
||||||
},
|
},
|
||||||
[aux_sym_command_token1] = {
|
[sym_command_text] = {
|
||||||
.visible = false,
|
.visible = true,
|
||||||
.named = false,
|
.named = true,
|
||||||
},
|
},
|
||||||
[aux_sym_command_argument_token1] = {
|
[aux_sym_command_argument_token1] = {
|
||||||
.visible = false,
|
.visible = false,
|
||||||
@ -2663,7 +2663,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
|
|||||||
ACCEPT_TOKEN(anon_sym_STAR);
|
ACCEPT_TOKEN(anon_sym_STAR);
|
||||||
END_STATE();
|
END_STATE();
|
||||||
case 74:
|
case 74:
|
||||||
ACCEPT_TOKEN(aux_sym_command_token1);
|
ACCEPT_TOKEN(sym_command_text);
|
||||||
if (lookahead == '\n') ADVANCE(57);
|
if (lookahead == '\n') ADVANCE(57);
|
||||||
if (lookahead == '#') ADVANCE(62);
|
if (lookahead == '#') ADVANCE(62);
|
||||||
if (lookahead == '|') ADVANCE(59);
|
if (lookahead == '|') ADVANCE(59);
|
||||||
@ -2673,7 +2673,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
|
|||||||
if (lookahead != 0) ADVANCE(74);
|
if (lookahead != 0) ADVANCE(74);
|
||||||
END_STATE();
|
END_STATE();
|
||||||
case 75:
|
case 75:
|
||||||
ACCEPT_TOKEN(aux_sym_command_token1);
|
ACCEPT_TOKEN(sym_command_text);
|
||||||
if (lookahead == '>') ADVANCE(162);
|
if (lookahead == '>') ADVANCE(162);
|
||||||
if (lookahead != 0 &&
|
if (lookahead != 0 &&
|
||||||
lookahead != '\t' &&
|
lookahead != '\t' &&
|
||||||
@ -2682,7 +2682,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
|
|||||||
lookahead != ' ') ADVANCE(76);
|
lookahead != ' ') ADVANCE(76);
|
||||||
END_STATE();
|
END_STATE();
|
||||||
case 76:
|
case 76:
|
||||||
ACCEPT_TOKEN(aux_sym_command_token1);
|
ACCEPT_TOKEN(sym_command_text);
|
||||||
if (lookahead != 0 &&
|
if (lookahead != 0 &&
|
||||||
lookahead != '\t' &&
|
lookahead != '\t' &&
|
||||||
lookahead != '\n' &&
|
lookahead != '\n' &&
|
||||||
@ -30282,7 +30282,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1190), 1,
|
ACTIONS(1190), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
ACTIONS(1192), 1,
|
ACTIONS(1192), 1,
|
||||||
anon_sym_EQ_GT,
|
anon_sym_EQ_GT,
|
||||||
[26219] = 2,
|
[26219] = 2,
|
||||||
@ -30320,7 +30320,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1204), 1,
|
ACTIONS(1204), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26269] = 2,
|
[26269] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
@ -30345,7 +30345,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1214), 1,
|
ACTIONS(1214), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26304] = 2,
|
[26304] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
@ -30360,7 +30360,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1220), 1,
|
ACTIONS(1220), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26325] = 2,
|
[26325] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
@ -30370,7 +30370,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1224), 1,
|
ACTIONS(1224), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26339] = 2,
|
[26339] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
@ -30400,7 +30400,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1236), 1,
|
ACTIONS(1236), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26381] = 2,
|
[26381] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
@ -30410,17 +30410,17 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1190), 1,
|
ACTIONS(1190), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26395] = 2,
|
[26395] = 2,
|
||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1240), 1,
|
ACTIONS(1240), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26402] = 2,
|
[26402] = 2,
|
||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1242), 1,
|
ACTIONS(1242), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26409] = 2,
|
[26409] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
@ -30435,7 +30435,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1248), 1,
|
ACTIONS(1248), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26430] = 2,
|
[26430] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
@ -30450,12 +30450,12 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1254), 1,
|
ACTIONS(1254), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26451] = 2,
|
[26451] = 2,
|
||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1256), 1,
|
ACTIONS(1256), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26458] = 2,
|
[26458] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
@ -30475,7 +30475,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1264), 1,
|
ACTIONS(1264), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26486] = 2,
|
[26486] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
@ -30495,17 +30495,17 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1272), 1,
|
ACTIONS(1272), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26514] = 2,
|
[26514] = 2,
|
||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1274), 1,
|
ACTIONS(1274), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26521] = 2,
|
[26521] = 2,
|
||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1276), 1,
|
ACTIONS(1276), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26528] = 2,
|
[26528] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
@ -30525,7 +30525,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1284), 1,
|
ACTIONS(1284), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26556] = 2,
|
[26556] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
@ -30540,7 +30540,7 @@ static const uint16_t ts_small_parse_table[] = {
|
|||||||
ACTIONS(353), 1,
|
ACTIONS(353), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
ACTIONS(1290), 1,
|
ACTIONS(1290), 1,
|
||||||
aux_sym_command_token1,
|
sym_command_text,
|
||||||
[26577] = 2,
|
[26577] = 2,
|
||||||
ACTIONS(3), 1,
|
ACTIONS(3), 1,
|
||||||
sym__comment,
|
sym__comment,
|
||||||
|
Loading…
Reference in New Issue
Block a user