-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.common
More file actions
53 lines (49 loc) · 1.95 KB
/
sample.common
File metadata and controls
53 lines (49 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
###########################################################
# Example of Common Syntax suitable for testing Pygments.
# The program does not make much sense, it’s just a test.
# This comment block tests out end-of-line comments.
###########################################################
# This illustrates the keyword val, the := operator,
# function calls, whitespace, symbols and punctuation.
val name1 := cgiGet( 'name1' );
val name2 := cgiGet( 'name2' );
# This is a function definition which involves the
# define/enddefine keywords and the => punctuation.
define output() =>>
# Shows if/then/elseif/endif syntax and also
# strings and environment variable syntax.
if ${OUTPUT} = "html" then
# This illustrates the embedded XML syntax.
<html>
# Here we have text with interpolated expressions
# and an escaped HTML character entity.
#### Issue: string interpolation.
#### <title> "Welcome \(name1) \& \(name2)" </title>
<body>
</body>
</html>
elseif ${OUTPUT}... = "text"... then # Shows explodes.
# Loops, lists and vectors with numeric literals.
# Note use of parallel iteration operator.
{
#### Issue: parallel iterators
for i in [ 2, 3, 5, 7, 11 ] #### // n from 1
do
tmp := newVector( i, i );
# Some arithmetic operators.
if 2 * n > i + 1 then
# The other postfix function appl. syntax.
# Also the indexing operator.
n @factorise -> i[ 1 ]
endif
endfor
} =: v; # Reverse short declaration operator.
else
# Shows postfix function application.
throw UnexpectedValue return _ with (
"$OUTPUT has unexpected value",
'$OUTPUT' -> ${OUTPUT}
)
endif
enddefine;
output().println; # And postfix function application.