我敢肯定,我已經想通了。以前我不明白的是該範圍如何工作。我仍然不完全理解它,但我現在已經足夠了解每種語法的begin
和end
的嵌套定義(正則表達式)。
作用域使事情所以更容易!之前我想做(?<=\A#'\s.*)(\$)
之類的正則表達式,在#'
式樣的評論中找到美元符號......但顯然這不會起作用,因爲*
(+
因爲同樣的原因而不起作用)的重複。通過範圍界定,它已經暗示我們必須在\A#'\s
比賽中進行比賽,之後纔會匹配\$
。
這裏是我的語言語法的相關部分:
{ begin = '(^[ \t]+)?(?=#\'')';
end = '(?!\G)';
beginCaptures = { 1 = { name = 'punctuation.whitespace.comment.leading.r'; }; };
patterns = (
{ name = 'comment.line.number-sign-tick.r';
begin = "#' ";
end = '\n';
beginCaptures = { 0 = { name = 'punctuation.definition.comment.r'; }; };
patterns = (
// Markdown within Comment
{ name = 'comment.line.number-sign-tick-raw.r';
begin = '(`)(?!\s)'; // backtick not followed by whitespace
end = '(?<!\s)(`)'; // backtick not preceded by whitespace
beginCaptures = { 0 = { name = 'punctuation.definition.comment.r'; }; };
},
// Equation within comment
{ name = 'comment.line.number-sign-tick-eqn.r';
begin = '((?<!\G)([\$]{1,2})(?!\s))';
end = '(?<!\s)([\$]{1,2})';
beginCaptures = { 0 = { name = 'punctuation.definition.comment.r'; }; };
// Markdown within Equation
patterns = (
{ name = 'comment.line.number-sign-tick-raw.r';
begin = '(`)(?!\s)'; // backtick not followed by whitespace
end = '(?<!\s)(`)'; // backtick not preceded by whitespace
beginCaptures = { 0 = { name = 'punctuation.definition.comment.r'; }; };
},
);
},
);
},
);
},
這裏是一些R代碼裏面:
# below is a `knitr` (note no effect of backticks) code chunk
#+ codeChunk, include=FALSE
# normal R comment, follow by code
data <- matrix(rnorm(6,3, sd=7), nrow=2)
#' This would be recognized as markdown by `knitr::spin()`, with the preceding portion as "raw" text
`note that this doesnt go to the 'raw' format ... it is normal code!`
#+ anotherChunk
# also note how the dollar signs behave normally
data <- as.list(data)
data$blah <- "blah"
`data`[[1]] # backticks behaving
#' I can introduce a Latex-style equation, filling in values from R using `knitr` code chunks: $\frac{top}{bottom}=\frac{`r topValue`}{`r botValue`}$ then continue on with markdown.
這裏是什麼樣子的TextMate2這些更改後:
相當不錯,除了被挑選出來的棋子在方程式裏面時,它們會以斜體顯示。我可以忍受這一點。我甚至可以說服自己,我是這樣想的;)(順便說一句,我指定fontName='regular'
爲快遞新,所以我不知道爲什麼這是越來越重)