11WT = WT or {}
2- WT .flag = {}
2+ WT .expressions = {}
33
44-- Utility: Split string by space
55local function split (str )
@@ -16,13 +16,13 @@ local function trim(s)
1616end
1717
1818-- Selection parser: returns a list of unit objects based on selectionExpr
19- function WT .flag .getCandidates (selectionExpr )
19+ function WT .expressions .getCandidates (selectionExpr )
2020 -- TODO: Implement unit selection logic using DCS API
2121 return {}
2222end
2323
2424-- Basic keyword handlers: fetch unit parameters
25- WT .flag .keywords = {
25+ WT .expressions .keywords = {
2626 AGL = function (unit ) return 0 end , -- TODO
2727 ASL = function (unit ) return 0 end , -- TODO
2828 SPEED = function (unit ) return 0 end , -- TODO
@@ -32,26 +32,26 @@ WT.flag.keywords = {
3232}
3333
3434-- Complex keyword registry
35- WT .flag .complexKeywords = {}
35+ WT .expressions .complexKeywords = {}
3636
3737-- Register a complex keyword with argument count and handler
38- function WT .flag .registerKeyword (name , argCount , handler )
39- WT .flag .complexKeywords [name ] = { argCount = argCount , handler = handler }
38+ function WT .expressions .registerKeyword (name , argCount , handler )
39+ WT .expressions .complexKeywords [name ] = { argCount = argCount , handler = handler }
4040end
4141
4242-- Replace logical operators with Lua equivalents
43- function WT .flag .normalizeOperators (expr )
43+ function WT .expressions .normalizeOperators (expr )
4444 expr = expr :gsub (" AND" , " and" )
4545 expr = expr :gsub (" OR" , " or" )
4646 expr = expr :gsub (" NOT" , " not" )
4747 return expr
4848end
4949
5050-- Preprocess complex keywords: replace with placeholders
51- function WT .flag .preprocessComplex (expr )
51+ function WT .expressions .preprocessComplex (expr )
5252 return expr :gsub (" ([A-Z]+%s*:?[%w_]*)" , function (term )
5353 local keyword , args = term :match (" ^(%w+)%s*(.*)$" )
54- local entry = WT .flag .complexKeywords [keyword ]
54+ local entry = WT .expressions .complexKeywords [keyword ]
5555 if entry then
5656 local argList = {}
5757 if args ~= " " then
@@ -71,9 +71,9 @@ function WT.flag.preprocessComplex(expr)
7171end
7272
7373-- Preprocess basic keywords: replace with placeholders
74- function WT .flag .preprocessKeywords (expr )
74+ function WT .expressions .preprocessKeywords (expr )
7575 return expr :gsub (" ([%u_]+)" , function (term )
76- if WT .flag .keywords [term ] then
76+ if WT .expressions .keywords [term ] then
7777 return " __KEYWORD_" .. term .. " __"
7878 else
7979 return term
@@ -82,17 +82,17 @@ function WT.flag.preprocessKeywords(expr)
8282end
8383
8484-- At construction, preprocess the expression
85- function WT .flag .new (selectionExpr , boolExpr , evalMode , threshold )
85+ function WT .expressions .new (selectionExpr , boolExpr , evalMode , threshold )
8686 local self = {
8787 selectionExpr = selectionExpr ,
8888 evalMode = evalMode or " ANY" ,
8989 threshold = threshold ,
9090 }
9191
9292 -- Preprocess expression: logical ops, complex, then basic keywords
93- local expr = WT .flag .normalizeOperators (boolExpr )
94- expr = WT .flag .preprocessComplex (expr )
95- expr = WT .flag .preprocessKeywords (expr )
93+ local expr = WT .expressions .normalizeOperators (boolExpr )
94+ expr = WT .expressions .preprocessComplex (expr )
95+ expr = WT .expressions .preprocessKeywords (expr )
9696 self .exprTemplate = expr
9797 self .complexTerms = {}
9898 self .basicTerms = {}
@@ -111,7 +111,7 @@ function WT.flag.new(selectionExpr, boolExpr, evalMode, threshold)
111111 local expr = self .exprTemplate
112112 -- Substitute complex term placeholders
113113 for _ , entry in ipairs (self .complexTerms ) do
114- local handlerEntry = WT .flag .complexKeywords [entry .keyword ]
114+ local handlerEntry = WT .expressions .complexKeywords [entry .keyword ]
115115 local argList = {}
116116 if entry .args ~= " " then
117117 for arg in string.gmatch (entry .args , " [^_]+" ) do
@@ -126,7 +126,7 @@ function WT.flag.new(selectionExpr, boolExpr, evalMode, threshold)
126126 end
127127 -- Substitute basic keyword placeholders
128128 for _ , entry in ipairs (self .basicTerms ) do
129- local value = tostring (WT .flag .keywords [entry .term ](unit ))
129+ local value = tostring (WT .expressions .keywords [entry .term ](unit ))
130130 expr = expr :gsub (entry .placeholder , value )
131131 end
132132 local ok , result = pcall (function () return loadstring (" return " .. expr )() end )
@@ -135,7 +135,7 @@ function WT.flag.new(selectionExpr, boolExpr, evalMode, threshold)
135135
136136 -- Evaluate the whole expression
137137 function self :evaluate ()
138- local candidates = WT .flag .getCandidates (self .selectionExpr )
138+ local candidates = WT .expressions .getCandidates (self .selectionExpr )
139139 local countTrue = 0
140140 local total = # candidates
141141 for _ , unit in ipairs (candidates ) do
@@ -164,17 +164,17 @@ function WT.flag.new(selectionExpr, boolExpr, evalMode, threshold)
164164end
165165
166166-- Example: Register a complex keyword
167- WT .flag .registerKeyword (" LOCKED" , 1 , function (unit , lockType )
167+ WT .expressions .registerKeyword (" LOCKED" , 1 , function (unit , lockType )
168168 -- TODO: Implement logic to check if unit is locked by lockType (e.g., RADAR)
169169 return false
170170end )
171171
172- WT .flag .registerKeyword (" PROX" , 2 , function (unit , coalition , unitType )
172+ WT .expressions .registerKeyword (" PROX" , 2 , function (unit , coalition , unitType )
173173 -- TODO: Implement logic to get proximity to specified coalition/unitType
174174 return 99999
175175end )
176176
177177-- Usage example (stub):
178- -- local expr = WT.flag .new("COALITION RED AIRCRAFT", "AGL > 500 AND LOCKED RADAR", "ANY")
178+ -- local expr = WT.expressions .new("COALITION RED AIRCRAFT", "AGL > 500 AND LOCKED RADAR", "ANY")
179179-- local result = expr:evaluate()
180180-- expr:setWhen("FlagX")
0 commit comments