// 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_Sentence(
            delIsMemberEnd InIsMemberEnd,
            Stmt InTopStmt, StmtElem InParent,
            StmtWordListCursor InCsr,
            WordCursor InDelimCursor)
        {
            StmtElemForm sef = StmtElemForm.None;

            if ((InParent != null) && (InParent.IsSentence == true))
            {
                sef = CalcElemForm_Standalone(InTopStmt, InParent, InCsr);
            }
            else
            {
                StmtWordListCursor c2 = null;
                sef = StmtElemForm.Sentence;

                // lookahead in the stmt string. look to see if the sentence ends with
                // a braced section or not.
                c2 = InCsr.PositionBefore(WhichEdge.LeadEdge);
                while (true)
                {
                    c2 = c2.Next();
                    if (c2 == null)
                    {
                        break;
                    }

                    if (c2.StmtWord.HasSubWords == true)
                    {
                        if (InTopStmt.StmtTraits.IsSentenceOpenBraceChar(c2.WordCursor.DelimValue) == true)
                        {
                            sef = StmtElemForm.BracedSentence;
                            break;
                        }

                        c2 = c2.Next();
                    }

                    // word is an assignment symbol. stmt is not a sentence. it is an assignment.
                    if ((InParent != null) && (InParent.ElemForm != StmtElemForm.lhs))
                    {
                        if (c2.WordCursor.DelimIsAssignmentSymbol == true)
                        {
                            sef = StmtElemForm.Assignment;
                            break;
                        }
                    }

                    // last word in the sentence.
                    if (InTopStmt.StmtTraits.IsSentenceDelim(c2.WordCursor.DelimValue) == false)
                    {
                        break;
                    }
                }
            }
            return(sef);
        }
Example #2
0
        StmtWordListCursor Parse_Assignment(delIsMemberEnd InIsMemberEnd)
        {
            StmtElem           elem = null;
            StmtElemForm       sef  = StmtElemForm.None;
            StmtWordListCursor csr  = this.StartCursor.PositionBefore(WhichEdge.LeadEdge);

            // first word is the lhs of the assignment stmt.
            csr = csr.Next();

            StmtElem lhsElem = new StmtElem(TopStmt, StmtElemForm.lhs, csr);

            AddMemberElem(lhsElem);

            // parse the lhs word
            sef  = StmtElem.CalcElemForm(null, TopStmt, lhsElem, csr);
            elem = new StmtElem(TopStmt, sef, csr);
            lhsElem.AddMemberElem(elem);
            if (Stmt.ElemFormHasSubElements(sef) == true)
            {
                csr = elem.Parse();
            }

            // right hand side.
            csr = csr.Next();
            if ((csr == null) || (csr.WordCursor.IsEndOfString == true))
            {
                throw new ApplicationException("assignment stmt missing right hand side");
            }
            StmtElem rhsElem = new StmtElem(TopStmt, StmtElemForm.rhs, csr);

            AddMemberElem(rhsElem);

            sef  = StmtElem.CalcElemForm(InIsMemberEnd, TopStmt, rhsElem, csr);
            elem = new StmtElem(TopStmt, sef, csr);
            rhsElem.AddMemberElem(elem);
            if (Stmt.ElemFormHasSubElements(sef) == true)
            {
                StmtWordListCursor csr2 = null;
                csr2 = elem.Parse();
                if (elem.ElemForm == StmtElemForm.Function)
                {
                    csr = csr.Next();
                }
                else
                {
                    csr = csr2;
                }
            }
            return(csr);
        }
Example #3
0
        private void Parse_Common(string InStmtText, StmtWordListCursor InCsr, StmtTraits InTraits)
        {
            StmtWordListCursor csr = null;

            mStmtText   = InStmtText;
            mStmtTraits = InTraits;

            csr = InCsr.Next();
            if (csr == null)
            {
                throw new ApplicationException("stmt is empty");
            }

            // the TopStmt holds a collection of statements.
            mTopElem = new StmtElem(this, StmtElemForm.TopStmt, csr);

            // parse the collection of statements.
            csr = mTopElem.Parse();

#if skip
            StmtElemForm sef = StmtElemForm.None;
            sef      = StmtElem.CalcElemForm(this, null, csr);
            mTopElem = new StmtElem(this, sef, csr);

            if (Stmt.ElemFormHasSubElements(mTopElem.ElemForm) == true)
            {
                csr = mTopElem.Parse();
            }
#endif
        }
        // If start of function, must scan to close function and the advance to
        // delim that follows the function.

        // Could be standalone function or the function could be member of
        // expression element ( or any other stmt level element. a sentence being most common. )

        // When parent elem is an expression, dont return an expression char delimeted
        // elem as start of new expression.

        // note: no need to be error checking the delimeter at this point.
        // The parent element parsing code will do that. Here we just say that
        // if the delim is expected within the parent elem the elem is standalone.
        // otherwise, the elem is consider a stmt within the stmt.
        static StmtElemForm CalcElemForm(
            delIsMemberEnd InIsMemberEnd,
            Stmt InTopStmt, StmtElem InParent,
            StmtWordListCursor InCsr)
        {
            StmtElemForm sef = StmtElemForm.None;


            // the cursor StmtWord has sub words. that is, it is braced. elem form could be
            // function, could be expression, ...
            if (InCsr.StmtWord.HasSubWords == true)
            {
                // the next word in the string.
                // note: since the word is braced, the next word is the delim only word which
                //       follows the closing brace. ( see StmtElem_FirstPass processing ).
                StmtWordListCursor nxCsr = InCsr.Next();

                sef = CalcElemForm_Actual(InIsMemberEnd, InTopStmt, InParent, InCsr, nxCsr.WordCursor);
            }

            else
            {
                sef = CalcElemForm_Actual(InIsMemberEnd, InTopStmt, InParent, InCsr, InCsr.WordCursor);
            }


            return(sef);
        }
Example #5
0
        // parse a collection of statements.
        StmtWordListCursor Parse_TopStmt(delIsMemberEnd InIsMemberEnd)
        {
            StmtElem           elem = null;
            StmtElemForm       sef  = StmtElemForm.None;
            StmtWordListCursor csr  = this.StartCursor.PositionBefore(WhichEdge.LeadEdge);

            while (true)
            {
                csr = csr.Next();
                if ((csr == null) || (csr.WordCursor.IsEndOfString == true))
                {
                    break;
                }

                sef = StmtElem.CalcElemForm(InIsMemberEnd, TopStmt, this, csr);

                // skip empty words within the collection of stmts.
                if (sef == StmtElemForm.Empty)
                {
                }

                else
                {
//        sef = StmtElem.CalcElemForm(InIsMemberEnd, TopStmt, this, csr);
                    elem = new StmtElem(TopStmt, sef, csr);

                    AddMemberElem(elem);

                    csr = elem.Parse();
                }
            }
            return(csr);
        }
Example #6
0
        // a qualified sequence are consecutive words separated by path delim: aa/bb/cc
        StmtWordListCursor Parse_QualifiedSequence(delIsMemberEnd InIsMemberEnd)
        {
            StmtElem           elem = null;
            StmtElemForm       sef  = StmtElemForm.None;
            StmtWordListCursor csr  = this.StartCursor.PositionBefore(WhichEdge.LeadEdge);

            while (true)
            {
                csr = csr.Next();
                if ((csr == null) || (csr.WordCursor.IsEndOfString == true))
                {
                    break;
                }

                sef  = StmtElem.CalcElemForm(InIsMemberEnd, TopStmt, this, csr);
                elem = new StmtElem(TopStmt, sef, csr);
                AddMemberElem(elem);

                if (Stmt.ElemFormHasSubElements(elem.ElemForm) == true)
                {
                    csr = Parse_SubElement(csr, elem, null);
                }

                if (csr.WordCursor.IsPathPart == false)
                {
                    break;
                }
            }
            return(csr);
        }
Example #7
0
        // parse the CSV form element.
        // return the WordCursor that terminates the element.
        private StmtWordListCursor Parse_CSV(delIsMemberEnd InIsMemberEnd)
        {
            StmtElem           elem = null;
            StmtElemForm       sef  = StmtElemForm.None;
            StmtWordListCursor csr  = this.StartCursor.PositionBefore(WhichEdge.LeadEdge);

            while (true)
            {
                csr = csr.Next();
                if ((csr == null) || (csr.WordCursor.IsEndOfString == true))
                {
                    break;
                }

                sef  = StmtElem.CalcElemForm(InIsMemberEnd, TopStmt, this, csr);
                elem = new StmtElem(TopStmt, sef, csr);
                AddMemberElem(elem);

                if (Stmt.ElemFormHasSubElements(elem.ElemForm) == true)
                {
                    csr = elem.Parse();
                }

                // the CSV stmt ends when an element is not comma delimeted.
                if (csr.WordCursor.DelimClass != DelimClassification.DividerSymbol)
                {
                    break;
                }
                if (csr.WordCursor.DelimValue != ",")
                {
                    break;
                }
            }
            return(csr);
        }
Example #8
0
        // parse the Command form element.
        // return the WordCursor that terminates the element.
        StmtWordListCursor Parse_Command(delIsMemberEnd InIsMemberEnd)
        {
            StmtElem           elem = null;
            StmtElemForm       sef  = StmtElemForm.None;
            StmtWordListCursor csr  = this.StartCursor.PositionAfter(WhichEdge.LeadEdge);

            while (true)
            {
                csr = csr.Next();
                if ((csr == null) || (csr.WordCursor.IsEndOfString == true))
                {
                    break;
                }

                sef  = StmtElem.CalcElemForm(InIsMemberEnd, TopStmt, this, csr);
                elem = new StmtElem(TopStmt, sef, csr);
                AddMemberElem(elem);

                if (Stmt.ElemFormHasSubElements(elem.ElemForm) == true)
                {
                    csr = elem.Parse(Parse_Command_IsMemberEnd);
                }

                // the command stmt ends when an element is not space delimeted.
                if (csr.WordCursor.DelimClass != DelimClassification.Whitespace)
                {
                    break;
                }
            }
            return(csr);
        }
Example #9
0
        StmtWordListCursor Parse_ValueExpression(delIsMemberEnd InIsMemberEnd)
        {
            StmtElem           elem = null;
            StmtElemForm       sef  = StmtElemForm.None;
            StmtWordListCursor csr  = this.StartCursor.PositionBefore(WhichEdge.LeadEdge);

            // parse the expression until delim that is not an expression symbol
            while (true)
            {
                csr = csr.Next();
                if ((csr == null) || (csr.WordCursor.IsEndOfString == true))
                {
                    break;
                }

                sef  = StmtElem.CalcElemForm(InIsMemberEnd, TopStmt, this, csr);
                elem = new StmtElem(TopStmt, sef, csr);
                AddMemberElem(elem);

                if (Stmt.ElemFormHasSubElements(elem.ElemForm) == true)
                {
                    elem.Parse();
                    csr = csr.Next();
                    if (csr == null)
                    {
                        break;
                    }
                }

                // add the expression string as a operator element of the expression parent.
                if (csr.WordCursor.DelimIsExpressionSymbol == true)
                {
                    elem = new StmtElem(TopStmt, StmtElemForm.ExpressionOperator, csr);
                    AddMemberElem(elem);
                }
                else
                {
                    break;
                }
            }

            return(csr);
        }
Example #10
0
        // parse the function form element.
        // return the WordCursor that terminates the element.
        StmtWordListCursor Parse_Function(delIsMemberEnd InIsMemberEnd)
        {
            StmtWordListCursor csr  = null;
            StmtElem           elem = null;
            StmtElemForm       sef  = StmtElemForm.None;

            csr = StartCursor.StmtWord.SubWords.PositionBegin();
            while (true)
            {
                csr = csr.Next();
                if (csr == null)
                {
                    break;
                }

                // new line between function arguments. is ok. treat as whitespace.
                else if ((csr.WordCursor.IsDelimOnly == true) &&
                         (csr.WordCursor.DelimClass == DelimClassification.NewLine))
                {
                }

                // is the closing brace delim of a function with no args.
                else if (csr.WordCursor.IsDelimOnly == true)
                {
                }

                // function arg sub element.
                else
                {
                    sef  = StmtElem.CalcElemForm(Parse_Function_IsMemberEnd, TopStmt, this, csr);
                    elem = new StmtElem(TopStmt, sef, csr);
                    AddMemberElem(elem);

                    if (Stmt.ElemFormHasSubElements(sef) == true)
                    {
                        csr = Parse_SubElement(csr, elem, Parse_Function_IsMemberEnd);
                    }
                }

                CloseCursor = csr;
            }
            return(csr);
        }
Example #11
0
        StmtWordListCursor Parse_Sentence(delIsMemberEnd InIsMemberEnd)
        {
            StmtElem           elem = null;
            StmtElemForm       sef  = StmtElemForm.None;
            StmtWordListCursor csr  = this.StartCursor.PositionBefore(WhichEdge.LeadEdge);

            while (true)
            {
                csr = csr.Next();
                if ((csr == null) || (csr.WordCursor.IsEndOfString == true))
                {
                    break;
                }

                sef = StmtElem.CalcElemForm(InIsMemberEnd, TopStmt, this, csr);

                // skip empty words within a sentence ( a newline char sequence )
                if (sef == StmtElemForm.Empty)
                {
                }

                else
                {
                    elem = new StmtElem(TopStmt, sef, csr);
                    AddMemberElem(elem);

                    if (Stmt.ElemFormHasSubElements(elem.ElemForm) == true)
                    {
                        csr = Parse_SubElement(csr, elem, null);
                    }
                }

                // the sentence ends when the delim after the sentence member elem is
                // not a sentence delim.
                if (TopStmt.StmtTraits.IsSentenceDelim(csr.WordCursor.DelimValue) == false)
                {
                    break;
                }
            }
            return(csr);
        }
Example #12
0
        // parse the sub element, then properly position the StmtWordListCursor to the word
        // which follows the sub element.
        StmtWordListCursor Parse_SubElement(
            StmtWordListCursor InElemCursor, StmtElem InSubElem, delIsMemberEnd InIsMemberEnd)
        {
            StmtWordListCursor csr2       = null;
            StmtWordListCursor elemCursor = InElemCursor;

            csr2 = InSubElem.Parse(InIsMemberEnd);

            // if the sub element just parsed is an expression, the words of the
            // expression were inline ( at the same level ) with the words of this
            // Function element.
            if ((InSubElem.IsExpression == true) ||
                (InSubElem.ElemForm == StmtElemForm.Sentence))
            {
                elemCursor = csr2;
            }

            // an assignment stmt. ( should throw if not delim by stmt end delim. )
            else if (InSubElem.ElemForm == StmtElemForm.Assignment)
            {
                elemCursor = csr2;
            }

            // the sub element is a function. the way the words of the sub function are
            // parsed, the closing brace of the sub function will be the delim of the
            // last element of the sub function.
            // The next word of this owning function ( assuming it is properly formed )
            // will be a delim only word where the delim is either "," or close brace.
            else if ((InSubElem.ElemForm == StmtElemForm.Function) ||
                     (InSubElem.ElemForm == StmtElemForm.BracedSentence) ||
                     (InSubElem.ElemForm == StmtElemForm.BracedContent))
            {
                elemCursor = elemCursor.Next();
            }

            return(elemCursor);
        }
Example #13
0
        // braced content consists of a list of statements.
        // examples of braced on content:
        //    string func( arg InFac1 ) { int xx = 5 ; return xx.ToString( ) ; } // two stmts.
        //    char[] nwc = new char[] { 'a', 'b', 'c' } ; //  one stmt.
        StmtWordListCursor Parse_BracedContent(delIsMemberEnd InIsMemberEnd)
        {
            StmtWordListCursor csr  = null;
            StmtElem           elem = null;
            StmtElemForm       sef  = StmtElemForm.None;

            csr = StartCursor.StmtWord.SubWords.PositionBegin();
            while (true)
            {
                csr = csr.Next();
                if (csr == null)
                {
                    break;
                }

                // is the closing brace delim of a function with no args.
                else if (csr.WordCursor.IsDelimOnly == true)
                {
                }

                // function arg sub element.
                else
                {
                    sef  = StmtElem.CalcElemForm(Parse_Function_IsMemberEnd, TopStmt, this, csr);
                    elem = new StmtElem(TopStmt, sef, csr);
                    AddMemberElem(elem);

                    if (Stmt.ElemFormHasSubElements(sef) == true)
                    {
                        csr = Parse_SubElement(csr, elem, Parse_Function_IsMemberEnd);
                    }
                }

                CloseCursor = csr;
            }
            return(csr);
        }