summaryrefslogtreecommitdiff
path: root/pygments
diff options
context:
space:
mode:
authorAmr Hesham <amr96@programmer.net>2023-03-07 11:15:03 +0200
committerGitHub <noreply@github.com>2023-03-07 10:15:03 +0100
commitfce7d0a2dd58046b6d48aff7e6c7059c90d0ac22 (patch)
treed3d1dec5dbc18dd462b0d2e853f8c89e21831850 /pygments
parente61ffd96840c8a04b0556746fcfe8d7704ef6780 (diff)
downloadpygments-git-fce7d0a2dd58046b6d48aff7e6c7059c90d0ac22.tar.gz
Improve number regex and add lexer guess for carbon syntax (#2370)
Diffstat (limited to 'pygments')
-rw-r--r--pygments/lexers/carbon.py33
1 files changed, 29 insertions, 4 deletions
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