diff options
author | Kristian Lyngstol <kly@kly.no> | 2016-02-09 13:26:40 +0100 |
---|---|---|
committer | Kristian Lyngstol <kly@kly.no> | 2016-02-09 13:26:40 +0100 |
commit | 42b5a94660d635989248de5c2b93fa608ab2b861 (patch) | |
tree | 9772243409db2920a24ab877b8108095919a95a2 | |
parent | 2a0288be69cdeaa747a5651297575ff0f3811484 (diff) | |
download | pygments-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.py | 16 |
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)) |