public static System.Tuple<int, int> _ParsePrefixDecl(Attribute attr, string decl, ActionAST a, Grammar g)
{
// walk backwards looking for start of an ID
bool inID = false;
int start = -1;
for (int i = decl.Length - 1; i >= 0; i--)
{
char ch = decl[i];
// if we haven't found the end yet, keep going
if (!inID && char.IsLetterOrDigit(ch))
{
inID = true;
}
else if (inID && !(char.IsLetterOrDigit(ch) || ch == '_'))
{
start = i + 1;
break;
}
}
if (start < 0 && inID)
{
start = 0;
}
if (start < 0)
{
g.tool.errMgr.GrammarError(ErrorType.CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL, g.fileName, a.Token, decl);
}
// walk forward looking for end of an ID
int stop = -1;
for (int i = start; i < decl.Length; i++)
{
char ch = decl[i];
// if we haven't found the end yet, keep going
if (!(char.IsLetterOrDigit(ch) || ch == '_'))
{
stop = i;
break;
}
if (i == decl.Length - 1)
{
stop = i + 1;
}
}
// the name is the last ID
attr.name = decl.Substring(start, stop - start);
// the type is the decl minus the ID (could be empty)
attr.type = decl.Substring(0, start);
if (stop <= decl.Length - 1)
{
attr.type += decl.Substring(stop, decl.Length - stop);
}
attr.type = attr.type.Trim();
if (attr.type.Length == 0)
{
attr.type = null;
}
return Tuple.Create(start, stop);
}