Skip to content

Commit

Permalink
removing no more required codes
Browse files Browse the repository at this point in the history
making tables to local so that it will not expose in node definitions
  • Loading branch information
jharajeev55 committed Nov 22, 2024
1 parent 04cf64e commit f5b6fd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 40 deletions.
40 changes: 7 additions & 33 deletions Json_parser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ static void parse_commands_josn(string base_lib_dir, string json_file_path)
Console.WriteLine(cmdList.First());
var outStr = "---@meta\n\n";
int MAX_DEPT = 10;
var nodeTable = new HashSet<string>();
Dictionary<string, Dictionary<string, CommandInfo>>[] instrTable = new Dictionary<string, Dictionary<string, CommandInfo>>[MAX_DEPT];
for (int i = 0; i < MAX_DEPT; i++)
{
Expand Down Expand Up @@ -87,21 +86,7 @@ static void parse_commands_josn(string base_lib_dir, string json_file_path)
{
string s = cmd.name;
var tSplit = s.Contains(".") ? s.Trim().Split('.') : s.Trim().Split(':');
if (cmd.tsplink_supported.Contains("Yes"))
{
//if (tSplit[0] == "bufferVar")
//continue;
if (tSplit.Length > 1)
{
nodeTable.Add(tSplit[0] + " = " + tSplit[0]);
}
else
{
nodeTable.Add(s.Contains('(') ? s.Split('(')[0] + " = " + s.Split('(')[0] : s + " = " + s);
}
}



for (int i = 0; i < tSplit.Length - 1; i++)
{//ignore functions
string attr = null;
Expand All @@ -123,7 +108,7 @@ static void parse_commands_josn(string base_lib_dir, string json_file_path)

outStr += "---@class io_object\nlocal io_object={}\n---@class scriptVar\nlocal scriptVar={}\n---@class eventID\n\n---@class file_object\nlocal file_object ={}\n\n"; //PRIV
outStr += "---@class bufferVar\nlocal bufferVar={}\n";
outStr += "---@class digio\n digio = {}\n\n---@class tsplink\n tsplink = {}\n\n---@class lan\n lan = {}\n\n---@class tspnetConnectionID\nlocal tspnetConnectionID = {}\n\n ---@class promptID\nlocal promptID = {}\n\n";
outStr += "---@class digio\n local digio = {}\n\n---@class tsplink\n local tsplink = {}\n\n---@class lan\n local lan = {}\n\n---@class tspnetConnectionID\nlocal tspnetConnectionID = {}\n\n ---@class promptID\nlocal promptID = {}\n\n";

var tsplinkStr = "";
tsplinkStr = outStr;
Expand Down Expand Up @@ -168,11 +153,7 @@ static void parse_commands_josn(string base_lib_dir, string json_file_path)

}

nodeTable.Remove("node[N] = node[N]"); // for now removing this command from nodeTable because its creating problem in lua definitions
nodeTable.Remove("slot[slot] = slot[slot]"); // for now removing this command from nodeTable because its creating problem in lua definition




if (file_name.Contains("26"))
{

Expand All @@ -184,35 +165,28 @@ static void parse_commands_josn(string base_lib_dir, string json_file_path)
else // for tti models
{

nodeTable.Add("defbuffer1 = defbuffer1");
nodeTable.Add("defbuffer2 = defbuffer2");

}

var nodeTable_str = @"{" + string.Join(",\n ", nodeTable) + "\n}";
var node_class_name = Regex.Replace(file_name, @"[^a-zA-Z0-9_]", "");
var nodeTableDetails = $"---@meta\n\n---@class model{node_class_name}\nmodel{node_class_name} = {nodeTable_str}" +
$"\n--#region node details\n--#endregion";

var node_class_name = Regex.Replace(file_name, @"[^a-zA-Z0-9_]", "");

Directory.CreateDirectory(Path.Combine(base_lib_dir, model));
Directory.CreateDirectory(Path.Combine(base_lib_dir, model, "tspLinkSupportedCommands"));
Directory.CreateDirectory(Path.Combine(base_lib_dir, model, "AllTspCommands"));
Directory.CreateDirectory(Path.Combine(base_lib_dir, model, "Helper"));


var nodeTableFilePath = $"{base_lib_dir}/{model}/tspLinkSupportedCommands/nodeTable.lua";
var AllTspCommandsFilePath = $"{base_lib_dir}/{model}/AllTspCommands/" + file_name + ".lua";
var tspLinkSupportedCommandsFilePath = $"{base_lib_dir}/{model}/tspLinkSupportedCommands/" + file_name + "_TSPLink.lua";
var AllTspCommandsFilePath = $"{base_lib_dir}/{model}/AllTspCommands/definitions.lua";
var tspLinkSupportedCommandsFilePath = $"{base_lib_dir}/{model}/tspLinkSupportedCommands/definitions.txt";

var static_folder_Path = Path.Combine(base_lib_dir, model, "Helper");

Utility.CopyStaticFiles(model, static_folder_Path);

Utility.write_to_file(nodeTableFilePath, nodeTableDetails);
Utility.write_to_file(AllTspCommandsFilePath, outStr);
Utility.write_to_file(tspLinkSupportedCommandsFilePath, tsplinkStr);

Utility.SetFileReadOnly(nodeTableFilePath);
Utility.SetFileReadOnly(AllTspCommandsFilePath);
Utility.SetFileReadOnly(tspLinkSupportedCommandsFilePath);

Expand Down
14 changes: 7 additions & 7 deletions Json_parser/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ public static string PrintFields(int depth, string file_name, Dictionary<string,
var outStr = "";
if (forTspLink) // for tsplink node string needs to append in tables
{
NODE_STR = "node[2].";
NODE_ALIAS_STR = "node2_";
outStr += "node = {}\nnode[2] = {}\n";
NODE_STR = "node[$node_number$].";
NODE_ALIAS_STR = "node$node_number$_";
outStr += "node = {}\nnode[$node_number$] = {}\n";

}
else
Expand Down Expand Up @@ -179,7 +179,7 @@ public static string PrintFields(int depth, string file_name, Dictionary<string,
else
{
string rem = keyValuePair.Key.Replace(marker, "|").Split('|')[1];
class_data += type_name + rem + " = {}\n";
class_data += $"{type_name}{rem} = {{}}\n";
table_name = $"{type_name}{rem}";
}
is_array = true;
Expand All @@ -191,7 +191,7 @@ public static string PrintFields(int depth, string file_name, Dictionary<string,
{
table_name = NODE_STR + keyValuePair.Key;
class_data += "---@class " + keyValuePair.Key + "\n";
class_data += table_name + " = {}\n";
class_data += $"{table_name} = {{}}\n";
}

outStr += class_data;
Expand Down Expand Up @@ -319,7 +319,7 @@ public static string HelpContent_for_nodes(KeyValuePair<string, CommandInfo> com


var function_name = command.Key.Replace("(", "").Replace(")", "");
command_help += $"function {function_name}({cmd.signature.Substring(start, end - start)}) end\n";
command_help += $"local function {function_name}({cmd.signature.Substring(start, end - start)}) end\n";
command_help += $"{table}.{function_name} = { function_name}\n";
}

Expand Down Expand Up @@ -777,7 +777,7 @@ public static string create_tspLinkNode_enum_alias_type(ParamInfo param)
command_help += $"\n---@alias {NODE_ALIAS_STR}{aliasName}\n";
foreach (var data in enum_data)
{
command_help += $"---|`{NODE_STR}{data.Split(' ')[0]}`\n ";
command_help += $"---|`{NODE_STR}{data.Split(' ')[0]}`\n";
}
command_help += "\n";

Expand Down

0 comments on commit f5b6fd6

Please sign in to comment.