Ejemplo n.º 1
0
    public void AddRule(ParseNode_Rule rule)
    {
        var nt = rule.NtName;

        if (m_dicNt2Rule.ContainsKey(nt))
        {
            throw new Exception(nt + ": duplicate");
        }
        m_dicNt2Rule.Add(nt, rule);
        m_lsRule.Add(rule);
    }
Ejemplo n.º 2
0
    public void MoveToLine(int line, LR_SyntaxTree parseTree)
    {
        for (var prevLine = line - 1; prevLine >= 0; --prevLine)
        {
            var tokens = m_kTokenScanner.GetFormatedLine(prevLine).tokens;
            for (var i = tokens.Count - 1; i >= 0; --i)
            {
                var token = tokens[i];
                var leaf  = token.m_kLinkedLeaf;
                if (token.tokenKind == LexerToken.Kind.Missing)
                {
                    if (token.m_kLinkedLeaf != null && token.m_kLinkedLeaf.Parent != null)
                    {
                        token.m_kLinkedLeaf.Parent.m_sSyntaxError = null;
                    }
                    tokens.RemoveAt(i);
                    continue;
                }

                if (leaf == null || leaf.ParseNode == null)
                {
                    continue;
                }

                if (token.tokenKind < LexerToken.Kind.LastWSToken)
                {
                    continue;
                }

                if (leaf.m_sSyntaxError != null)
                {
                    ErrorToken   = leaf;
                    ErrorMessage = leaf.m_sSyntaxError;
                    continue;
                }

                MoveAfterLeaf(leaf);
                return;
            }
        }

        //tokens = null;
        //currentLine = -1;
        //currentTokenIndex = -1;
        m_kTokenScanner.Reset();

        SyntaxRule_Cur = null;
        ParseNode_Cur  = null;
        ErrorToken     = null;
        ErrorMessage   = null;
        SyntaxRule_Err = null;
        ParseNode_Err  = null;

        m_kTokenScanner.MoveNext();

        ParseNode_Rule startRule = Parser_CSharp.Instance.ParseRoot.Rule_Start;

        SyntaxRule_Cur = parseTree.root; // = new ParseTree.Node(rootId);
        ParseNode_Cur  = startRule;      //.Parse(pSyntaxTreeBuilder);
        SyntaxRule_Err = SyntaxRule_Cur;
        ParseNode_Err  = ParseNode_Cur;
    }
Ejemplo n.º 3
0
    public bool CollectCompletions(TokenSet tokenSet, SyntaxTreeBuilder pSyntaxTreeBuilder, int identifierId)
    {
        var clone = pSyntaxTreeBuilder.Clone();

        var hasName = false;
        var current = this;

        while (current != null && current.parent != null)
        {
            tokenSet.Add(current.FirstSet);

            if (current.FirstSet.Contains(identifierId))
            {
                ParseNode_Rule currentRule = null;
                var            currentId   = current as ParseNode_Id;
                if (currentId == null)
                {
                    var rule = current.parent;
                    while (rule != null && !(rule is ParseNode_Rule))
                    {
                        rule = rule.parent;
                    }
                    currentId   = rule != null ? rule.parent as ParseNode_Id : null;
                    currentRule = rule as ParseNode_Rule;
                }

                if (currentId != null)
                {
                    var peerAsRule = currentId.LinkedTarget as ParseNode_Rule;
                    if (peerAsRule != null && peerAsRule.contextualKeyword)
                    {
                        Debug.Log(currentId.Name);
                    }
                    else if (currentRule != null && currentRule.contextualKeyword)
                    {
                        Debug.Log("currentRule " + currentRule.NtName);
                    }
                    else
                    {
                        var id = currentId.Name;
                        if (Array.IndexOf(new[]
                        {
                            "constantDeclarators",
                            "constantDeclarator",
                        }, id) >= 0)
                        {
                            hasName = true;
                        }
                    }
                }
            }

            if (!current.FirstSet.ContainsEmpty())
            {
                break;
            }

            current = current.parent.NextAfterChild(current, clone);
        }
        tokenSet.RemoveEmpty();

        return(hasName);
    }