From db3f4c7d4aa1ecde6efa0a555f67db029c876ca6 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Mon, 18 Mar 2024 04:20:48 +0100 Subject: [PATCH] toml: only highlight inf and nan in value, highlight keys starting with digit (#2003) Fixes #1636 Fixes #1873 --- lib/rouge/lexers/toml.rb | 22 +++++++++++----------- spec/visual/samples/toml | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/rouge/lexers/toml.rb b/lib/rouge/lexers/toml.rb index 23ec389acf..8f12e996f5 100644 --- a/lib/rouge/lexers/toml.rb +++ b/lib/rouge/lexers/toml.rb @@ -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 @@ -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 diff --git a/spec/visual/samples/toml b/spec/visual/samples/toml index 10b351238a..84f20be0b8 100644 --- a/spec/visual/samples/toml +++ b/spec/visual/samples/toml @@ -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 +"""