Comments (3)
So, it worked on my full grammar (well, mostly, but I think where it is acting up is unrelated to this). I extended the test grammar and input to cover more nesting and cyclical cases, too, which worked.
The fix was indeed to step back from the whileCaptures
approach and instead have while
match just the captured level of indentation from the begin
and a look-ahead to see if the next character was another whitespace. Then, putting patterns
at the top level worked. The extended example:
Grammar:
{
"name": "Foo",
"scopeName": "source.foo",
"patterns": [
{ "include": "#foo" }
],
"repository": {
"foo": {
"name": "meta.foo",
"begin": "(\\s*)foo.*",
"while": "\\1(?=\\s)",
"patterns": [{ "include": "#bar" }, { "include": "#hmm" }]
},
"bar": {
"name": "meta.bar",
"begin": "(\\s*)bar.*",
"while": "\\1(?=\\s)",
"patterns": [{ "include": "#baz" }]
},
"baz": {
"name": "meta.baz",
"begin": "(\\s*)baz.*",
"while": "\\1(?=\\s)",
"patterns": [{ "include": "#foo" }, { "include": "#hmm" }]
},
"hmm": {
"name": "meta.hmm",
"begin": "(\\s*)hmm.*",
"while": "\\1(?=\\s)"
}
}
}
Input:
foo
bar
baz
foo
bar
baz
hmm
baz
baz
hmm
hmm
hmm
bar
baz
baz
biz
foo
hmm
The token inspector confirmed this works as I would expect, so regardless of what is going on with my full grammar I think the original issue was more in terms of my understanding of whileCaptures
(or apparently lack thereof) than the overall nested concept. Because of that, I am closing this issue under the assumption the wonkiness in my full grammar is not quite this issue either.
from vscode-textmate.
I agree, I believe what's happening here is the while is eating all the characters, e.g. #3
in the stuff below. (I'm just a random grammar/syntax maker BTW) That said I think it is still possible to nest them.
Here's a copy-paste of my personal documentation on while, which I think partly confirms what you saw in the source code.
The textmate "while" key has almost no documentation. I'm writing this to explain what little I know about it.
The good part
The "while" key is stronger than the "end" pattern, as soon as the while is over, it stops and most importantly, it cuts off any ranges that are still open. This is incredibly important because almost nothing else in textmate does this, and it is useful for stopping broken syntax.
I believe it was designed to match things like the python intentation-based block.
The bad part(s)
However, there are some caveats.
- The "while" pattern is line-based, not character-based. If you match a single character on a line, then the whole line is considered to be inside the pattern-range
- On each line, nothing will start being matched until the while pattern has been fully matched
- Once the while pattern matches, everything after the while pattern will be tagged using the patterns inside of the pattern-range (the included patterns)
(end)
I have no idea if any of that is intended behavior. That said, I think your issue is the first while consumes all the text on the line, so there's nothing left for the included patterns to even match against.
I would guess that changing it to match just the white space of one indent level, and then including bar as a regular include (rather than a whileCapture) would fix it. I don't think I've ever gotten the while captures to work, I usually just use a lookahead in the while, and then include a pattern that does the actual matching
from vscode-textmate.
Thanks for the response. Interestingly, Python does not use while
for this case (at least not the built-in support). Only a handful of built-ins use while
at all, and Markdown is the only one that does extensively (apart from searchResult
, which I assume is, well, related to the search feature).
Anyway, I went with capturing the full line and passing it into the whileCaptures
because generally how I have seen that work in other constructs (say, match
/captures
) is that the include
s can process the incoming as they need. That said, some of your thoughts triggered a different line of thinking, and I was able to do some adjustments to the test grammar to match the test input as I would expect. I will attempt to port that over to my real grammar and report back if it works.
from vscode-textmate.
Related Issues (20)
- Add Option to Format in often used match expression parts HOT 1
- Vscodes TextMate doesn't support the any scope selector `*` in `injections` HOT 2
- lacks of some type export on latest version
- Unable to exclude elements with "textmate" scope selectors in custom themes HOT 1
- Textmate engine bug for `\k<>` backreferences HOT 2
- Please add back IRawGrammar as top level export!
- YAML Syntax interprets IP-Style Strings as numbers HOT 1
- Tagging releases HOT 4
- Cannot read property 'INITIAL' of undefine.
- Consider using end pattern as bail out for embedded languages HOT 12
- Scopes on Recursive Regex Cause Problems
- Misclassification of PHP syntax tokens HOT 3
- Matching multiline text HOT 2
- How to find all local variables? HOT 2
- JSON grammar without `filePath` parsed incorrectly as PList
- How to make the embedded language have corresponding language id
- Clarification about concurrent tokenization using multiple themes
- PHPdoc highlighting issue HOT 1
- Incorrect 'no more matches'? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-textmate.