// 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); }
// 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); }
// 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); }
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); }
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); }
// 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); }