Files
tia-lsp/src/builtin_instructions.lua
T
lazar 553192e7a1 feat: improve tree-sitter syntax highlighting with named nodes
- Add aliases for keywords (VAR_INPUT, BEGIN, IF, etc.) as named nodes
- Add aliases for built-in types (INT, BOOL, STRING, etc.) as type_builtin
- Add aliases for constants (TRUE, FALSE)
- Add aliases for operators (AND, OR, NOT, MOD)
- Add prefix node for # variable prefix highlighting
- Highlight FB instance names in calls
- Highlight FB parameter names as properties
- Update README with detailed syntax highlighting features
- Update .gitignore for *.wasm files
2026-02-20 23:29:26 +01:00

311 lines
11 KiB
Lua

local M = {}
M.FUNCTIONS = {
ADD = true,
SUB = true,
MUL = true,
DIV = true,
MOD = true,
ABS = true,
NEG = true,
SQR = true,
SQRT = true,
EXP = true,
LN = true,
LOG = true,
SIN = true,
COS = true,
TAN = true,
ASIN = true,
ACOS = true,
ATAN = true,
MIN = true,
MAX = true,
LIMIT = true,
CALCULATE = true,
CONVERT = true,
ROUND = true,
TRUNC = true,
CEIL = true,
FLOOR = true,
SCALE_X = true,
NORM_X = true,
LEN = true,
CONCAT = true,
LEFT = true,
RIGHT = true,
MID = true,
INSERT = true,
DELETE = true,
REPLACE = true,
FIND = true,
AND = true,
OR = true,
XOR = true,
NOT = true,
SHL = true,
SHR = true,
ROL = true,
ROR = true,
DECO = true,
ENCO = true,
BCD_I = true,
I_BCD = true,
DI_BCD = true,
DI_R = true,
I_DI = true,
R_DI = true,
R_DB = true,
MOVE = true,
FILL = true,
SWAP = true,
PEEK = true,
POKE = true,
GET_ERROR = true,
GET_ERR_ID = true,
RESET_ERR = true,
T_CONV = true,
T_ADD = true,
T_SUB = true,
T_DIFF = true,
T_COMBINE = true,
DT_DATE = true,
DT_TOD = true,
DATE_TO_DTL = true,
DTL_TO_DATE = true,
TOD_TO_DTL = true,
DTL_TO_TOD = true,
TimeToTicks = true,
TicksToTime = true,
GETHIGHNUM = true,
GETLOWNUM = true,
SAMPLE = true,
SAMPLE_TRIG = true,
WRIT_HIST = true,
READ_HIST = true,
COMPRESS = true,
READFILE = true,
WRITEFILE = true,
READ_DB = true,
WRITE_DB = true,
RDREC = true,
WRREC = true,
RALRM = true,
GET_DIAG = true,
DPRINT = true,
CTRL_PWM = true,
CTRL_PTO = true,
STATUS_PTO = true,
HOME = true,
MOVE_JOG = true,
MOVE_VEL = true,
MOVE_AXIS = true,
POS_PULSE = true,
POS_MC = true,
SET_CAM = true,
CAM_TB = true,
CAM_TE = true,
CAM_DOWN = true,
MC_CamIn = true,
MC_CamOut = true,
MC_Superimpose = true,
MC_GearIn = true,
MC_GearOut = true,
MC_Phasing = true,
MC_CombineAxes = true,
MC_Interpolate = true,
MC_MoveLinear = true,
MC_MoveCircular = true,
MC_MoveDirect = true,
MC_Home = true,
MC_Halt = true,
MC_Stop = true,
MC_Power = true,
MC_Reset = true,
MC_ReadParam = true,
MC_WriteParam = true,
MC_ReadAxisError = true,
MC_TouchProbe = true,
MC_AbortTrigger = true,
MC_ExtSetPointGen = true,
MC_Generator = true,
MC_BRIDGE = true,
MC_BRIDGE_OFF = true,
ENABLE = true,
DISABLE = true,
DISPLAY = true,
LOG_EVENT = true,
ALARM = true,
ALARM_DQ = true,
GET_ALARM = true,
GETINST = true,
GETALARMST = true,
CHANGEOVER = true,
REPLY_VALUE = true,
NOTIFY = true,
NOTIFY_WITH_ACK = true,
ASGEN = true,
HMI_R_DISCONNECT = true,
HMI_R_CONNECT = true,
HMI_R_SEND = true,
HMI_R_RECEIVE = true,
HMI_R_GET_STATE = true,
MODBUSPN = true,
MODBUSCP = true,
TSEND = true,
TRCV = true,
TCON = true,
TDISCON = true,
TSEND_C = true,
TRCV_C = true,
TUSEND = true,
TURCV = true,
TCONNECT = true,
TDISCONNECT = true,
GETHNSON = true,
DELHNSON = true,
DNS_CLIENT = true,
DHCP_CLIENT = true,
DCP_CLIENT = true,
}
M.FUNCTION_BLOCKS = {
TON = true,
TOF = true,
TP = true,
TONR = true,
CTU = true,
CTD = true,
CTUD = true,
IEC_TIMER = true,
IEC_TON = true,
IEC_TOF = true,
IEC_TP = true,
IEC_COUNTER = true,
IEC_CTU = true,
IEC_CTD = true,
IEC_CTUD = true,
R_TRIG = true,
F_TRIG = true,
SR = true,
RS = true,
SCHEDULE = true,
BPM = true,
LOG = true,
DATALOG = true,
}
M.DATA_TYPES = {
BOOL = true,
BYTE = true,
WORD = true,
DWORD = true,
LWORD = true,
CHAR = true,
WCHAR = true,
STRING = true,
WSTRING = true,
INT = true,
DINT = true,
LINT = true,
USINT = true,
SINT = true,
UINT = true,
UDINT = true,
ULINT = true,
REAL = true,
LREAL = true,
TIME = true,
DATE = true,
TOD = true,
TIME_OF_DAY = true,
DATE_AND_TIME = true,
DT = true,
S5TIME = true,
LTIME = true,
DTL = true,
}
M.PARAMETERS = {
TON = { inputs = { { name = "IN", type = "BOOL" }, { name = "PT", type = "TIME" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "ET", type = "TIME" } } },
TOF = { inputs = { { name = "IN", type = "BOOL" }, { name = "PT", type = "TIME" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "ET", type = "TIME" } } },
TP = { inputs = { { name = "IN", type = "BOOL" }, { name = "PT", type = "TIME" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "ET", type = "TIME" } } },
TONR = { inputs = { { name = "IN", type = "BOOL" }, { name = "PT", type = "TIME" }, { name = "R", type = "BOOL" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "ET", type = "TIME" } } },
CTU = { inputs = { { name = "CU", type = "BOOL" }, { name = "R", type = "BOOL" }, { name = "PV", type = "INT" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "CV", type = "INT" } } },
CTD = { inputs = { { name = "CD", type = "BOOL" }, { name = "LD", type = "BOOL" }, { name = "PV", type = "INT" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "CV", type = "INT" } } },
CTUD = { inputs = { { name = "CU", type = "BOOL" }, { name = "CD", type = "BOOL" }, { name = "R", type = "BOOL" }, { name = "LD", type = "BOOL" }, { name = "PV", type = "INT" } }, outputs = { { name = "QU", type = "BOOL" }, { name = "QD", type = "BOOL" }, { name = "CV", type = "INT" } } },
R_TRIG = { inputs = { { name = "CLK", type = "BOOL" } }, outputs = { { name = "Q", type = "BOOL" } } },
F_TRIG = { inputs = { { name = "CLK", type = "BOOL" } }, outputs = { { name = "Q", type = "BOOL" } } },
SR = { inputs = { { name = "S", type = "BOOL" }, { name = "R1", type = "BOOL" } }, outputs = { { name = "Q1", type = "BOOL" } } },
RS = { inputs = { { name = "S1", type = "BOOL" }, { name = "R", type = "BOOL" } }, outputs = { { name = "Q1", type = "BOOL" } } },
IEC_TIMER = { inputs = { { name = "IN", type = "BOOL" }, { name = "PT", type = "TIME" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "ET", type = "TIME" } } },
IEC_TON = { inputs = { { name = "IN", type = "BOOL" }, { name = "PT", type = "TIME" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "ET", type = "TIME" } } },
IEC_TOF = { inputs = { { name = "IN", type = "BOOL" }, { name = "PT", type = "TIME" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "ET", type = "TIME" } } },
IEC_TP = { inputs = { { name = "IN", type = "BOOL" }, { name = "PT", type = "TIME" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "ET", type = "TIME" } } },
IEC_COUNTER = { inputs = { { name = "CU", type = "BOOL" }, { name = "CD", type = "BOOL" }, { name = "R", type = "BOOL" }, { name = "LD", type = "BOOL" }, { name = "PV", type = "INT" } }, outputs = { { name = "QU", type = "BOOL" }, { name = "QD", type = "BOOL" }, { name = "CV", type = "INT" } } },
IEC_CTU = { inputs = { { name = "CU", type = "BOOL" }, { name = "R", type = "BOOL" }, { name = "PV", type = "INT" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "CV", type = "INT" } } },
IEC_CTD = { inputs = { { name = "CD", type = "BOOL" }, { name = "LD", type = "BOOL" }, { name = "PV", type = "INT" } }, outputs = { { name = "Q", type = "BOOL" }, { name = "CV", type = "INT" } } },
IEC_CTUD = { inputs = { { name = "CU", type = "BOOL" }, { name = "CD", type = "BOOL" }, { name = "R", type = "BOOL" }, { name = "LD", type = "BOOL" }, { name = "PV", type = "INT" } }, outputs = { { name = "QU", type = "BOOL" }, { name = "QD", type = "BOOL" }, { name = "CV", type = "INT" } } },
ADD = { inputs = { { name = "IN1" }, { name = "IN2" } }, outputs = { { name = "OUT" } } },
SUB = { inputs = { { name = "IN1" }, { name = "IN2" } }, outputs = { { name = "OUT" } } },
MUL = { inputs = { { name = "IN1" }, { name = "IN2" } }, outputs = { { name = "OUT" } } },
DIV = { inputs = { { name = "IN1" }, { name = "IN2" } }, outputs = { { name = "OUT" } } },
MIN = { inputs = { { name = "IN1" }, { name = "IN2" } }, outputs = { { name = "OUT" } } },
MAX = { inputs = { { name = "IN1" }, { name = "IN2" } }, outputs = { { name = "OUT" } } },
LIMIT = { inputs = { { name = "MN" }, { name = "IN" }, { name = "MX" } }, outputs = { { name = "OUT" } } },
MOVE = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
CONVERT = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
ROUND = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
TRUNC = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
CEIL = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
FLOOR = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
SQR = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
SQRT = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
SIN = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
COS = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
TAN = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
ASIN = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
ACOS = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
ATAN = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
LEN = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
CONCAT = { inputs = { { name = "IN1" }, { name = "IN2" } }, outputs = { { name = "OUT" } } },
LEFT = { inputs = { { name = "IN" }, { name = "L" } }, outputs = { { name = "OUT" } } },
RIGHT = { inputs = { { name = "IN" }, { name = "L" } }, outputs = { { name = "OUT" } } },
MID = { inputs = { { name = "IN" }, { name = "L" }, { name = "P" } }, outputs = { { name = "OUT" } } },
AND = { inputs = { { name = "IN1" }, { name = "IN2" } }, outputs = { { name = "OUT" } } },
OR = { inputs = { { name = "IN1" }, { name = "IN2" } }, outputs = { { name = "OUT" } } },
XOR = { inputs = { { name = "IN1" }, { name = "IN2" } }, outputs = { { name = "OUT" } } },
SHL = { inputs = { { name = "IN" }, { name = "N" } }, outputs = { { name = "OUT" } } },
SHR = { inputs = { { name = "IN" }, { name = "N" } }, outputs = { { name = "OUT" } } },
ROL = { inputs = { { name = "IN" }, { name = "N" } }, outputs = { { name = "OUT" } } },
ROR = { inputs = { { name = "IN" }, { name = "N" } }, outputs = { { name = "OUT" } } },
BCD_I = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
I_BCD = { inputs = { { name = "IN" } }, outputs = { { name = "OUT" } } },
}
function M.get_parameters(name)
return M.PARAMETERS[name:upper()]
end
function M.is_known_function(name)
return M.FUNCTIONS[name:upper()] or false
end
function M.is_known_function_block(name)
return M.FUNCTION_BLOCKS[name:upper()] or false
end
function M.is_known_data_type(name)
return M.DATA_TYPES[name:upper()] or false
end
function M.is_known_instruction(name)
return M.is_known_function(name) or M.is_known_function_block(name) or false
end
function M.is_known_type_or_instruction(name)
return M.is_known_data_type(name) or M.is_known_instruction(name) or false
end
return M