-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial Perl support and some tests #1301
base: main
Are you sure you want to change the base?
Changes from all commits
5f35c86
cbc72ff
580f55d
3175e6b
c4c6afa
2abccee
b406a48
2a70959
fa494ec
fe039a6
8de6370
e8ed2bc
726cab0
f7a0fcf
3596f1f
65d7a59
37aa1b4
521f2e0
a052de0
12a1a22
d287a38
c6cb621
b40ff3d
70bed59
c0187b2
a0bb761
64a9894
dd0d992
3846418
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { | ||
argumentMatcher, | ||
cascadingMatcher, | ||
createPatternMatchers, | ||
matcher, | ||
patternMatcher, | ||
} from "../util/nodeMatchers"; | ||
import { NodeMatcherAlternative } from "../typings/Types"; | ||
import { SimpleScopeTypeType } from "@cursorless/common"; | ||
import { | ||
childRangeSelector, | ||
unwrapSelectionExtractor, | ||
} from "../util/nodeSelectors"; | ||
import { patternFinder } from "../util/nodeFinders"; | ||
import { branchMatcher } from "./branchMatcher"; | ||
|
||
const nodeMatchers: Partial< | ||
Record<SimpleScopeTypeType, NodeMatcherAlternative> | ||
> = { | ||
map: "hash", | ||
list: "array", | ||
condition: matcher( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing ternaries. prob not a showstopper to ship without it; depending how common ternaries are in Perl |
||
patternFinder( | ||
"while_statement[condition]", | ||
"for_statement_1[condition]", | ||
"for_statement_2.binary_expression!", | ||
"for_statement_2.array_variable!", | ||
"for_simple_statement.binary_expression!", | ||
"for_simple_statement.array_variable!", | ||
"if_statement[condition]", | ||
"unless_statement[condition]", | ||
), | ||
unwrapSelectionExtractor, | ||
), | ||
string: [ | ||
"string_single_quoted", | ||
"string_double_quoted", | ||
"string_q_quoted", | ||
"string_qq_quoted", | ||
], | ||
ifStatement: "if_statement", | ||
functionCall: [ | ||
"call_expression", | ||
"call_expression_with_just_name", | ||
"method_invocation", | ||
], | ||
functionCallee: cascadingMatcher( | ||
patternMatcher("call_expression_with_just_name"), | ||
matcher( | ||
patternFinder("call_expression", "method_invocation"), | ||
childRangeSelector( | ||
["arguments", "argument", "empty_parenthesized_argument"], | ||
[], | ||
), | ||
), | ||
), | ||
comment: "comments", | ||
namedFunction: ["function_definition"], | ||
anonymousFunction: "anonymous_function", | ||
regularExpression: [ | ||
"patter_matcher_m", // Mistype (?) but that is the name in tree-sitter-perl; it must come before pattern_matcher | ||
"pattern_matcher", | ||
"regex_pattern_qr", | ||
"substitution_pattern_s", | ||
], | ||
collectionKey: "key_value_pair[key]", | ||
collectionItem: "hash[variable]", | ||
argumentOrParameter: argumentMatcher("arguments"), | ||
class: [ | ||
"package_statement!.block[body]", | ||
"source_file!.package_statement", | ||
"package_statement", | ||
"source_file", | ||
], | ||
className: "package_statement.package_name!", | ||
name: ["function_definition[name]", "*[key]"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
value: ["*[value]"], | ||
branch: cascadingMatcher( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing ternaries. prob not a showstopper to ship without it; depending how common ternaries are in Perl |
||
branchMatcher("if_statement", ["else_clause", "elsif_clause"]), | ||
), | ||
}; | ||
|
||
export const patternMatchers = createPatternMatchers(nodeMatchers); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
languageId: perl | ||
Leeft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
command: | ||
version: 4 | ||
spokenForm: change arg | ||
action: { name: clearAndSetSelection } | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: { type: argumentOrParameter } | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: some_funky_func( "and", "three", "args" ) | ||
selections: | ||
- anchor: { line: 0, character: 36 } | ||
active: { line: 0, character: 36 } | ||
marks: {} | ||
finalState: | ||
documentContents: some_funky_func( "and", "three", ) | ||
selections: | ||
- anchor: { line: 0, character: 33 } | ||
active: { line: 0, character: 33 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
languageId: perl | ||
command: | ||
version: 4 | ||
spokenForm: change arg | ||
action: {name: clearAndSetSelection} | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: argumentOrParameter} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: some_funky_func( "and", "three", "args" ) | ||
selections: | ||
- anchor: {line: 0, character: 29} | ||
active: {line: 0, character: 29} | ||
marks: {} | ||
finalState: | ||
documentContents: some_funky_func( "and", , "args" ) | ||
selections: | ||
- anchor: {line: 0, character: 24} | ||
active: {line: 0, character: 24} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
languageId: perl | ||
command: | ||
version: 4 | ||
spokenForm: change arg | ||
action: {name: clearAndSetSelection} | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: argumentOrParameter} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: some_funky_func( "and", "three", "args" ) | ||
selections: | ||
- anchor: {line: 0, character: 21} | ||
active: {line: 0, character: 21} | ||
marks: {} | ||
finalState: | ||
documentContents: some_funky_func( , "three", "args" ) | ||
selections: | ||
- anchor: {line: 0, character: 17} | ||
active: {line: 0, character: 17} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
languageId: perl | ||
command: | ||
version: 5 | ||
spokenForm: change arg | ||
action: {name: clearAndSetSelection} | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: argumentOrParameter} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: some_funky_func( "and", "three", "args" ) | ||
selections: | ||
- anchor: {line: 0, character: 16} | ||
active: {line: 0, character: 16} | ||
marks: {} | ||
thrownError: {name: NoContainingScopeError} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have mixed feelings about adding a test for behaviour that we don't actually want to preserve. any thoughts @AndreasArvidsson? some schools of thought support it; I believe it's called "characterization testing" in the literature |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
languageId: perl | ||
command: | ||
version: 5 | ||
spokenForm: change branch | ||
action: {name: clearAndSetSelection} | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: branch} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: | | ||
if ( 1 ) { | ||
2; | ||
} elsif ( 3 ) { | ||
4; | ||
} else { | ||
5; | ||
} | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
marks: {} | ||
finalState: | ||
documentContents: |2 | ||
elsif ( 3 ) { | ||
4; | ||
} else { | ||
5; | ||
} | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
languageId: perl | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
command: | ||
version: 5 | ||
spokenForm: change branch | ||
action: {name: clearAndSetSelection} | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: branch} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: | | ||
if ( 1 ) { | ||
2; | ||
} elsif ( 3 ) { | ||
4; | ||
} else { | ||
5; | ||
} | ||
selections: | ||
- anchor: {line: 2, character: 2} | ||
active: {line: 2, character: 2} | ||
marks: {} | ||
finalState: | ||
documentContents: | | ||
if ( 1 ) { | ||
2; | ||
} else { | ||
5; | ||
} | ||
selections: | ||
- anchor: {line: 2, character: 2} | ||
active: {line: 2, character: 2} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
languageId: perl | ||
command: | ||
version: 5 | ||
spokenForm: change branch | ||
action: {name: clearAndSetSelection} | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: branch} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: | | ||
if ( 1 ) { | ||
2; | ||
} elsif ( 3 ) { | ||
4; | ||
} else { | ||
5; | ||
} | ||
selections: | ||
- anchor: {line: 4, character: 2} | ||
active: {line: 4, character: 2} | ||
marks: {} | ||
finalState: | ||
documentContents: | | ||
if ( 1 ) { | ||
2; | ||
} elsif ( 3 ) { | ||
4; | ||
} | ||
selections: | ||
- anchor: {line: 4, character: 2} | ||
active: {line: 4, character: 2} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
languageId: perl | ||
command: | ||
version: 4 | ||
spokenForm: change call | ||
action: { name: clearAndSetSelection } | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: { type: functionCall } | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
my $var = 1; | ||
$var = func(); | ||
$var = 2; | ||
selections: | ||
- anchor: { line: 1, character: 12 } | ||
active: { line: 1, character: 12 } | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
my $var = 1; | ||
$var = ; | ||
$var = 2; | ||
selections: | ||
- anchor: { line: 1, character: 7 } | ||
active: { line: 1, character: 7 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
languageId: perl | ||
command: | ||
version: 4 | ||
spokenForm: change call | ||
action: { name: clearAndSetSelection } | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: { type: functionCall } | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
my $var = 1; | ||
$var = func_with_params( $var ); | ||
$var = 2; | ||
selections: | ||
- anchor: { line: 1, character: 27 } | ||
active: { line: 1, character: 27 } | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
my $var = 1; | ||
$var = ; | ||
$var = 2; | ||
selections: | ||
- anchor: { line: 1, character: 7 } | ||
active: { line: 1, character: 7 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
languageId: perl | ||
command: | ||
version: 4 | ||
spokenForm: change call | ||
action: { name: clearAndSetSelection } | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: { type: functionCall } | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
my $var = 1; | ||
$var = $object->method( ); | ||
$var = 2; | ||
selections: | ||
- anchor: { line: 1, character: 24 } | ||
active: { line: 1, character: 24 } | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
my $var = 1; | ||
$var = ; | ||
$var = 2; | ||
selections: | ||
- anchor: { line: 1, character: 7 } | ||
active: { line: 1, character: 7 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing "state" (
statement
)