-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into pokey/keyboard-parser
- Loading branch information
Showing
159 changed files
with
4,508 additions
and
862 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package p | ||
|
||
func switches(x any) { | ||
switch x { | ||
case 1: | ||
// bar | ||
case 2: | ||
x = nil | ||
case "s": | ||
case 4, "t": | ||
x = 7 | ||
// qux | ||
case 5: | ||
// foo | ||
fallthrough | ||
default: | ||
panic("x") | ||
} | ||
switch x := x.(type) { | ||
case int: | ||
x++ | ||
case string, struct{}: | ||
println(x) | ||
default: | ||
panic(x) | ||
} | ||
switch { | ||
case x == 1: | ||
panic("one") | ||
case false: | ||
// unreachable | ||
} | ||
} | ||
|
||
func ifElseChains(x int) { | ||
if y := 0; x == 1 { | ||
// foo | ||
} else if z:=0; x == 2 { | ||
x-- | ||
x-- | ||
x-- | ||
} else if z:=0; x == 2 { | ||
x-- | ||
x-- | ||
x-- | ||
} else if x == 3 { | ||
x++ | ||
} else if x == 3 { | ||
x++ | ||
} else { | ||
x *= 2 | ||
} | ||
|
||
if x == 4{ | ||
x++ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,11 @@ | ||
import type { SyntaxNode } from "web-tree-sitter"; | ||
import { SimpleScopeTypeType } from "@cursorless/common"; | ||
import { NodeMatcherAlternative, SelectionWithEditor } from "../typings/Types"; | ||
import { typedNodeFinder } from "../util/nodeFinders"; | ||
import { | ||
createPatternMatchers, | ||
leadingMatcher, | ||
matcher, | ||
patternMatcher, | ||
} from "../util/nodeMatchers"; | ||
import { xmlElementExtractor, getNodeRange } from "../util/nodeSelectors"; | ||
|
||
const attribute = "*?.attribute!"; | ||
|
||
const getStartTag = patternMatcher(`*?.start_tag!`); | ||
const getEndTag = patternMatcher(`*?.end_tag!`); | ||
|
||
const getTags = (selection: SelectionWithEditor, node: SyntaxNode) => { | ||
const startTag = getStartTag(selection, node); | ||
const endTag = getEndTag(selection, node); | ||
return startTag != null && endTag != null ? startTag.concat(endTag) : null; | ||
}; | ||
import { NodeMatcherAlternative } from "../typings/Types"; | ||
import { createPatternMatchers } from "../util/nodeMatchers"; | ||
|
||
const nodeMatchers: Partial< | ||
Record<SimpleScopeTypeType, NodeMatcherAlternative> | ||
> = { | ||
xmlElement: matcher( | ||
typedNodeFinder("element", "script_element", "style_element"), | ||
xmlElementExtractor, | ||
), | ||
xmlBothTags: getTags, | ||
xmlStartTag: getStartTag, | ||
xmlEndTag: getEndTag, | ||
attribute: attribute, | ||
collectionItem: attribute, | ||
name: "*?.tag_name!", | ||
collectionKey: ["*?.attribute_name!"], | ||
value: leadingMatcher( | ||
["*?.quoted_attribute_value!.attribute_value", "*?.attribute_value!"], | ||
["="], | ||
), | ||
string: "quoted_attribute_value", | ||
comment: "comment", | ||
collectionItem: "*?.attribute!", | ||
}; | ||
|
||
export const patternMatchers = createPatternMatchers(nodeMatchers); | ||
|
||
const textFragmentTypes = ["attribute_value", "raw_text", "text"]; | ||
|
||
export function stringTextFragmentExtractor( | ||
node: SyntaxNode, | ||
_selection: SelectionWithEditor, | ||
) { | ||
if (textFragmentTypes.includes(node.type)) { | ||
return getNodeRange(node); | ||
} | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,12 @@ | ||
import { | ||
createPatternMatchers, | ||
argumentMatcher, | ||
leadingMatcher, | ||
conditionMatcher, | ||
trailingMatcher, | ||
matcher, | ||
cascadingMatcher, | ||
} from "../util/nodeMatchers"; | ||
import { childRangeSelector } from "../util/nodeSelectors"; | ||
import { patternFinder } from "../util/nodeFinders"; | ||
import { argumentMatcher, createPatternMatchers } from "../util/nodeMatchers"; | ||
|
||
import { NodeMatcherAlternative } from "../typings/Types"; | ||
import { SimpleScopeTypeType } from "@cursorless/common"; | ||
|
||
// Generated by the following command: | ||
// > curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-java/master/src/node-types.json | jq '[.[] | select(.type == "statement" or .type == "declaration") | .subtypes[].type]' | ||
const STATEMENT_TYPES = [ | ||
"annotation_type_declaration", | ||
"class_declaration", | ||
"enum_declaration", | ||
"import_declaration", | ||
"interface_declaration", | ||
"module_declaration", | ||
"package_declaration", | ||
"assert_statement", | ||
"break_statement", | ||
"continue_statement", | ||
"declaration", | ||
"do_statement", | ||
"enhanced_for_statement", | ||
"expression_statement", | ||
"for_statement", | ||
"if_statement", | ||
"labeled_statement", | ||
"local_variable_declaration", | ||
"return_statement", | ||
"switch_expression", | ||
"synchronized_statement", | ||
"throw_statement", | ||
"try_statement", | ||
"try_with_resources_statement", | ||
"while_statement", | ||
"yield_statement", | ||
|
||
// exceptions | ||
// ";", | ||
// "block", | ||
"switch_statement", | ||
"method_declaration", | ||
"constructor_declaration", | ||
"field_declaration", | ||
]; | ||
import { NodeMatcherAlternative } from "../typings/Types"; | ||
|
||
const nodeMatchers: Partial< | ||
Record<SimpleScopeTypeType, NodeMatcherAlternative> | ||
> = { | ||
statement: STATEMENT_TYPES, | ||
class: "class_declaration", | ||
className: "class_declaration[name]", | ||
ifStatement: "if_statement", | ||
string: "string_literal", | ||
comment: ["line_comment", "block_comment", "comment"], | ||
anonymousFunction: "lambda_expression", | ||
list: "array_initializer", | ||
functionCall: [ | ||
"method_invocation", | ||
"object_creation_expression", | ||
"explicit_constructor_invocation", | ||
], | ||
functionCallee: cascadingMatcher( | ||
matcher( | ||
patternFinder("method_invocation"), | ||
childRangeSelector(["argument_list"], []), | ||
), | ||
matcher( | ||
patternFinder("object_creation_expression"), | ||
childRangeSelector(["argument_list"], []), | ||
), | ||
matcher( | ||
patternFinder("explicit_constructor_invocation"), | ||
childRangeSelector(["argument_list", ";"], []), | ||
), | ||
), | ||
map: "block", | ||
name: [ | ||
"*[declarator][name]", | ||
"assignment_expression[left]", | ||
"*[name]", | ||
"formal_parameter.identifier!", | ||
], | ||
namedFunction: ["method_declaration", "constructor_declaration"], | ||
type: trailingMatcher([ | ||
"generic_type.type_arguments.type_identifier", | ||
"generic_type.type_identifier", | ||
"generic_type.scoped_type_identifier.type_identifier", | ||
"type_identifier", | ||
"local_variable_declaration[type]", | ||
"array_creation_expression[type]", | ||
"formal_parameter[type]", | ||
"method_declaration[type]", | ||
]), | ||
functionName: [ | ||
"method_declaration.identifier!", | ||
"constructor_declaration.identifier!", | ||
], | ||
value: leadingMatcher( | ||
[ | ||
"*[declarator][value]", | ||
"assignment_expression[right]", | ||
"return_statement[0]", | ||
"*[value]", | ||
], | ||
["=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="], | ||
), | ||
condition: conditionMatcher("*[condition]"), | ||
argumentOrParameter: argumentMatcher("formal_parameters", "argument_list"), | ||
branch: ["switch_block_statement_group", "switch_rule"], | ||
["private.switchStatementSubject"]: "switch_expression[condition][0]", | ||
}; | ||
|
||
export default createPatternMatchers(nodeMatchers); |
Oops, something went wrong.