public override bool Scan(SyntaxTreeBuilder pSyntaxTreeBuilder)
    {
        if (!pSyntaxTreeBuilder.KeepScanning)
        {
            return(true);
        }

        var ifNode = node as ParseNode_ManyOpt_If ?? node as ParseNode_ManyOpt_IfNot;

        if (ifNode != null)
        {
            int tokenIndex, line;
            do
            {
                tokenIndex = pSyntaxTreeBuilder.TokenScanner.CurrentTokenIndex;
                line       = pSyntaxTreeBuilder.TokenScanner.CurrentLine - 1;
                if (!node.Scan(pSyntaxTreeBuilder))
                {
                    return(false);
                }
                if (!pSyntaxTreeBuilder.KeepScanning)
                {
                    return(true);
                }
            } while (pSyntaxTreeBuilder.TokenScanner.CurrentTokenIndex != tokenIndex || pSyntaxTreeBuilder.TokenScanner.CurrentLine - 1 != line);
        }
        else
        {
            while (FirstSet.Contains(pSyntaxTreeBuilder.TokenScanner.Current.tokenId))
            {
                int tokenIndex = pSyntaxTreeBuilder.TokenScanner.CurrentTokenIndex;
                int line       = pSyntaxTreeBuilder.TokenScanner.CurrentLine;
                if (!node.Scan(pSyntaxTreeBuilder))
                {
                    return(false);
                }
                if (!pSyntaxTreeBuilder.KeepScanning)
                {
                    return(true);
                }
                if (pSyntaxTreeBuilder.TokenScanner.CurrentTokenIndex == tokenIndex && pSyntaxTreeBuilder.TokenScanner.CurrentLine - 1 == line)
                {
                    throw new Exception("Infinite loop!!!");
                }
            }
        }
        return(true);
    }
Esempio n. 2
0
    public override bool PreCheck(ParseNode_Base node, int maxDistance = int.MaxValue)
    {
        if (m_kTokenScanner.IsEnding)
        {
            return(false);
        }
        var line  = m_kTokenScanner.CurrentLine;
        var index = m_kTokenScanner.CurrentTokenIndex;
        //	var realIndex = nonTriviaTokenIndex;

        var temp = maxScanDistance;

        maxScanDistance = maxDistance;
        var match = node.Scan(this);

        maxScanDistance = temp;

        //for (var i = m_kTokenScanner.CurrentLine; i > line; --i)
        //    if (i < lines.Length)
        //        lines[i].laLines = Math.Max(lines[i].laLines, i - line);

        m_kTokenScanner.MoveTo(line, index);
        //m_kTokenScanner.CurrentLine = line;
        //m_kTokenScanner.CurrentTokenIndex = index;
        //	nonTriviaTokenIndex = realIndex;
        //tokens = currentLine < lines.Length ? lines[currentLine].tokens : null;
        return(match);
    }
 public override bool Scan(SyntaxTreeBuilder pSyntaxTreeBuilder)
 {
     if (!pSyntaxTreeBuilder.KeepScanning)
     {
         return(true);
     }
     if (FirstSet.Contains(pSyntaxTreeBuilder.TokenScanner.Current))
     {
         return(rhs.Scan(pSyntaxTreeBuilder));
     }
     else if (!FirstSet.ContainsEmpty())
     {
         return(false);
     }
     return(true);
 }