Skip to content
Snippets Groups Projects
Commit 0de60b4a authored by Reeves, David E's avatar Reeves, David E
Browse files

* get vars functionality

parent 77b35f24
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ using System.IO.Compression;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
......@@ -19,6 +20,7 @@ namespace CodeCompleteTool
public static bool javaServer = false;
public static System.Diagnostics.Process process;
private static readonly Regex sWhitespace = new Regex(@"\s+");
public static void CloseJava()
{
......@@ -85,6 +87,78 @@ namespace CodeCompleteTool
return new object[] { new string[] { "Datamap not defined." }, new string[] { "Datamap not defined." } };
}
public static object[] GetLocalVars(HTNNode root)
{
List<string> varNames = new List<string>();
_GetLocalVars(root, varNames);
if (varNames.Count > 0)
{
List<object[]> res = new List<object[]>();
foreach (string varName in varNames)
{
res.Add(new string[] { "\""+varName+"\"" });
res.Add(new string[] { "Local variable '" + varName + "'" });
}
return res.ToArray();
}
else
return new object[] { new string[] { "No variables defined." }, new string[] { "No variables have defined yet." } };
}
static void _GetLocalVars(HTNNode node, List<string> varList)
{
if (node.CodeText != null && node.CodeText.Length > 0)
{
string srcTxt = node.CodeText.ToLower();
srcTxt = ReplaceWhitespace(srcTxt, "");
string token = "putvar(";
if (srcTxt.Contains("putvar("))
{
string[] tokens = srcTxt.Split(new string[] { token }, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length > 0)
{
foreach (string tok in tokens)
{
if (tok[0] == '\"')
{
int endIndex = 1;
for (; endIndex < tok.Length; endIndex++)
if (tok[endIndex] == '\"')
break;
string varName = tok.Substring(1, endIndex-1);
if (!varList.Contains(varName))
varList.Add(varName);
}
}
}
}
}
if (node.Nodes != null && node.Nodes.Count > 0)
{
List<TreeNode> tns = new List<TreeNode>();
List<HTNNode> htns = new List<HTNNode>();
foreach (TreeNode tn in node.Nodes)
{
tns.Add(tn);
htns.Add((HTNNode)tn);
}
foreach (HTNNode child in htns)
{
_GetLocalVars(child, varList);
}
}
}
public static string ReplaceWhitespace(string input, string replacement)
{
return sWhitespace.Replace(input, replacement);
}
public static object[] GetKillTypeNames()
{
string[] killTypeNames = new string[]
......
......@@ -263,6 +263,41 @@ namespace ScintillaPythonControl
keywordsHelp = (string[])res[1];
}
break;
case "VAR_NAME":
c = this;
root = null;
while (c != null)
{
if (c is HTNScintillaControl)
{
HTNScintillaControl hsc = (HTNScintillaControl)c;
root = hsc.HTNTree.RootNode;
}
c = c.Parent;
}
//if (root == null)
//{
// keywords = new string[] { "Unknown paramater" };
// keywordsHelp = new string[] { "Unknown parameter" };
//}
//else
//{
//res = CodeCompleteTools.GetParams(root);
res = CodeCompleteTools.GetLocalVars(root);
keywords = new string[res.Length / 2];
keywordsHelp = new string[res.Length / 2];
int k = 0;
for(int i=0;i<res.Length;i+=2)
{
keywords[k] = ((string[])res[i])[0];
keywordsHelp[k] = ((string[])res[i + 1])[0];
k++;
}
//}
break;
case "SENSOR_NAME":
res = ScenarioXML.GetSensors();
keywords = (string[])res[0];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment