r5231 - trunk/varnish-cache/doc/sphinx/phk

phk at varnish-cache.org phk at varnish-cache.org
Tue Sep 21 21:17:27 CEST 2010


Author: phk
Date: 2010-09-21 21:17:26 +0200 (Tue, 21 Sep 2010)
New Revision: 5231

Added:
   trunk/varnish-cache/doc/sphinx/phk/vcl_expr.rst
Modified:
   trunk/varnish-cache/doc/sphinx/phk/index.rst
Log:
Give a rough outline of VCL expressions and operator precedence



Modified: trunk/varnish-cache/doc/sphinx/phk/index.rst
===================================================================
--- trunk/varnish-cache/doc/sphinx/phk/index.rst	2010-09-21 19:15:57 UTC (rev 5230)
+++ trunk/varnish-cache/doc/sphinx/phk/index.rst	2010-09-21 19:17:26 UTC (rev 5231)
@@ -8,6 +8,7 @@
 
 .. toctree::
 
+	vcl_expr.rst
 	ipv6suckage.rst
 	backends.rst
 	platforms.rst

Added: trunk/varnish-cache/doc/sphinx/phk/vcl_expr.rst
===================================================================
--- trunk/varnish-cache/doc/sphinx/phk/vcl_expr.rst	                        (rev 0)
+++ trunk/varnish-cache/doc/sphinx/phk/vcl_expr.rst	2010-09-21 19:17:26 UTC (rev 5231)
@@ -0,0 +1,87 @@
+.. _phk_vcl_expr:
+
+===============
+VCL Expressions
+===============
+
+I have been working on VCL expressions recently, and we are approaching
+the home stretch now.
+
+The data types in VCL are "sort of weird" seen with normal programming
+language eyes, in that they are not "general purpose" types, but
+rather tailored types for the task at hand.
+
+For instance, we have both a TIME and a DURATION type, a quite
+unusual constellation for a programming language.
+
+But in HTTP context, it makes a lot of sense, you really have to
+keep track of what is a relative time (age) and what is absolute
+time (Expires).
+
+Obviously, you can add a TIME and DURATION, the result is a TIME.
+
+Equally obviously, you can not add TIME to TIME, but you can subtract
+TIME from TIME, resulting in a DURATION.
+
+VCL do also have "naked" numbers, like INT and REAL, but what you
+can do with them is very limited.  For instance you can multiply a
+duration by a REAL, but you can not multiply a TIME by anything.
+
+Given that we have our own types, the next question is what
+precedence operators have.
+
+The C programming language is famous for having a couple of gottchas
+in its precedence rules and given our limited and narrow type
+repetoire, blindly importing a set of precedence rules may confuse
+a lot more than it may help.
+
+Here are the precedence rules I have settled on, from highest to
+lowest precedence:
+
+Atomic
+	'true', 'false', constants
+
+	function calls
+
+	variables
+
+	'(' expression ')'
+
+Multiply/Divide
+	INT * INT
+
+	INT / INT
+
+	DURATION * REAL
+
+Add/Subtract
+	STRING + STRING
+
+	INT +/- INT
+
+	TIME +/- DURATION
+
+	TIME - TIME
+
+	DURATION +/- DURATION
+
+Comparisons
+	'==', '!=', '<', '>', '~' and '!~'
+
+	string existence check (-> BOOL)
+
+Boolean not
+	'!'
+
+Boolean and
+	'&&'
+
+Boolean or
+	'||'
+
+
+Input and feedback most welcome!
+
+Until next time,
+
+Poul-Henning, 2010-09-21




More information about the varnish-commit mailing list