syntax: don't pick up chan chains (channel of channels) #678
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes the following wrong highlighting:
into:
This is a very weird error. We want to show an error if the chan
statement is in form of:
The correct form should be of course:
But for example, if we have a channel of channels (like below), the
selected piece of whitespace is also highlighted as an error
Because it's the part of
<- chan
, whereas we should not treat as anerror because we have two
chan<-
andchan<-
statements.To fix this, we add a
negative lookbehind
regex statement. It will notmatch a text if it's preceded with other text.
First let assemble the current regex for the case:
<- chan
(receive-only annotation), which is:
The first part is:
Here the pattern @<= matches with zero width if the preceding atom
matches just before what follows.
\s\+
means white space of at leastone character. So it matches whitespaces which precedes the
statement
<-
Now the second part is only useful with the first part. I've added the
placeholder to make it more readable:
First the pattern
\@=
means to match the preceding atom with zerowidth. So it will match the PLACEHOLDER till it finds a
chan
statement. Once it finds it, it doesn't proceed anymore. So we only
highlight the whitespaces between
<-
andchan
only if we have awhite space of at least one character
Finally we can introduce our fix now. We're going to pick the
<-
statemetn if it doesn't follow a
chan
. Sochan<-
should NOT triggeran error anymore, because we're not going to pick arrows in that form.
To match an arrow which doesn't follow a chan statement can be done via
a
negative lookbehind
, which is in the form of:This literally means: "Match
<-
only if it doesn't followchan
.We're going to use this pattern for the plain
<-
pattern. Not we'rejust going to replace this into our current regex:
This original regex:
will be changed into:
Fixes #655