Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/parse-tree-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ We have a small domain-specific language that we use to define patterns to look
| TYPE | Match node type<br>`node.type` |
| Dot operator(`.`) | Type hierarchy between parent and child |
| Wildcard op(`*`) | Match any type |
| Negation op(`~`) | Match any type other than what is specified after `~` |
| Important op(`!`) | Use this node as result instead of parent.<br>By default the leftmost/top node is used |
| Optional op(`?`) | Node is optional. Will match if available. |
| Field op(`[field]`) | Get child field node for resulting node.<br>Only evaluated on the resulting node at the end.<br>`node.childForFieldName(field)` |
Expand Down
7 changes: 4 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ export async function activate(context: vscode.ExtensionContext) {

// const processedTargets = processTargets(navigationMap!, targets);
} catch (e) {
vscode.window.showErrorMessage(e.message);
console.trace(e.message);
throw e;
const err = e as Error;
vscode.window.showErrorMessage(err.message);
console.trace(err.message);
throw err;
}
}
);
Expand Down
4 changes: 2 additions & 2 deletions src/languages/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ const nodeMatchers: Partial<Record<ScopeType, NodeMatcherAlternative>> = {
className: "class_definition[name]",
namedFunction: "decorated_definition?.function_definition",
functionName: "function_definition[name]",
type: ["function_definition[return_type]", "*[type]"],
type: valueMatcher("function_definition[return_type]", "*[type]"),
Copy link
Copy Markdown
Member Author

@pokey pokey Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is so that the leading : gets deleted when using "chuck type"

name: [
"assignment[left]",
"typed_parameter.identifier!",
"parameters.identifier!",
"*[name]",
],
collectionItem: argumentMatcher(...dictionaryTypes, ...listTypes),
value: valueMatcher("assignment[right]", "pair[value].*", "*[value]"),
value: valueMatcher("assignment[right]", "~subscript[value]"),
argumentOrParameter: argumentMatcher("parameters", "argument_list"),
};

Expand Down
23 changes: 23 additions & 0 deletions src/test/suite/fixtures/recorded/languages/python/chuckType.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
spokenForm: chuck type
languageId: python
command:
actionName: remove
partialTargets:
- type: primitive
modifier: {type: containingScope, scopeType: type, includeSiblings: false}
extraArgs: []
marks: {}
initialState:
documentContents: "foo: str = 'hello'"
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
finalState:
documentContents: foo = 'hello'
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
thatMark:
- anchor: {line: 0, character: 3}
active: {line: 0, character: 3}
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: outside, modifier: {type: containingScope, scopeType: type, includeSiblings: false}}]
23 changes: 23 additions & 0 deletions src/test/suite/fixtures/recorded/languages/python/chuckValue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
spokenForm: chuck value
languageId: python
command:
actionName: remove
partialTargets:
- type: primitive
modifier: {type: containingScope, scopeType: value, includeSiblings: false}
extraArgs: []
marks: {}
initialState:
documentContents: "foo: str = \"hello\""
selections:
- anchor: {line: 0, character: 2}
active: {line: 0, character: 2}
finalState:
documentContents: "foo: str "
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should prob clean up this trailing string too, but prob best to leave that one for object-oriented targets refactor

selections:
- anchor: {line: 0, character: 2}
active: {line: 0, character: 2}
thatMark:
- anchor: {line: 0, character: 9}
active: {line: 0, character: 9}
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: outside, modifier: {type: containingScope, scopeType: value, includeSiblings: false}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
spokenForm: clear every value
languageId: python
command:
actionName: clearAndSetSelection
partialTargets:
- type: primitive
modifier: {type: containingScope, scopeType: value, includeSiblings: true}
extraArgs: []
marks: {}
initialState:
documentContents: |-
{
"foo": "bar",
"baz": "bongo",
}
selections:
- anchor: {line: 1, character: 13}
active: {line: 1, character: 13}
finalState:
documentContents: |-
{
"foo": ,
"baz": ,
}
selections:
- anchor: {line: 1, character: 11}
active: {line: 1, character: 11}
- anchor: {line: 2, character: 11}
active: {line: 2, character: 11}
thatMark:
- anchor: {line: 1, character: 11}
active: {line: 1, character: 11}
- anchor: {line: 2, character: 11}
active: {line: 2, character: 11}
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: value, includeSiblings: true}}]
8 changes: 6 additions & 2 deletions src/util/nodeFinders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,17 @@ class Pattern {
isOptional: boolean = false;

constructor(pattern: string) {
this.type = pattern.match(/^[\w*]+/)![0];
this.type = pattern.match(/^[\w*~]+/)![0];
this.fields = [...pattern.matchAll(/(?<=\[).+?(?=\])/g)].map((m) => m[0]);
this.isImportant = pattern.indexOf("!") > -1;
this.isOptional = pattern.indexOf("?") > -1;
}

typeEquals(node: SyntaxNode) {
return this.type === node.type || this.type === "*";
return (
this.type === node.type ||
this.type === "*" ||
(this.type.startsWith("~") && this.type.slice(1) !== node.type)
);
}
}