-
Notifications
You must be signed in to change notification settings - Fork 726
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
Improve R syntax highlighting #383
Conversation
Backtick delimited identifiers are names, not strings, and should be highlighted accordingly.
A backtick delimited name cannot contain backticks, and contains at least one character.
This fixes the recognition of `NULL.` as an identifier, rather than a constant followed by a dot.
Identifiers in R may contain any number of letters, digits, dots and underscores; their only constraint is that they may not start with an underscore.
Identifiers that start with a dot cannot immediately be followed by a number.
Having all constants in an array ensures fewer errors due to uniform handling; case in point: there was still a bug that would have highlighted `NA.` etc as a constant followed by a dot.
Regarding the highlighting of function names, several strategies are viable:
I’m not a fan of (1) since R’s functions are just normal identifiers, and thus it’s impossible to tell whether sum = a + b + c I can’t think of any good argument to suggest that I like (2) although it has unavoidable false negatives. For instance, it’s impossible to tell in general whether the |
Roxygen highlighting isn’t currently supported by the syntax highlighter, if I understand the list of tokens correctly: there’s no way of highlighting something as a keyword (or similar) inside a comment. I’ve reported this as a separate issue (#388). |
Although FWIW, recent versions of RStudio provide an option to allow users to opt-in for 2); however, in practice, it can be a bit visually noisy. https://github.com/rstudio/rstudio/blob/master/src/gwt/acesupport/acemode/r_highlight_rules.js might be useful for inspiration (although obviously not written in Ruby) |
@kevinushey Have a look at my most recent commit, which implements (2) after a fashion, though I intentionally chose to highlight primitive functions not as |
Looks good! Thanks for being the one to put in the work here :) I think highlighting primitives as |
Thanks for your work! This is released in v1.11.0. |
This PR adds the following features to the R lexer:
.r
...
(and in fact any combination of dots in identifiers) is a valid name, and not a keyword_
%
…%
are recognised, and may contain whitespacereturn
isn’t a keyword in R, it’s a normal identifier#'
are marked as doc commentsThe following improvements are still outstanding:
return
)?A separate lexer should be added to support the various flavours (RMarkdown and TeX) of Knitr. This is beyond the scope of this PR.