public static System.Tuple<int, int> _ParsePostfixDecl(Attribute attr, string decl, ActionAST a, Grammar g)
{
int start = -1;
int stop = -1;
int colon = decl.IndexOf(':');
int namePartEnd = colon == -1 ? decl.Length : colon;
// look for start of name
for (int i = 0; i < namePartEnd; ++i)
{
char ch = decl[i];
if (char.IsLetterOrDigit(ch) || ch == '_')
{
start = i;
break;
}
}
if (start == -1)
{
start = 0;
g.tool.errMgr.GrammarError(ErrorType.CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL, g.fileName, a.Token, decl);
}
// look for stop of name
for (int i = start; i < namePartEnd; ++i)
{
char ch = decl[i];
if (!(char.IsLetterOrDigit(ch) || ch == '_'))
{
stop = i;
break;
}
if (i == namePartEnd - 1)
{
stop = namePartEnd;
}
}
if (stop == -1)
{
stop = start;
}
// extract name from decl
attr.name = decl.Substring(start, stop - start);
// extract type from decl (could be empty)
if (colon == -1)
{
attr.type = "";
}
else
{
attr.type = decl.Substring(colon + 1, decl.Length - colon - 1);
}
attr.type = attr.type.Trim();
if (attr.type.Length == 0)
{
attr.type = null;
}
return Tuple.Create(start, stop);
}