提交 1ee51b18 编写于 作者: C Christoph Seitz

Add support for parsing transformations in placeholders.

上级 98d7de04
...@@ -246,6 +246,15 @@ export class Placeholder extends Marker { ...@@ -246,6 +246,15 @@ export class Placeholder extends Marker {
: undefined; : undefined;
} }
get transform(): Transform {
for (const child of this._children) {
if (child instanceof Transform) {
return child as Transform;
}
}
return undefined;
}
toTextmateString(): string { toTextmateString(): string {
if (this.children.length === 0) { if (this.children.length === 0) {
return `\$${this.index}`; return `\$${this.index}`;
...@@ -482,6 +491,9 @@ export class TextmateSnippet extends Marker { ...@@ -482,6 +491,9 @@ export class TextmateSnippet extends Marker {
let ret = 0; let ret = 0;
walk([marker], marker => { walk([marker], marker => {
ret += marker.len(); ret += marker.len();
if (marker instanceof Transform) {
return false;
}
return true; return true;
}); });
return ret; return ret;
...@@ -690,10 +702,17 @@ export class SnippetParser { ...@@ -690,10 +702,17 @@ export class SnippetParser {
// ${1:<children>} // ${1:<children>}
while (true) { while (true) {
// ...} -> done
if (this._accept(TokenType.CurlyClose)) { if (this._accept(TokenType.CurlyClose)) {
// ...} -> done
parent.appendChild(placeholder); parent.appendChild(placeholder);
return true; return true;
} else if (this._accept(TokenType.Forwardslash)) {
//../<regex>/<format>/<options>} -> transform
if (this._parseTransform(placeholder)) {
parent.appendChild(placeholder);
return true;
}
} }
if (this._parse(placeholder)) { if (this._parse(placeholder)) {
...@@ -722,6 +741,12 @@ export class SnippetParser { ...@@ -722,6 +741,12 @@ export class SnippetParser {
placeholder.appendChild(choice); placeholder.appendChild(choice);
parent.appendChild(placeholder); parent.appendChild(placeholder);
return true; return true;
} else if (this._accept(TokenType.Forwardslash)) {
// ...|/<regex>/<format>/<options>} -> transform
if (this._parseTransform(placeholder)) {
parent.appendChild(placeholder);
return true;
}
} }
} }
...@@ -729,6 +754,16 @@ export class SnippetParser { ...@@ -729,6 +754,16 @@ export class SnippetParser {
return false; return false;
} }
} else if (this._accept(TokenType.Forwardslash)) {
// ${1/<regex>/<format>/<options>}
if (this._parseTransform(placeholder)) {
parent.appendChild(placeholder);
return true;
}
this._backTo(token);
return false;
} else if (this._accept(TokenType.CurlyClose)) { } else if (this._accept(TokenType.CurlyClose)) {
// ${1} // ${1}
parent.appendChild(placeholder); parent.appendChild(placeholder);
...@@ -829,7 +864,7 @@ export class SnippetParser { ...@@ -829,7 +864,7 @@ export class SnippetParser {
} }
} }
private _parseTransform(parent: Variable): boolean { private _parseTransform(parent: Variable | Placeholder): boolean {
// ...<regex>/<format>/<options>} // ...<regex>/<format>/<options>}
let transform = new Transform(); let transform = new Transform();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册