-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompile_lua.tpa
53 lines (51 loc) · 2.29 KB
/
compile_lua.tpa
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
//Action function that lets you compile BAF and D files containing Bubb's EEex Lua functions (EEex_Lua, EEex_LuaTrigger)
//The function converts easy to read multiline Lua code into a single line syntax supported by weidu
//https://github.com/Bubb13/EEex/
//Example usage:
//LAF COMPILE_LUA STR_VAR path = ~someDir/someFile.baf~ END
//LAF COMPILE_LUA STR_VAR path = ~someDir~ END
DEFINE_ACTION_FUNCTION COMPILE_LUA
INT_VAR
eval = 1 //set to 0 to disable variable evaluation during compilation
STR_VAR
path = ~~ //can be either a single BAF/D file or directory where BAF and/or D files are located
quote = ~"~ //adjust quotation that you're using for EEex_Lua style functions (weidu supports following quotations: ", ~, %, ~~~~~)
BEGIN
OUTER_SPRINT newline ~%WNL%%LNL%%MNL%%TAB% ~
//create array of files to compile
ACTION_IF ((~%path%~ STRING_CONTAINS_REGEXP ~\.[BbDd][Aa]?[Ff]?$~) = 0) BEGIN
ACTION_DEFINE_ASSOCIATIVE_ARRAY files_array BEGIN ~%path%~ => ~~ END
END ELSE BEGIN
ACTION_BASH_FOR ~%path%~ ~^.+\.[bd]a?f?$~ BEGIN
ACTION_DEFINE_ASSOCIATIVE_ARRAY files_array BEGIN ~%BASH_FOR_FILESPEC%~ => ~~ END
END
END
//loop through files_array
ACTION_PHP_EACH files_array AS file => dummy BEGIN
PRINT ~Compilling %file%...~
COPY - ~%file%~ ~.../%file%~ //copy into inlined file
PATCH_IF ~%quote%~ STR_EQ "~~~~~" BEGIN
REPLACE_TEXTUALLY "~~~~~" "@"
SPRINT quote ~@~ //single character so that it can be captured with the same regexp code
END
PATCH_FOR_EACH function IN EEex_Lua EEex_LuaTrigger BEGIN //you can add more EEex_Lua style multi-line actions/triggers here if needed
REPLACE_EVALUATE CASE_INSENSITIVE ~%function%([%newline%]*%quote%[%newline%]*\([^%quote%]+\)[%newline%]*%quote%[%newline%]*)~ BEGIN
PATCH_PRINT ~Converting %function% code: %MATCH1%~
INNER_PATCH_SAVE MATCH1 ~%MATCH1%~ BEGIN //convert multi-line EEex_Lua style function content into single line
REPLACE_TEXTUALLY ~[%newline%]+~ ~ ~
REPLACE_TEXTUALLY ~^ ~ ~~
REPLACE_TEXTUALLY ~ $~ ~~
END
END ~%function%(%quote%%MATCH1%%quote%)~ //replace single-line function
END
PATCH_IF ~%quote%~ STR_EQ ~@~ BEGIN
REPLACE_TEXTUALLY ~@~ "~~~~~"
END
//compile inlined file
ACTION_IF eval = 1 BEGIN
COMPILE EVAL ~.../%file%~
END ELSE BEGIN
COMPILE ~.../%file%~
END
END
END