コード例 #1
0
        // calc the elem form based on the isolated delim of the element.
        // ( see the caller. the isolated delim is either the direct delim of the
        //   word in the string, or is the delim that follows a braced word. )
        static StmtElemForm CalcElemForm_Actual(
            delIsMemberEnd InIsMemberEnd,
            Stmt InTopStmt, StmtElem InParent,
            StmtWordListCursor InCsr,
            WordCursor InDelimCursor)
        {
            StmtElemForm sef = StmtElemForm.None;

            // how to handle InParent when InParent is ElemForm == StmtElemForm.TopStmt?

            // actual end of text of string.
            if ((InDelimCursor.DelimClass == DelimClassification.EndOfString) ||
                (InTopStmt.StmtTraits.IsEndStmtDelim(InDelimCursor.DelimValue) == true))
            {
                if ((InParent != null) && (InParent.ElemForm != StmtElemForm.TopStmt))
                {
                    sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
                }
                else if (InTopStmt.StmtTraits.HasSentenceDelimStrings == true)
                {
                    sef = StmtElemForm.Sentence;
                }
                else
                {
                    sef = StmtElemForm.Command;
                }
            }

            // lhs of assignment statement.
            else if (InDelimCursor.DelimIsAssignmentSymbol == true)
            {
                if (InParent == null)
                {
                    sef = StmtElemForm.Assignment;
                }
                else if ((InParent.ElemForm == StmtElemForm.lhs) ||
                         (InParent.ParentElemForm == StmtElemForm.lhs))
                {
                    sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
                }
                else
                {
                    sef = StmtElemForm.Assignment;
                }
            }

            // a qualified name ( a directory path )
            else if (InDelimCursor.IsPathPart == true)
            {
                if (InParent == null)
                {
                    sef = StmtElemForm.QualifiedSequence;
                }
                else if (InParent.ElemForm == StmtElemForm.QualifiedSequence)
                {
                    sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
                }
                else
                {
                    sef = StmtElemForm.QualifiedSequence;
                }
            }

            else if ((InDelimCursor.DelimIsPathPart == true) &&
                     (InDelimCursor.WhitespaceFollowsWord == true))
            {
                if (InParent == null)
                {
                    sef = StmtElemForm.Command;
                }
                else if (InParent.ElemForm == StmtElemForm.Command)
                {
                    sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
                }
                else
                {
                    sef = StmtElemForm.Command;
                }
            }

            // the delim of the StmtWord is an expression symbol. this word is either the
            // start of an expression, or a word within an expression.
            // ( for now, assume is a value expression. if turns out to be boolean, should
            // be able to change the elem form of the expression element. )
            else if (InDelimCursor.DelimIsExpressionSymbol == true)
            {
                if (InParent == null)
                {
                    sef = StmtElemForm.ValueExpression;
                }
                else if (InParent.IsExpression == true)
                {
                    sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
                }
                else
                {
                    sef = StmtElemForm.ValueExpression;
                }
            }

            // word is part of a space delim command string
            // note: have to set the CommandCapable switch in StmtTraits in order to parse
            //       commands.
            else if ((InTopStmt.StmtTraits.CommandCapable == true) &&
                     (InDelimCursor.DelimIsWhitespace == true))
            {
                if (InParent == null)
                {
                    sef = StmtElemForm.Command;
                }
                else if (InParent.ElemForm == StmtElemForm.Command)
                {
                    sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
                }
                else
                {
                    sef = StmtElemForm.Command;
                }
            }

            // sentence delimiter.
            else if (InTopStmt.StmtTraits.IsSentenceDelim(InDelimCursor.DelimValue) == true)
            {
                sef = CalcElemForm_Actual_Sentence(
                    InIsMemberEnd, InTopStmt, InParent, InCsr, InDelimCursor);
            }

            // comma seperated values
            else if (InDelimCursor.DelimValue == ",")
            {
                if (InParent == null)
                {
                    sef = StmtElemForm.CSV;
                }
                else if (InParent.CommaIsMemberDelim)
                {
                    sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
                }
                else if ((InParent.Parent != null) &&
                         (InParent.Parent.CommaIsMemberDelim))
                {
                    sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
                }
                else
                {
                    sef = StmtElemForm.CSV;
                }
            }

            else if (InTopStmt.StmtTraits.IsFunctionCloseBrace(InDelimCursor.DelimValue) == true)
            {
                if (InParent == null)
                {
                    throw new ApplicationException("unexpected close brace char");
                }
                else if (InParent.ElemForm == StmtElemForm.Function)
                {
                    sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
                }
                else if ((InParent.ElemForm == StmtElemForm.Sentence) &&
                         (InParent.ParentElemForm == StmtElemForm.Function))
                {
                    sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
                }
                else
                {
                    throw new ApplicationException("unexpected function close brace char");
                }
            }

            else if (InTopStmt.StmtTraits.IsSentenceCloseBraceChar(InDelimCursor.DelimValue) == true)
            {
                if (InParent == null)
                {
                    throw new ApplicationException("unexpected close brace char");
                }
                else if (InParent.ElemForm == StmtElemForm.Sentence)
                {
                    sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
                }
                else
                {
                    throw new ApplicationException("unexpected function close brace char");
                }
            }

            return(sef);
        }