Skip to content

Commit

Permalink
Fix lexing of names in R lexer (#896)
Browse files Browse the repository at this point in the history
The R lexer does not properly lex names with digits. This commit fixes that.
  • Loading branch information
fmichonneau authored and pyrmont committed Jul 30, 2019
1 parent 85cf976 commit 0975003
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/rouge/lexers/r.rb
Expand Up @@ -60,16 +60,15 @@ def self.detect?(text)
rule %r/%[^%]*?%/, Operator

rule %r/0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?/, Num::Hex
rule %r/[+-]?(\d+([.]\d+)?|[.]\d+)([eE][+-]?\d+)?[Li]?/,
Num
rule %r/[+-]?(\d+([.]\d+)?|[.]\d+)([eE][+-]?\d+)?[Li]?/, Num

# Only recognize built-in functions when they are actually used as a
# function call, i.e. followed by an opening parenthesis.
# `Name::Builtin` would be more logical, but is usually not
# highlighted specifically; thus use `Name::Function`.
rule %r/\b(?<!.)(#{PRIMITIVE_FUNCTIONS.join('|')})(?=\()/, Name::Function

rule %r/[a-zA-Z.]([a-zA-Z_][\w.]*)?/ do |m|
rule %r/(?:(?:[[:alpha:]]|[.][._[:alpha:]])[._[:alnum:]]*)|[.]/ do |m|
if KEYWORDS.include? m[0]
token Keyword
elsif KEYWORD_CONSTANTS.include? m[0]
Expand Down
2 changes: 2 additions & 0 deletions spec/visual/samples/r
Expand Up @@ -5,6 +5,8 @@

## Valid names
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV0123456789._a <- NULL
f2_bar <- NULL
F2_BAR <- NULL
.foo_ <- NULL
._foo <- NULL
. <- NULL
Expand Down

0 comments on commit 0975003

Please sign in to comment.