本文整理汇总了C#中CstNode.AllTokenNodes方法的典型用法代码示例。如果您正苦于以下问题:C# CstNode.AllTokenNodes方法的具体用法?C# CstNode.AllTokenNodes怎么用?C# CstNode.AllTokenNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CstNode
的用法示例。
在下文中一共展示了CstNode.AllTokenNodes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetLocationInformation
public void SetLocationInformation(CstNode tree, string code) {
var line = 1;
var pos = 0;
var index = 0;
var startHiddenLocation = new CodeLocation(line, pos);
foreach (var tokenNode in tree.AllTokenNodes()) {
var token = tokenNode.Token;
var tokenStr = token.Text;
if (tokenStr == string.Empty) { // e.g. NEWLINE in Python
token.Range = new CodeRange(startHiddenLocation, startHiddenLocation);
continue;
}
var startHiddenIndex = index;
var tokenChar = tokenStr[0];
while (code[index] != tokenChar
|| code.Substring(index, tokenStr.Length) != tokenStr) {
if (code[index] != '\n') {
pos++;
} else {
line++;
pos = 0;
}
index++;
}
var endHiddenIndex = index;
var startTokenLocation = new CodeLocation(line, pos);
var endIndex = index + tokenStr.Length;
while (index < endIndex) {
if (code[index] != '\n') {
pos++;
} else {
line++;
pos = 0;
}
index++;
}
tokenNode.Hiddens.Add(
new CstToken(
Code2XmlConstants.HiddenElementName,
code.Substring(startHiddenIndex, endHiddenIndex - startHiddenIndex),
Code2XmlConstants.DefaultHiddenRuleId,
new CodeRange(startHiddenLocation, startTokenLocation)));
startHiddenLocation = new CodeLocation(line, pos); // as endTokenLocation
token.Range = new CodeRange(startTokenLocation, startHiddenLocation);
}
{
var startHiddenIndex = index;
var endIndex = code.Length;
while (index < endIndex) {
if (code[index] != '\n') {
pos++;
} else {
line++;
pos = 0;
}
index++;
}
var endHiddenLocation = new CodeLocation(line, pos);
var token = new CstToken(
Code2XmlConstants.EofTokenName, String.Empty, Code2XmlConstants.EofRuleId,
new CodeRange(endHiddenLocation, endHiddenLocation));
var eofNode = new CstNode(token);
eofNode.Hiddens.Add(
new CstToken(
Code2XmlConstants.HiddenElementName,
code.Substring(startHiddenIndex, index - startHiddenIndex),
Code2XmlConstants.DefaultHiddenRuleId,
new CodeRange(startHiddenLocation, endHiddenLocation)));
tree.AddLast(eofNode);
}
}