Skip to content

Commit a739113

Browse files
committed
Improved hxml parsing (ignores everything after --next when using raw hxml)
Fixed completion failing due to macros escaping. Fixes Chman/Snowkit-FD#8
1 parent 51d7c7f commit a739113

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

External/Plugins/HaXeContext/Completion/HaxeComplete.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ namespace HaXeContext
2020
internal class HaxeComplete
2121
{
2222
static readonly Regex reArg =
23-
new Regex("^(-cp)\\s*([^\"'].*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
23+
new Regex("^(-cp|-resource)\\s*([^\"'].*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
24+
static readonly Regex reMacro =
25+
new Regex("^(--macro)\\s*([^\"'].*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
26+
static readonly Regex reQuote =
27+
new Regex("([^\"])\"", RegexOptions.Compiled);
2428

2529
static readonly Regex rePosition =
2630
new Regex("(?<path>.*?):(?<line>[0-9]*): (?<range>characters|lines) (?<start>[0-9]*)-(?<end>[0-9]*)",
@@ -105,7 +109,9 @@ string[] BuildHxmlArgs()
105109
// Build Haxe command
106110
var paths = ProjectManager.PluginMain.Settings.GlobalClasspaths.ToArray();
107111
var hxmlArgs = new List<String>(hxproj.BuildHXML(paths, "Nothing__", true));
112+
RemoveComments(hxmlArgs);
108113
QuotePath(hxmlArgs);
114+
EscapeMacros(hxmlArgs);
109115

110116
// Get the current class edited (ensure completion even if class not reference in the project)
111117
var package = ASContext.Context.CurrentModel.Package;
@@ -131,6 +137,38 @@ string[] BuildHxmlArgs()
131137
return hxmlArgs.ToArray();
132138
}
133139

140+
private void RemoveComments(List<string> hxmlArgs)
141+
{
142+
for (int i = 0; i < hxmlArgs.Count; i++)
143+
{
144+
string arg = hxmlArgs[i];
145+
if (!string.IsNullOrEmpty(arg))
146+
{
147+
if (arg.StartsWith("#")) // commented line
148+
hxmlArgs[i] = "";
149+
}
150+
}
151+
}
152+
153+
private void EscapeMacros(List<string> hxmlArgs)
154+
{
155+
for (int i = 0; i < hxmlArgs.Count; i++)
156+
{
157+
string arg = hxmlArgs[i];
158+
if (!string.IsNullOrEmpty(arg))
159+
{
160+
Match m = reMacro.Match(arg);
161+
if (m.Success)
162+
hxmlArgs[i] = m.Groups[1].Value + " " + EscapeQuotes(m.Groups[2].Value.Trim());
163+
}
164+
}
165+
}
166+
167+
private string EscapeQuotes(string expr)
168+
{
169+
return reQuote.Replace(expr, "$1\\\"");
170+
}
171+
134172
void QuotePath(List<string> hxmlArgs)
135173
{
136174
for (int i = 0; i < hxmlArgs.Count; i++)
@@ -141,8 +179,6 @@ void QuotePath(List<string> hxmlArgs)
141179
Match m = reArg.Match(arg);
142180
if (m.Success)
143181
hxmlArgs[i] = m.Groups[1].Value + " \"" + m.Groups[2].Value.Trim() + "\"";
144-
else if (arg.StartsWith("#")) // commented line
145-
hxmlArgs[i] = "";
146182
}
147183
}
148184
}

External/Plugins/ProjectManager/Projects/Haxe/HaxeProject.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ private void ParseHXML(string[] raw)
365365
if (m.Success)
366366
{
367367
string op = m.Groups[1].Value;
368+
if (op == "-next")
369+
break; // ignore the rest
370+
368371
string value = m.Groups[2].Value.Trim();
369372
switch (op)
370373
{
@@ -385,7 +388,8 @@ private void ParseHXML(string[] raw)
385388
int.TryParse(header[2], out MovieOptions.Fps);
386389
MovieOptions.Background = header[3];
387390
break;
388-
case "--connect": break; // ignore
391+
case "-connect": break; // ignore
392+
case "-each": break; // ignore
389393
default:
390394
// detect platform (-cpp output, -js output, ...)
391395
var targetPlatform = FindPlatform(op);
@@ -395,7 +399,8 @@ private void ParseHXML(string[] raw)
395399
haxeTarget = targetPlatform.HaxeTarget;
396400
output = value;
397401
}
398-
else add.Add(line); break;
402+
else add.Add(line);
403+
break;
399404
}
400405
}
401406
}

0 commit comments

Comments
 (0)