-
Notifications
You must be signed in to change notification settings - Fork 0
/
README_unprocessed
101 lines (92 loc) · 2.83 KB
/
README_unprocessed
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Sed preprocesser
$msg $msg = This file was processed by the very sed script hosted in this repo.
Its syntax will be documented here. You should check the unprocessed version too, or else this will not make much sense.
The main functionality of this sed script is the declaration and substitution of variables. For this purpose there is an evaluator symbol, which can be one or more characters long. By default it is `$`. It can be redeclared anywhere in the processed file(s). $SED_EVALUATOR_SYMBOL=@
# Assignment
Values can be assigned to variables with the following syntax:
```
EVALUATOR_SYMBOL variable_name = value
```
All the whitespaces represented here may contain any number of spaces or tabs except for the one before value. There a single whitespace character is optionally consumed, but anything more than that will be stored in the variable.
Example:
```
$var = A variable's value can contain spaces. @var = A variable's value can contain spaces.
```
A variable may be evaluated as
```
EVALUATOR_SYMBOLvariable_name
```
Example:
```
$var
```
evaluates to
```
@var
```
The evaluator symbol can be changed by setting the SED_EVALUATOR_SYMBOL variable's value. (This has been done in the unprocessed version up until now so as not to evaluate the dollar signs so far.)
Example: @SED_EVALUATOR_SYMBOL=eval
```
$SED_EVALUATOR_SYMBOL=@
```
From this point on variables with $ in front of them will not be expanded. @ will be used for expansion. You can make this as long or shor as you wish. It may also contain whitespace characters.
Assignemnts following any text will leave the text alone. eval example = As you can see.
eval example
# The interesting part
Some more weird stuff also works.
Multiple layers of evaluation may be used. eval SED_EVALUATOR_SYMBOL=@
```
$var1 = 2
$var2 = var1
$var2
$$var2
```
will output
```
@var1=2
@var2 = var1
@var2
@@var2
```
Variables are expanded before assignment.
```
$var1 = 2
$var2 = $var1
$var2
$$var2
```
gives
```@SED_EVALUATOR_SYMBOL=$
$var1 = 2
$var2 = $var1
$var2
$$var2
```$SED_EVALUATOR_SYMBOL=@
Variables may store valid commands which may be executed by prefixing them with the evaluator symbol again. This can be used to delay execution.
```
$v1 = v2 = this works as expected
$v2
$$v1
$v2
```
Results in:
```@SED_EVALUATOR_SYMBOL=$
$v1 = v2 = this works as expected
$v2
$$v1
$v2
```$SED_EVALUATOR_SYMBOL=@
The following also works
```
$v2 = v2 = this works as expected
$$v2
$v2
```
Results in:
```@SED_EVALUATOR_SYMBOL=$
$v2 = v2 = this works as expected
$$v2
$v2
```$SED_EVALUATOR_SYMBOL=@
# Notes
If you do not wish to break the script in any way be careful whenever declaring any variables starting with SED_. The only two such value that are intended to be used and relied upon are `SED_PREPROC_VER` and `SED_EVALUATOR_SYMBOL`. SED_PREPROC_VER always expands into the current version fo the sed preprocessor script.