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?