在sublime-text 3中,从Tools > Developer > New Syntax ...的菜单中,我找到了这个默认代码
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
file_extensions:
- ec
scope: source.example-c
contexts:
main:
# Strings begin and end with quotes, and use backslashes as an escape
# character
- match: '"'
scope: punctuation.definition.string.begin.example-c
push: double_quoted_string
# Comments begin with a '//' and finish at the end of the line
- match: '//'
scope: punctuation.definition.comment.example-c
push: line_comment
# Keywords are if, else for and while.
# Note that blackslashes don't need to be escaped within single quoted
# strings in YAML. When using single quoted strings, only single quotes
# need to be escaped: this is done by using two single quotes next to each
# other.
- match: '\b(if|else|for|while)\b'
scope: keyword.control.example-c
# Numbers
- match: '\b(-)?[0-9.]+\b'
scope: constant.numeric.example-c
double_quoted_string:
- meta_scope: string.quoted.double.example-c
- match: '\\.'
scope: constant.character.escape.example-c
- match: '"'
scope: punctuation.definition.string.end.example-c
pop: true
line_comment:
- meta_scope: comment.line.example-c
- match: $
pop: true它默认捕获的是双引号,通过
- match: '"'
scope: punctuation.definition.string.begin.example-c
push: double_quoted_string和
double_quoted_string:
- meta_scope: string.quoted.double.example-c
- match: '\\.'
scope: constant.character.escape.example-c
- match: '"'
scope: punctuation.definition.string.end.example-c
pop: true如果我在代码中添加以下代码:
- match: ''''
scope: punctuation.definition.string.begin.example-c
push: single_quoted_string和
single_quoted_string:
- meta_scope: string.quoted.single.example-c
- match: '\\.'
scope: constant.character.escape.example-c
- match: '"'
scope: punctuation.definition.string.end.example-c
pop: true当双引号包含在单引号内时,结果不会很好:

我怎么才能修复它呢?
发布于 2020-03-17 03:48:08
将您的规则更改为:
- match: "'"
scope: punctuation.definition.string.begin.example-c
push: single_quoted_string还有这个
single_quoted_string:
- meta_scope: string.quoted.single.example-c
- match: '\\.'
scope: constant.character.escape.example-c
- match: "'"
scope: punctuation.definition.string.end.example-c
pop: trueYAML既可以处理单引号,也可以处理双引号,所以如果需要在正则表达式中使用其中一个,请使用另一个将正则表达式括起来。
https://stackoverflow.com/questions/60666584
复制相似问题