summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Lyngstol <kly@kly.no>2016-02-08 19:42:36 +0100
committerKristian Lyngstol <kly@kly.no>2016-02-08 19:42:36 +0100
commit2a0288be69cdeaa747a5651297575ff0f3811484 (patch)
treec98a0b47ff191e4206873aa543fc6f7b267846b1
parente7647cf59896cea248079f89e53b3dc089247218 (diff)
downloadpygments-2a0288be69cdeaa747a5651297575ff0f3811484.tar.gz
Varnihs Lexer: Add various missing tokens
The lexing is a bit imprecise right now, but other than that I think the biggest missing parts right now is the inner workings of ACLs and vmods. It might be missing a few variables too. In general, the lexer is in need of some reorganizing to tidy things up.
-rw-r--r--pygments/lexers/varnish.py23
-rw-r--r--tests/examplefiles/varnish.vcl9
2 files changed, 26 insertions, 6 deletions
diff --git a/pygments/lexers/varnish.py b/pygments/lexers/varnish.py
index e8ee716b..0162f55f 100644
--- a/pygments/lexers/varnish.py
+++ b/pygments/lexers/varnish.py
@@ -52,8 +52,9 @@ class VCLLexer(RegexLexer):
(r'}',Punctuation,'#pop')
],
'statements': [
- (r'\d+[sdwhm]',Literal.Date),
- (r'[~!%^&*+=|?:<>/-]', Operator),
+ (r'\d+[sdwhmy]',Literal.Date),
+ (r'\d+ms',Literal.Date),
+ (r'[~!^&*+=|<>/-]', Operator),
(r'(hash_data)(\()(.+)(\)\s*;\s*$)',
bygroups(Keyword, Punctuation, using(this), Punctuation)),
(r'(set\s)([^\s]+)(\s*=\s*)(.+)(\s*;\s*)($|#.*$|//.*$|/\*.*$)',
@@ -72,18 +73,27 @@ class VCLLexer(RegexLexer):
'vcl_hit','vcl_miss','vcl_deliver','vcl_synth','vcl_backend_fetch',
'vcl_backend_response','vcl_backend_error','vcl_init','vcl_fini'),
suffix=r'\b'),Name.Function),
- (words(('if','else','elsif','synth',
+ (words(('if','else','elsif','elif','synth',
'synthetic'), suffix=r'\b'),Keyword),
+ (r'(new\s+)(\w+)(\s*=)(.*)(;)',
+ bygroups(Keyword.Namespace,Name.Variable.Global,Punctuation,Text,Punctuation)),
+ (r'(rollback\s*)(\(\s*\)\s*;)',
+ bygroups(Keyword,Punctuation)),
+ (r'storage\.\w+\.\w+\b', Name.Variable),
+ (r'(local|remote)\.ip\b', Name.Variable),
+ (r'now\b', Name.Variable),
(words(('true','false')),Name.Builtin),
(r'(call \s*)([^\s;]+)(;)',
bygroups(Keyword,Name.Variable.Global,Punctuation)),
(r'obj\.ttl',Name.Variable),
- (r'(req|bereq|obj|resp|beresp)\.http\.[^\s]+\b',Name.Variable),
- (r'(req|bereq)\.(url|method|xid)\b',Name.Variable),
+ (r'(req_top|req|bereq|obj|resp|beresp)\.http\.[^\s]+\b',Name.Variable),
+ (r'(req_top|req|bereq)\.(url|method|xid)\b',Name.Variable),
(r'(resp|beresp|obj)\.(status|reason)\b',Name.Variable),
(r'(beresp|obj)\.(ttl|grace)\b',Name.Variable),
(r'(backend)(\s+\w+)(\s*{)',
bygroups(Keyword, Name.Variable.Global, Punctuation), 'backend'),
+ (r'(ban\s*)(\()(.*)(\)\s*;)',
+ bygroups(Keyword,Punctuation,using(this),Punctuation)),
(r'(probe\s)(\s*\w+\s)({)',
bygroups(Keyword,Name.Variable.Global,Punctuation),'probe'),
(r'(acl\s)(\s*\w+\s)({)',
@@ -161,7 +171,8 @@ class VCLSnippetLexer(VCLLexer):
tokens = {
'snippetspre': [
(r'\<variable\>', Name.Variable),
- (r'\<value\>', Name.Variable)
+ (r'\<value\>', Name.Variable),
+ (r'\.\.\.+', Comment)
],
'snippetspost': [
(r'(req|bereq|obj|resp|beresp|client|server)(\.http)?\.\*\b',Name.Variable),
diff --git a/tests/examplefiles/varnish.vcl b/tests/examplefiles/varnish.vcl
index c14e1779..6258c313 100644
--- a/tests/examplefiles/varnish.vcl
+++ b/tests/examplefiles/varnish.vcl
@@ -23,6 +23,14 @@ include "foo.vcl";
import std;
+sub vcl_init {
+ new b = director.foo();
+}
+
+sub vcl_recv {
+ ban(req.url ~ "foo");
+ rollback();
+}
sub vcl_recv {
if (req.method == "PRI") {
/* We do not support SPDY or HTTP/2.0 */
@@ -96,6 +104,7 @@ sub vcl_miss {
}
sub vcl_deliver {
+ set resp.http.x-storage = storage.s0.free;
return (deliver);
}