From fce7d0a2dd58046b6d48aff7e6c7059c90d0ac22 Mon Sep 17 00:00:00 2001 From: Amr Hesham Date: Tue, 7 Mar 2023 11:15:03 +0200 Subject: Improve number regex and add lexer guess for carbon syntax (#2370) --- pygments/lexers/carbon.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'pygments') diff --git a/pygments/lexers/carbon.py b/pygments/lexers/carbon.py index adc5ff38..b7f1ab9b 100644 --- a/pygments/lexers/carbon.py +++ b/pygments/lexers/carbon.py @@ -53,10 +53,11 @@ class CarbonLexer(RegexLexer): (r'(auto|bool|string|i8|i16|i32|i64|u8|u16|u32|u64|' r'f8|f16|f32|f64)\b', Keyword.Type), # numeric literals - (r'[0-9]*[.][0-9]+', Number.Double), - (r'0b[01]+[sl]?', Number.Bin), - (r'0o[0-7]+[sl]?', Number.Oct), - (r'[0-9]+', Number.Integer), + (r'[0-9]*[.][0-9]+?', Number.Double), + (r'0b[01]+?', Number.Bin), + (r'0o[0-7]+?', Number.Oct), + (r'0x[0-9a-fA-F]+?', Number.Hex), + (r'[0-9]+?', Number.Integer), # string literal (r'"(\\.|[^"\\])*"', String), # char literal @@ -69,3 +70,27 @@ class CarbonLexer(RegexLexer): (r'[^\W\d]\w*', Name.Other), ] } + + def analyse_text(text): + result = 0 + if 'forall' in text: + result += 0.1 + if 'type' in text: + result += 0.1 + if 'Self' in text: + result += 0.1 + if 'observe' in text: + result += 0.1 + if 'package' in text: + result += 0.1 + if 'library' in text: + result += 0.1 + if 'choice' in text: + result += 0.1 + if 'addr' in text: + result += 0.1 + if 'constraint' in text: + result += 0.1 + if 'impl' in text: + result += 0.1 + return result \ No newline at end of file -- cgit v1.2.1