Hello,
I am defining a syntax for a text file where a line is the child of the previous line with less indentation, like this:
- a
- b, child of a (because a has less indentation)
- c, child of b (because b has less indentation)
- d, child of b (not child of c, because c does not has less indentation)
- e, child of a (because a is the previous line with less indentation)
I would like to color the line “todo” and its children, meaning the following lines with a greater indentation.
In the example below, we would color the lines “todo” and “child of todo”
- hello
- todo
- child of todo
- child of todo
- child of todo
- NOT child of todo
It is the first time I make a syntax definition and I thought I should use the push/pop context, so I made this test below for the todo line that begin with 3 spaces (I am sorry, I added - characters everywhere, because the preview was removing all my indentation! And the preview removes the 3 spaces in match: ‘^ - todo’, between ^ and todo)
- contexts:
- main:
- match: ‘^ - todo’
- scope: todo
- push: todo
- todo:
- meta_scope: todo
- match: ^ {0,3}[^ ]
- pop: true
But I would like it to work with any number of spaces.
For example, if the todo line begin with 9 spaces, the todo context would end as soon as there is a line that begin with less than 9 spaces.
The number of spaces could be a parameter used in the match that pops the todo context.
I guess that languages like Python solved the same problem, to detect the end of a class or a function.
Do you have any idea to do it?
I used a push/pop context, but I would be happy to use any other solution!
Thank you!
PS: Besides, with my solution, in the example, the begin of line “NOT child of todo” is in the scope, and it should not.