Hi everyone, I wonder if I can do the thing said in the topic?
The example is:
from "file" import abc
That’s not Python, that’s my own language.
So, what I need is:
- Consider ‘from’ as a keyword only if it is followed by ‘import’ at some point (at least at the same line for simplicity)
- After ‘from’ there goes an expression – that’s why we need to pop out the
keyword.control.import
context. - After the expression there goes an ‘import’ keyword. It is the standard keyword.
- After ‘import’ there goes another expression which shouldn’t be in this context too.
How my current context looks:
import_stmt:
- match: '\bimport\b'
scope: keyword.control.import
- match: '(\bfrom\b)\s*(.*?)\s*(\bimport\b)'
captures:
1: keyword.control.import
2: ???
3: keyword.control.import
I don’t know how to put a second capture out of current context (that is to highlight it separately, if there’s an indentifier between ‘from’ and ‘import’, highlight it as an identifier anywhere else in the code; if there’s a string, highlight if as a string).
Is it even possible? If not, can you please enable the option to make the element in the ‘captures’ array be possibly of the type ‘match’ as well as ordinary strings?
Then I would fix it something like that:
import_stmt:
- match: '\bimport\b'
scope: keyword.control.import
- match: '(\bfrom\b)\s*(.*?)\s*(\bimport\b)'
captures:
1: keyword.control.import
2:
- pop: true # or idk something like that to pop off the current context and highlight it separately???
3: keyword.control.import
Thanks in advance for any helpful advice!