本文整理汇总了C#中Lexer.GetParent方法的典型用法代码示例。如果您正苦于以下问题:C# Lexer.GetParent方法的具体用法?C# Lexer.GetParent怎么用?C# Lexer.GetParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer
的用法示例。
在下文中一共展示了Lexer.GetParent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Detect
internal override void Detect(Lexer l)
{
if (l.Char == '{' && !(l.GetParent() is ClassDefinitionToken))
{
l.TakeOwnership();
l.AddNode(new DirectNode(l.Text));
l.AddParent();
l.EndOwnership();
}
}
示例2: Detect
internal override void Detect(Lexer l)
{
if (!(l.Char == ' ' || (l.Char >= '0' && l.Char <= '9') || (l.Char >= 'a' && l.Char <= 'z') ||
(l.Char >= 'A' && l.Char <= 'Z') || l.Char == '\n' || l.Char == '\t' || l.Char == '\r' ||
l.Char == ';' || l.Char == '_' || l.Char == ':' || l.Char == '*' || l.Char == '<' ||
l.Char == '>') && !l.Text.Contains("="))
{
l.ForceExclude(); // contains characters we can't accept.
return;
}
if (!(l.GetParent() is ClassDefinitionToken))
{
l.ForceExclude(); // not within a class.
return;
}
KeywordResult res = Keywords.GetKeywords(l.Text);
if (res.Keywords.Count > 0 && res.PossibleKeyword == false)
{
// Now use regular expression checking against the substring starting
// at res.DeclIndex to determine whether it's a variable declaration.
string decl = l.Text.Substring(res.DeclIndex).Trim();
if (!decl.EndsWith(";") && !decl.EndsWith("{")) return; // Skip if we don't have a terminating character.
Regex r = new Regex(
"(?<Type>[a-zA-Z][a-zA-z0-9_\\:\\<\\>]+[ \t\r\n\\*]+)?" +
"(?<Name>[a-zA-Z][a-zA-z0-9_]*[ \t\r\n]*)" +
"(?<Assign>\\=[ \t\r\n]*((\\\".*\\\")|([a-zA-Z][a-zA-z0-9_\\:\\<\\>]+)|([0-9_.]*)))?;"
);
Match m = r.Match(decl);
if (m.Success)
{
// It's a variable declaration.
l.TakeOwnership();
if (m.Groups["Assign"].Success)
l.AddNode(new ClassVariableDeclarationNode(res.Keywords, m.Groups["Type"].Value.Trim(), m.Groups["Name"].Value.Trim(), m.Groups["Assign"].Value.TrimStart('=').TrimStart()));
else
l.AddNode(new ClassVariableDeclarationNode(res.Keywords, m.Groups["Type"].Value.Trim(), m.Groups["Name"].Value.Trim(), ""));
l.EndOwnership();
}
else
{
// A different kind of declaration that we aren't handling...
l.ForceExclude();
}
}
}
示例3: Detect
internal override void Detect(Lexer l)
{
if (!(l.Char == ' ' || (l.Char >= '0' && l.Char <= '9') || (l.Char >= 'a' && l.Char <= 'z') ||
(l.Char >= 'A' && l.Char <= 'Z') || l.Char == '\n' || l.Char == '\t' || l.Char == '\r' ||
l.Char == '{' || l.Char == '}' || l.Char == ':' || l.Char == '_' || l.Char == ';'))
{
l.ForceExclude(); // contains characters we can't accept.
return;
}
if (!(l.GetParent() is ClassDefinitionToken))
{
l.ForceExclude(); // not within a class.
return;
}
KeywordResult res = null;
if (l.Text.IndexOf('{') != -1)
res = Keywords.GetKeywords(l.Text.Substring(0, l.Text.IndexOf('{')));
else
res = Keywords.GetKeywords(l.Text);
if (res.Keywords.Count > 0 && res.PossibleKeyword == false && res.Keywords.Contains("property"))
{
// Now use regular expression checking against the substring starting
// at res.DeclIndex to determine whether it's a variable declaration.
string decl = l.Text.Substring(res.DeclIndex).Trim();
if (!decl.EndsWith("}")) return; // Skip if we don't have a terminating character.
Regex r = new Regex("(?<PropertyName>[a-zA-Z_][a-zA-z0-9_]*)[ \t\r\n]*\\{(?<PropertyContents>[^\\}]*)\\}");
Match m = r.Match(decl);
if (m.Success)
{
// It's a property declaration.
l.TakeOwnership();
l.AddNode(new DirectNode("\n"));
l.AddNode(new ClassPropertyDeclarationNode(res.Keywords,
m.Groups["PropertyName"].Value, m.Groups["PropertyContents"].Value.Trim()));
l.EndOwnership();
}
else if (decl.IndexOf('{') != -1 && decl.IndexOf('}') != -1)
{
// We can only force exclude if there's an opening bracket
// and a closing bracket and we still don't match.
l.ForceExclude();
}
}
}