private bool TryFindFirstTag(int begin, int end, TreeNode parentNode, out TreeNode node, out Token token) { node = new TreeNode(); token = new Token(); var currentPos = begin; while (currentPos < end) { if (TokenReader.TryParseDoubleUnderlineTag(_input, currentPos, end, out token)) { if (!parentNode.IsRoot && parentNode.Type == NodeType.SingleUnderlineTag) { currentPos = token.Position + token.Length; continue; } if (TokenReader.IsNumberWithUnderlines(_input, token.Position, token.Position + token.Length)) { currentPos = token.Position + token.Length; continue; } node.Type = NodeType.DoubleUnderlineTag; return(true); } if (TokenReader.TryParseSingleUnderlineTag(_input, currentPos, end, out token)) { if (TokenReader.IsNumberWithUnderlines(_input, token.Position, token.Position + token.Length)) { currentPos = token.Position + token.Length; continue; } node.Type = NodeType.SingleUnderlineTag; return(true); } currentPos++; } return(false); }