summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Lyngstol <kly@kly.no>2016-02-09 13:26:40 +0100
committerKristian Lyngstol <kly@kly.no>2016-02-09 13:26:40 +0100
commit42b5a94660d635989248de5c2b93fa608ab2b861 (patch)
tree9772243409db2920a24ab877b8108095919a95a2
parent2a0288be69cdeaa747a5651297575ff0f3811484 (diff)
downloadpygments-42b5a94660d635989248de5c2b93fa608ab2b861.tar.gz
Varnish Lexer: Add analyse_text()
It looks for documents starting with 'vcl 4.0;', optionally with comments preceding it. As all valid VCL as of Varnish 4.0 starts with this (even Varnish 4.1), this is pretty much guaranteed to work.
-rw-r--r--pygments/lexers/varnish.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/pygments/lexers/varnish.py b/pygments/lexers/varnish.py
index 0162f55f..d2d81f6d 100644
--- a/pygments/lexers/varnish.py
+++ b/pygments/lexers/varnish.py
@@ -28,6 +28,20 @@ class VCLLexer(RegexLexer):
filenames = [ '*.vcl' ]
mimetypes = ['text/x-vclsrc']
+ def analyse_text(text):
+ # If the very first line is 'vcl 4.0;' it's pretty much guaranteed
+ # that this is VCL
+ if re.search('^vcl 4\.0;\n', text):
+ return 1.0
+
+ # Skip over comments and blank lines
+ # This is accurate enough that returning 0.9 is reasonable.
+ # Almost no VCL files start without some comments.
+ if re.search('^((\s+)|(#[^\n]*\n)|(\n)|(\s*//[^\n]*\n)|(/\*[^*/]*\*/))*vcl 4\.0;', text):
+ return 0.9
+
+ return 0.0
+
tokens = {
'probe': [
(r'(\s*\.\w+)(\s*=\s*)([^;]*)(;)',
@@ -100,7 +114,7 @@ class VCLLexer(RegexLexer):
bygroups(Keyword,Name.Variable.Global,Punctuation),'acl'),
(r'[();]', Punctuation),
(r'(client|server)\.(ip|identity)\b',Name.Variable),
- (r'^(vcl )(4.0)(;)$',
+ (r'(vcl )(4.0)(;)$',
bygroups(Keyword.Reserved,Name.Constant,Punctuation)),
(r'(include\s+)("[^"]+"\s*)(;)',
bygroups(Keyword,String,Punctuation))