void Expand(CiMacro macro)
{
Dictionary<string, string> args = new Dictionary<string, string>();
StringBuilder sb = new StringBuilder();
this.CopyTo = sb;
try {
Expect(CiToken.LeftParenthesis);
bool first = true;
foreach (string name in macro.Params) {
if (first)
first = false;
else
Expect(CiToken.Comma);
ParseArg();
char c = sb[sb.Length - 1];
Trace.Assert(c == ',' || c == ')');
sb.Length--;
args.Add(name, sb.ToString().Trim());
sb.Length = 0;
}
}
finally {
this.CopyTo = null;
}
Check(CiToken.RightParenthesis);
if (macro.IsStatement) {
NextToken();
Check(CiToken.Semicolon);
}
BeginExpand("macro " + macro.Name, macro.Body, args);
NextToken();
}