-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new R pipe support #127
Conversation
token types are PIPE and PIPEBIND
This comment was marked as resolved.
This comment was marked as resolved.
R/highlight.R
Outdated
"'$'", "'@'","'~'", "'?'", "':'", "SPECIAL" | ||
"'$'", "'@'","'~'", "'?'", "':'", "SPECIAL", | ||
# pipes | ||
"PIPE", "PIPEBIND", "PLACEHOLDER" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, are you sure PLACEHOLDER
should be treated as infix? I would think it should maybe just go in special
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This _
felt more like an operator to me (with +
, -
, <
, >
...) than a special like function()
, switch()
or other.
Among KDE default style, dsOperator
seemed the closest. dsConstant
was my second choice but it is supposed to be Number related.
However, I am ok to apply dsKeyword
- I don't mind changing.
However, out of curiosity, I compared with other languages which have placeholder and it seems they are not highlighted specifically.
```scala
val f = _ + _
```
<div class="sourceCode" id="cb1">
<pre class="sourceCode scala"><code class="sourceCode scala">
<span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>
<span class="kw">val</span> f <span class="op">=</span> _ <span class="op">+</span> _
</span>
</code></pre>
</div>
and
```python
for _ in range(10):
print "hello"
```
<div class="sourceCode" id="cb1">
<pre class="sourceCode python"><code class="sourceCode python">
<span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>
<span class="cf">for</span> _ <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">10</span>):</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span> <span class="st">"hello"</span>
</span>
</code></pre>
</div>
Does not seem like current KDE file does a special treatment for this _
as placeholder character.
Highlight JS also does nothing special for the above snipper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm maybe we should just treat it as a SYMBOL
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"'$'", "'@'","'~'", "'?'", "':'", "SPECIAL" | ||
"'$'", "'@'","'~'", "'?'", "':'", "SPECIAL", | ||
# pipes | ||
"PIPE", "PIPEBIND" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant you should do the transformation in this function, so we only need to do it in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok. I was under the impression you did associate some token classes from R parsed data to some chroma or pandoc classes directly. So I went with that for this one too as token_type()
seemed to handle special grouping of some token type in infix
, special
, constant
and parens
groups.
I'll adapt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the change, hopefully I got it right. I did not went with that originally because you went with separate attributions for other types by duplicating
Lines 228 to 230 in 8434f36
"SLOT" = "va", | |
"SYMBOL" = "va", | |
"SYMBOL_FORMALS" = "va", |
Lines 254 to 256 in 8434f36
"SLOT" = "nv", | |
"SYMBOL" = "nv", | |
"SYMBOL_FORMALS" = "nv", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that's reasonable read — I think this is different because PLACEHOLDER
is only a single token so it makes more sense to lump it into one of the other classes.
This PR closes #126
Parsing shows that token are
PIPE
andPIPEBIND
I have put them in the
infix
category with the magrittr pipe.For new placeholder we have
PLACEHOLDER
tokenNot sure which highlight class it should have. Proposal in operator too for this one.
Added tests dependent on R requirement. Snapshots seems ok to use here.