Greetings. I am trying to do syntax highlighting on a multi-line shell script.
But I find it different from what I just think.
Here’s my .sublime-syntax and a testcase (an ‘echo’ with some 'cd’s).
[code]%YAML1.2
See http://www.sublimetext.com/docs/3/syntax.html
file_extensions:
- myTest
scope: source.myTest
contexts:
main:- match: ‘echo’
scope: support.function.builtin.shell
push: echoMatched - match: ‘cd’
scope: support.function.external.shell
echoMatched: - match: ‘\$’
scope: keyword - match: ‘(?<!\)$’
pop: true[/code]echo cd \ cd cd
- match: ‘echo’
Here’s what I think.
At first, we meet an ‘echo’ which matches ‘echo’ in the ‘main’ context, so ‘echo’ is highlighted due to ‘support.function.builtin.shell’ and ‘echoMatched’ is now pushed to the top of the stack.
After that, we meet a ‘cd’. It’s not matched in the ‘echoMatched’ context, so it won’t be highlighted.
After that, we meet a backslash at the line ending which matches ‘\$’ in the ‘echoMatched’ context so it would be highlighted due to ‘keyword.’
After that, we go to the second line and meet the 2nd ‘cd’ but we still in the ‘echoMatched’ context, it won’t be highlighted.
After that, we meet the end of the 2nd line which matches ‘(?<!\)$’, so ‘echoMatched’ is popped and ‘main’ is on the top of the stack.
After that, we go to the third line and meet the 3rd ‘cd’ which matches ‘cd’ in the ‘main’ context so it would be highlighted.
As a result, it should look like this.
But actually I got this.
What do I misunderstand?
How to make it in the right way?