protected internal virtual XPathElement GetXPathElement(IToken wordToken, bool anywhere)
{
if (wordToken.Type == TokenConstants.EOF)
{
throw new ArgumentException("Missing path element at end of path");
}
string word = wordToken.Text;
int ttype = parser.GetTokenType(word);
int ruleIndex = parser.GetRuleIndex(word);
switch (wordToken.Type)
{
case XPathLexer.Wildcard:
{
return anywhere ? new XPathWildcardAnywhereElement() : (XPathElement)new XPathWildcardElement();
}
case XPathLexer.TokenRef:
case XPathLexer.String:
{
if (ttype == TokenConstants.InvalidType)
{
throw new ArgumentException(word + " at index " + wordToken.StartIndex + " isn't a valid token name");
}
return anywhere ? new XPathTokenAnywhereElement(word, ttype) : (XPathElement)new XPathTokenElement(word, ttype);
}
default:
{
if (ruleIndex == -1)
{
throw new ArgumentException(word + " at index " + wordToken.StartIndex + " isn't a valid rule name");
}
return anywhere ? new XPathRuleAnywhereElement(word, ruleIndex) : (XPathElement)new XPathRuleElement(word, ruleIndex);
}
}
}