~ubuntu-branches/debian/sid/varnish/sid

« back to all changes in this revision

Viewing changes to doc/sphinx/=build/html/_sources/phk/vcl_expr.txt

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-10-29 15:23:24 UTC
  • mfrom: (0.1.15)
  • Revision ID: package-import@ubuntu.com-20111029152324-tdtlsurrv22ysknj
Tags: 3.0.2-1
* New upstream release
* Build from upstream tarball instead of git tag
* debian/watch: more specific regular expression

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.. _phk_vcl_expr:
 
2
 
 
3
===============
 
4
VCL Expressions
 
5
===============
 
6
 
 
7
I have been working on VCL expressions recently, and we are approaching
 
8
the home stretch now.
 
9
 
 
10
The data types in VCL are "sort of weird" seen with normal programming
 
11
language eyes, in that they are not "general purpose" types, but
 
12
rather tailored types for the task at hand.
 
13
 
 
14
For instance, we have both a TIME and a DURATION type, a quite
 
15
unusual constellation for a programming language.
 
16
 
 
17
But in HTTP context, it makes a lot of sense, you really have to
 
18
keep track of what is a relative time (age) and what is absolute
 
19
time (Expires).
 
20
 
 
21
Obviously, you can add a TIME and DURATION, the result is a TIME.
 
22
 
 
23
Equally obviously, you can not add TIME to TIME, but you can subtract
 
24
TIME from TIME, resulting in a DURATION.
 
25
 
 
26
VCL do also have "naked" numbers, like INT and REAL, but what you
 
27
can do with them is very limited.  For instance you can multiply a
 
28
duration by a REAL, but you can not multiply a TIME by anything.
 
29
 
 
30
Given that we have our own types, the next question is what
 
31
precedence operators have.
 
32
 
 
33
The C programming language is famous for having a couple of gottchas
 
34
in its precedence rules and given our limited and narrow type
 
35
repetoire, blindly importing a set of precedence rules may confuse
 
36
a lot more than it may help.
 
37
 
 
38
Here are the precedence rules I have settled on, from highest to
 
39
lowest precedence:
 
40
 
 
41
Atomic
 
42
        'true', 'false', constants
 
43
 
 
44
        function calls
 
45
 
 
46
        variables
 
47
 
 
48
        '(' expression ')'
 
49
 
 
50
Multiply/Divide
 
51
        INT * INT
 
52
 
 
53
        INT / INT
 
54
 
 
55
        DURATION * REAL
 
56
 
 
57
Add/Subtract
 
58
        STRING + STRING
 
59
 
 
60
        INT +/- INT
 
61
 
 
62
        TIME +/- DURATION
 
63
 
 
64
        TIME - TIME
 
65
 
 
66
        DURATION +/- DURATION
 
67
 
 
68
Comparisons
 
69
        '==', '!=', '<', '>', '~' and '!~'
 
70
 
 
71
        string existence check (-> BOOL)
 
72
 
 
73
Boolean not
 
74
        '!'
 
75
 
 
76
Boolean and
 
77
        '&&'
 
78
 
 
79
Boolean or
 
80
        '||'
 
81
 
 
82
 
 
83
Input and feedback most welcome!
 
84
 
 
85
Until next time,
 
86
 
 
87
Poul-Henning, 2010-09-21