-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathenvironmentvariables.jim
50 lines (39 loc) · 2.48 KB
/
environmentvariables.jim
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
{@comment environmentvariables.jim}
DEFINE ALL THE ENVIRONMENT VARIABLES AS MACROS
Import this file to use the environment variable names as macros inside the Jamal source documentations.
The names and the values are fetched from the file {@java:class javax0.jamal.api.EnvironmentVariables}.
The name of the variables will be the name of the Java constant.
The value of the macro will be the value of the Java constants.
After importing this file (IMPORT and NOT INCLUDE!!!), you can use the variable names as user-defined macros in the documentation.
HOW THIS WORKS:
===============
First of all, the comment tells Jamal that the macro start and stop strings in this file are single braces.
This behavior is defined in the documentation.
It is a demonstration here, and also, it is simpler to use these characters as start and stop strings in this file.
Also, as this file is imported, free text is ignored.
It may slow down processing a bit.
A few microseconds.
The rest of the macros:
-----------------------
It is a bit tricky here, but if you want to learn Jamal usage to the full extent, you can learn from examples.
So here it is.
Let's go from the inside towards out.
We include the class file EnvironmentVariables.java in verbatim mode.
That means it does not get interpreted.
It is like copying the file's content and surrounding it with an ident macro.
After that, `killLines` keeps only the lines that match the pattern.
Essentially, the lines having `JAMAL_`something`_ENV` or `JAMAL_`something`_SYS` defined on it remain.
The `replaceLines` macro converts these lines to Jamal define macros.
Each define uses the variable's name and assigns to it the value of the variable.
Note that it also works for the system properties calculated during class initialization.
We use the `ident` macro to protect the replace string's macros from being executed/evaluated immediately.
It is a series of `define` macros, which should be evaluated afterwards to have the desired effect.
So the steps in short:
1. include the file verbatim
2. keep the important lines only
3. convert the lines to Jamal macro definitions
4. execute the macro definition lines to have the macros in the macro table
{#eval {#replaceLines {@ident replace="/.*public\\s+static\\s+final\\s+String\\s+(\\w+)\\s*=\\s*.*;/{#define $1={@java:field (format=`\\$value`)javax0.jamal.api.EnvironmentVariables#$1}}/"}
{#killLines keep pattern="^.*JAMAL_.*_ENV\\s*=.*$"
{@include [verbatim] ./jamal-api/src/main/java/javax0/jamal/api/EnvironmentVariables.java}
}}}