本文介绍了如何在Sublime软件包开发YAML tmlanguage中匹配运算符分隔的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用PackageDevelopment的 .YAML-tmLanguage 在Sublime Text 2中为自定义语言进行语法定义.现在,我希望我的语法将字符串标识为非字符串.

I am making a syntax definition for a custom-made language in sublime text 2 using PackageDevelopment's .YAML-tmLanguage. For now I want my syntax to identify strings to non strings.

示例代码行:

string name = "Chuck Norris";
string message = "I am " + name + ", don't mess with a \"ROCKSTAR\"!";

我的双引号字符串模式:

my pattern for double quoted string:

- comment: strings in double quotes
  match: (".+")
  captures:
    '1': {name: string.quoted.double.me}

模式捕获的内容:

字符串名称= "Chuck Norris";
字符串消息= "I am " + name + ", don't mess with a "ROCKSTAR"!";

string name = "Chuck Norris";
string message = "I am " + name + ", don't mess with a "ROCKSTAR"!";

上面的第1行是正确的,但第2行似乎可以捕获所有内容.

line 1 above is correct but line 2 seems to capture all.

我想要的是:

字符串名称= "Chuck Norris";
字符串消息= "I am " +名称+ ", don't mess with a "ROCKSTAR"!";

string name = "Chuck Norris";
string message = "I am " + name + ", don't mess with a "ROCKSTAR"!";

推荐答案

我发现了一个很好的实现方法,该方法如何匹配用运算符分隔的字符串,以及如何使用YAML匹配双引号字符串和一些其他功能.

I discovered a good implementation on how to match operator-separated strings and also to match double quoted strings and some additional functionalities using YAML.

@WiktorStribiżewv的回答也解决了这个问题,但是我为此找到了一个很好的实现方式:

@Wiktor Stribiżewv's answer also fulfills the question but I found a good implementation for this:

- comment: strings in double quotes
  name: string.quoted.double.hit
  begin: \"
  end: \"
  patterns:
  - comment: escape characters
    name: constant.character.escape.hit
    match: \\.

  - comment: special characters
    name: constant.character.hit
    match: \%.

这也匹配\"\n等转义字符以及特殊字符%s%d

this also matches escape characters like \", \n and special characters %s, %d

这篇关于如何在Sublime软件包开发YAML tmlanguage中匹配运算符分隔的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:10