// 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
        // 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);
        }
        public static StmtElemForm CalcElemForm(
            Stmt InTopStmt, StmtElem InParent,
            StmtWordListCursor InCsr)
        {
            StmtElemForm   sef = StmtElemForm.None;
            delIsMemberEnd me  = null;

            sef = CalcElemForm(me, InTopStmt, InParent, InCsr);
            return(sef);
        }
Esempio n. 8
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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
        // calc the form of the element without the context of the delim that separates it
        // from the next element, and without consideration of the parent elem.
        private static StmtElemForm CalcElemForm_Standalone(
            Stmt InTopStmt, StmtElem InParent,
            StmtWordListCursor InCsr)
        {
            StmtElemForm form = StmtElemForm.None;
            WordCursor   wc   = InCsr.WordCursor;

            if (wc.IsDelimOnly == true)
            {
                form = StmtElemForm.Empty;
            }
            else if (wc.WordClassification == WordClassification.OpenNamedBraced)
            {
                form = StmtElemForm.Function;
            }
            else if (wc.WordClassification == WordClassification.OpenContentBraced)
            {
                form = StmtElemForm.BracedContent;
            }
            else if (wc.WordClassification == WordClassification.Identifier)
            {
                form = StmtElemForm.Variable;
            }
            else if (wc.WordClassification == WordClassification.Quoted)
            {
                form = StmtElemForm.QuotedLiteral;
            }
            else if (wc.WordClassification == WordClassification.Numeric)
            {
                form = StmtElemForm.NumericLiteral;
            }
            else
            {
                throw new ApplicationException(
                          "Cannot calc StmtElem form of word " +
                          wc.Word.ToString() + " starting at position " +
                          wc.WordBx.ToString());
            }
            return(form);
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
        // 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);
        }