Skip to content

Commit

Permalink
toml: only highlight inf and nan in value, highlight keys starting wi…
Browse files Browse the repository at this point in the history
…th digit (#2003)

Fixes #1636
Fixes #1873
  • Loading branch information
arp242 committed Mar 18, 2024
1 parent 2fa465a commit db3f4c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/rouge/lexers/toml.rb
Expand Up @@ -23,17 +23,6 @@ class TOML < RegexLexer
groups Name::Property, Text, Operator, Text, Punctuation
push :inline
end

rule %r/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/, Literal::Date

rule %r/[+-]?\d+(?:_\d+)*\.\d+(?:_\d+)*(?:[eE][+-]?\d+(?:_\d+)*)?/, Num::Float
rule %r/[+-]?\d+(?:_\d+)*[eE][+-]?\d+(?:_\d+)*/, Num::Float
rule %r/[+-]?(?:nan|inf)/, Num::Float

rule %r/0x\h+(?:_\h+)*/, Num::Hex
rule %r/0o[0-7]+(?:_[0-7]+)*/, Num::Oct
rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
rule %r/[+-]?\d+(?:_\d+)*/, Num::Integer
end

state :root do
Expand All @@ -59,6 +48,17 @@ class TOML < RegexLexer
groups Name::Property, Text, Punctuation
end

rule %r/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/, Literal::Date

rule %r/[+-]?\d+(?:_\d+)*\.\d+(?:_\d+)*(?:[eE][+-]?\d+(?:_\d+)*)?/, Num::Float
rule %r/[+-]?\d+(?:_\d+)*[eE][+-]?\d+(?:_\d+)*/, Num::Float
rule %r/[+-]?(?:nan|inf)/, Num::Float

rule %r/0x\h+(?:_\h+)*/, Num::Hex
rule %r/0o[0-7]+(?:_[0-7]+)*/, Num::Oct
rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
rule %r/[+-]?\d+(?:_\d+)*/, Num::Integer

rule %r/"""/, Str, :mdq
rule %r/"/, Str, :dq
rule %r/'''/, Str, :msq
Expand Down
19 changes: 19 additions & 0 deletions spec/visual/samples/toml
Expand Up @@ -166,3 +166,22 @@ emptyTableAreAllowed = true
name = "Nail"
sku = 284758393
color = "gray"

[special-floats]
inflection = "don't highlight"
influxdb = 1

nan = nan

inf-1 = inf
inf-2 = [inf, +nan, -nan, +inf, -inf]
inf-3 = {inf=inf, nan=nan}

str-inf-1 = 'inf'
str-inf-2 = "inf"
str-inf-3 = """ inf nan
inf nan
"""
str-inf-4 = """ inf nan
inf nan
"""

0 comments on commit db3f4c7

Please sign in to comment.