Skip to content

Commit dc2ff17

Browse files
author
fidgetingbits
committed
Better statement support and tests
1 parent 4794b2b commit dc2ff17

File tree

6 files changed

+153
-1
lines changed

6 files changed

+153
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: shellscript
2+
command:
3+
version: 6
4+
spokenForm: change command
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: command}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: ls non_existent_file || echo "File not found"
15+
selections:
16+
- anchor: {line: 0, character: 26}
17+
active: {line: 0, character: 26}
18+
marks: {}
19+
finalState:
20+
documentContents: "ls non_existent_file || "
21+
selections:
22+
- anchor: {line: 0, character: 24}
23+
active: {line: 0, character: 24}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
languageId: shellscript
2+
command:
3+
version: 6
4+
spokenForm: change condition each
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: e}
10+
modifiers:
11+
- type: containingScope
12+
scopeType: {type: condition}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: |-
16+
until [ $counter -gt 5 ]
17+
do
18+
echo "Iteration: $counter"
19+
((counter++))
20+
done
21+
selections:
22+
- anchor: {line: 4, character: 4}
23+
active: {line: 4, character: 4}
24+
marks:
25+
default.e:
26+
start: {line: 0, character: 9}
27+
end: {line: 0, character: 16}
28+
finalState:
29+
documentContents: |-
30+
until
31+
do
32+
echo "Iteration: $counter"
33+
((counter++))
34+
done
35+
selections:
36+
- anchor: {line: 0, character: 6}
37+
active: {line: 0, character: 6}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
languageId: shellscript
2+
command:
3+
version: 6
4+
spokenForm: change regex zero
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: '0'}
10+
modifiers:
11+
- type: containingScope
12+
scopeType: {type: regularExpression}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: |+
16+
17+
string="The date is 2023-01-01."
18+
if [[ $string =~ ([0-9]{4}-[0-9]{2}-[0-9]{2}) ]]; then
19+
matched_date="${BASH_REMATCH[1]}"
20+
echo "Matched date: $matched_date"
21+
fi
22+
23+
selections:
24+
- anchor: {line: 2, character: 5}
25+
active: {line: 2, character: 5}
26+
marks:
27+
default.0:
28+
start: {line: 2, character: 19}
29+
end: {line: 2, character: 22}
30+
finalState:
31+
documentContents: |+
32+
33+
string="The date is 2023-01-01."
34+
if [[ $string =~ ]]; then
35+
matched_date="${BASH_REMATCH[1]}"
36+
echo "Matched date: $matched_date"
37+
fi
38+
39+
selections:
40+
- anchor: {line: 2, character: 17}
41+
active: {line: 2, character: 17}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: shellscript
2+
command:
3+
version: 6
4+
spokenForm: change state
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: statement}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: cat <input.txt
15+
selections:
16+
- anchor: {line: 0, character: 9}
17+
active: {line: 0, character: 9}
18+
marks: {}
19+
finalState:
20+
documentContents: ""
21+
selections:
22+
- anchor: {line: 0, character: 0}
23+
active: {line: 0, character: 0}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: shellscript
2+
command:
3+
version: 6
4+
spokenForm: change state
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: statement}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: ls non_existent_file || echo "File not found"
15+
selections:
16+
- anchor: {line: 0, character: 19}
17+
active: {line: 0, character: 19}
18+
marks: {}
19+
finalState:
20+
documentContents: ""
21+
selections:
22+
- anchor: {line: 0, character: 0}
23+
active: {line: 0, character: 0}

queries/shellscript.scm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@
1414
(for_statement)
1515
(function_definition)
1616
(declaration_command)
17+
(case_statement)
18+
(subshell)
19+
(list)
20+
(redirected_statement)
1721
] @statement
1822

23+
;;FIXME: Make the #not-parent-type? thing a list of nodes
1924
(
2025
(_
2126
[
2227
(variable_assignment)
2328
(command)
2429
] @statement
25-
(#not-parent-type? @statement declaration_command)
30+
(#not-parent-type? @statement declaration_command c_style_for_statement list redirected_statement)
2631
)
2732
)
2833

0 commit comments

Comments
 (0)