string MassageInput(string s, out bool wasAssignment) {
// vs 0.8 (fix by toolmakerSteve2) process the words in reverse order when looking for assignments!
MatchCollection words = wordPattern.Matches(s);
Match[] wordArray = new Match[words.Count];
words.CopyTo(wordArray,0);
Array.Reverse(wordArray);
wasAssignment = false;
bool varDeclaration = false;
for (int i = 0; i < wordArray.Length; i++) {
Match m = wordArray[i];
// exclude matches found inside strings
if (s.LastIndexOf('"',m.Index) != -1 && s.IndexOf('"',m.Index) != -1)
continue;
string sym = m.Value;
if (! mustDeclare) // strip the '$'
sym = sym.Substring(1);
else { // either it's a declaration, or the var was previously declared.
if (sym == "var")
continue;
// are we preceded by 'var'? If so, this is a declaration
if (i+1 < wordArray.Length && wordArray[i+1].Value == "var")
varDeclaration = true;
else if (varTable[sym] == null)
continue;
}
string symRef = "V[\"" + sym + "\"]"; // will index our hashtable
// are we followed by an assignment operator?
Match lhs = assignment.Match(s,m.Index);
wasAssignment = lhs != Match.Empty && lhs.Index == m.Index;
Type symType = GetPublicRuntimeType(varTable[sym]);
// unless we're on the LHS, try to strongly type this variable reference.
if (symType != null && ! wasAssignment)
symRef = "((" + symType.ToString() + ")" + symRef + ")";
s = wordPattern.Replace(s,symRef,1,m.Index);
}
if (varDeclaration)
s = s.Replace("var ","");
return s;
}