Sublimetext3 如何告诉sublime文本语法highlighter捕获单引号和双引号?
在升华文本3中,从Sublimetext3 如何告诉sublime文本语法highlighter捕获单引号和双引号?,sublimetext3,syntax-highlighting,Sublimetext3,Syntax Highlighting,在升华文本3中,从Tools>Developer>newsyntax…的菜单中,我找到了这个默认代码 %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
Tools>Developer>newsyntax…
的菜单中,我找到了这个默认代码
%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
及
如果我在代码中添加此项:
- match: ''''
scope: punctuation.definition.string.begin.example-c
push: single_quoted_string
及
当双引号位于单引号内时,结果并不理想:
如何解决此问题?将您的规则更改为:
-匹配:“”
范围:标点符号.definition.string.begin.example-c
推送:单引号字符串
还有这个
单引号字符串:
-元作用域:string.quoted.single.example-c
-匹配:'\\.'
范围:constant.character.escape.example-c
-匹配:“”
范围:标点符号.definition.string.end.example-c
波普:没错
YAML可以处理单引号和双引号,因此如果您需要在正则表达式中使用一个或另一个,请使用另一个来包围正则表达式。PS。我没有足够的分数来嵌入图像。
single\u quoted\u string
中检测字符串正在关闭的规则正在查找“
关闭字符串,即使它查找一个”
打开字符串。@OdatNurd,那么我如何修复它?您需要更新-match:”中的正则表达式“
使其匹配单引号而不是双引号。您在这里看到的问题是,您设置了单引号和双引号字符串,以便它们认为双引号结束了它们。因此,在一个带引号的字符串中,看到的第一个“
结束字符串,这就是您的图像显示的内容。@OdatNurd,我应该在更新代码的正则表达式中写什么?
- 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