summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Morgan <me@chrismorgan.info>2015-05-22 11:01:34 +1000
committerChris Morgan <me@chrismorgan.info>2015-05-22 11:01:34 +1000
commitf8f9e8a74bce9174093129e91fe2c27389811d0a (patch)
tree6b686788c1b3abd0b7484d35fcada1d0696a59eb
parent21dd706774a3cfbe9514ef8ac57c6656b48b5c0e (diff)
downloadpygments-f8f9e8a74bce9174093129e91fe2c27389811d0a.tar.gz
Support shebangs in the Rust lexer.
I had forgotten about this obscure feature of Rust.
-rw-r--r--pygments/lexers/rust.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py
index df218e5d..2b6ff707 100644
--- a/pygments/lexers/rust.py
+++ b/pygments/lexers/rust.py
@@ -29,6 +29,12 @@ class RustLexer(RegexLexer):
tokens = {
'root': [
+ # rust allows a file to start with a shebang, but if the first line
+ # starts with #![ then it’s not a shebang but a crate attribute.
+ (r'#![^[\r\n].*$', Comment.Preproc),
+ default('base'),
+ ],
+ 'base': [
# Whitespace and Comments
(r'\n', Whitespace),
(r'\s+', Whitespace),