Beispiel #1
0
            public void AdvanceNextValue( )
            {
                mAtFinalEmptyValue = false;
                if (mCsr != null)
                {
                    // where is the cursor now. is it at a word, does that word have a delim.
                    bool delimEndedWord = false;
                    if ((mCsr.IsAtWord == true) &&
                        (mCsr.DelimClass == DelimClassification.DividerSymbol))
                    {
                        delimEndedWord = true;
                    }

//					mCsr.AdvanceNextWord( ) ;
                    mCsr = Scanner.ScanNextWord(CsvString.String, mCsr);

                    if (mCsr.IsAtWord == true)
                    {
                        ++mValueNx;
                    }
                    else if (mCsr.IsDelimOnly == true)
                    {
                        ++mValueNx;
                    }
                    else if (delimEndedWord == true)
                    {
                        mAtFinalEmptyValue = true;
                        ++mValueNx;
                    }
                    else
                    {
                        mValueNx = -1;
                    }
                }
            }
Beispiel #2
0
        // ------------------------ ScanFirstWord -------------------------
        public static WordCursor ScanFirstWord(string InString, TextTraits InTraits)
        {
            BoundedString boundedString = new BoundedString(InString);
            WordCursor    res           = ScanFirstWord(boundedString, InTraits);

            return(res);
        }
Beispiel #3
0
        // ------------------------ PositionAfterWord ----------------------
        public static WordCursor PositionAfterWord(WordCursor InWord)
        {
            WordCursor word = new WordCursor(InWord);

            word.Position = RelativePosition.After;
            return(word);
        }
Beispiel #4
0
        // ------------------------ PositionBeforeWord ----------------------
        public static WordCursor PositionBeforeWord(WordCursor InWord)
        {
            WordCursor word = new WordCursor(InWord);

            word.Position = RelativePosition.Before;
            return(word);
        }
Beispiel #5
0
        // ----------------------- PositionBeginWord -----------------------------
        // position at begin of string to scan.
        public static WordCursor PositionBeginWord( )
        {
            WordCursor word = new WordCursor( );

            word.RelativePosition = AcRelativePosition.Begin;
            return(word);
        }
        // ------------------ ScanWord_IsolatedWord_CommentToEnd -------------------
        public static ScanPatternResults ScanWord_IsolateWord_CommentToEnd(
            string Text,
            int WordBx,
            ref WordCursor Results, TextTraits Traits)
        {
            string             wordText;
            ScanPatternResults spr = null;

            // look for end of comment. ( either end of line or end of string )
            int fx = Text.IndexOf(Environment.NewLine, WordBx);

            if (fx >= 0)
            {
                int Lx = fx - WordBx;
                wordText = Text.Substring(WordBx, Lx);
                ScanPattern pat =
                    Traits.NonWordPatterns.FindPatternAtSubstring(Text, fx, 2);
                spr = new ScanPatternResults(fx, pat);
            }
            else
            {
                wordText = Text.Substring(WordBx);
                spr      = new ScanPatternResults(-1);
            }

            // store info on the word found in the return WordCursor argument.
            Results.SetWord(wordText, WordClassification.CommentToEnd, WordBx);

            // return value of method contains info on the word delim.
            return(spr);
        }
Beispiel #7
0
 public StmtWord(string InStmtText, StmtWord InParent, WordCursor InWordCursor)
 {
     mStmtText   = InStmtText;
     mSubWords   = null;
     mWordCursor = InWordCursor;
     Parent      = InParent;
 }
        // ------------------ ScanWord_IsolatedWord_CommentToEnd -------------------
        private static ScanPatternResults ScanWord_IsolateWord_CommentToEnd(
            BoundedString InBoundedString,
            int InWordBx,
            ref WordCursor InOutResults, TextTraits InTraits)
        {
            string             wordText;
            ScanPatternResults spr = null;

            // look for end of comment. ( either end of line or end of string )
            int fx = Scanner.ScanEqual(InBoundedString, InWordBx, Environment.NewLine).ResultPos;

            if (fx >= 0)
            {
                int Lx = fx - InWordBx;
                wordText = InBoundedString.Substring(InWordBx, Lx);
                ScanPattern pat =
                    InTraits.NonWordPatterns.FindPatternAtSubstring(InBoundedString, fx);
                spr = new ScanPatternResults(fx, pat);
            }
            else
            {
                wordText = InBoundedString.Substring(InWordBx);
                spr      = new ScanPatternResults(-1);
            }

            // store info on the word found in the return WordCursor argument.
            InOutResults.SetWord(wordText, WordClassification.CommentToEnd, InWordBx);

            // return value of method contains info on the word delim.
            return(spr);
        }
        // ----------------------- ScanWord_IsolatedWord_Braced -----------------------
        public static void ScanWord_IsolateWord_Braced(
            string Text,
            int WordBx,
            ScanPatternResults NonWordResults,
            ref WordCursor Results,
            TextTraits Traits)
        {
            string wordText;
            int    Lx, Ix;

            int braceIx = NonWordResults.FoundPos;

            char braceChar = NonWordResults.FoundPat.LeadChar;

            if (Traits.BracedTreatment == ScannerBracedTreatment.Parts)
            {
                // a standalone open brace char. the brace char is the word ( and it will
                // also be the delim )
                if (WordBx == braceIx)
                {
                    Results.SetWord(
                        NonWordResults.FoundPat.PatternValue,
                        WordClassification.OpenContentBraced, WordBx, braceChar);
                }
                else
                {
                    wordText =
                        Text.Substring(WordBx, braceIx - WordBx);
                    Results.SetWord(
                        wordText, WordClassification.OpenNamedBraced, WordBx, braceChar);
                }
            }

            // the whole braced word.  braced word runs all the way to the closing brace.
            else if (Traits.BracedTreatment == ScannerBracedTreatment.Whole)
            {
                int remLx = Text.Length - braceIx;
                Ix = ScanCloseBrace(
                    Text,
                    braceIx, remLx, Traits.QuoteEncapsulation);
                if (Ix == -1)
                {
                    throw new ApplicationException(
                              "Closing brace not found starting at position " +
                              braceIx + " in " + Text);
                }
                Lx       = Ix - WordBx + 1;
                wordText = Text.Substring(WordBx, Lx);
                if (WordBx == braceIx)
                {
                    Results.SetWord(
                        wordText, WordClassification.ContentBraced, WordBx, braceChar);
                }
                else
                {
                    Results.SetWord(
                        wordText, WordClassification.NamedBraced, WordBx, braceChar);
                }
            }
        }
        // ----------------------- ScanWord_IsolatedWord_Braced -----------------------
        private static void ScanWord_IsolateWord_Braced(
            BoundedString InBoundedString,
            int InWordBx,
            ScanPatternResults InNonWordResults,
            ref WordCursor InOutResults,
            TextTraits InTraits)
        {
            string wordText;
            int    Lx, Ix;

            int braceIx = InNonWordResults.FoundPos;

            char braceChar = InNonWordResults.FoundPat.LeadChar;

            if (InTraits.BracedTreatment == ScannerBracedTreatment.Parts)
            {
                // a standalone open brace char. the brace char is the word ( and it will
                // also be the delim )
                if (InWordBx == braceIx)
                {
                    InOutResults.SetWord(
                        InNonWordResults.FoundPat.PatternValue,
                        WordClassification.OpenContentBraced, InWordBx, braceChar);
                }
                else
                {
                    wordText =
                        InBoundedString.String.Substring(InWordBx, braceIx - InWordBx);
                    InOutResults.SetWord(
                        wordText, WordClassification.OpenNamedBraced, InWordBx, braceChar);
                }
            }

            // the whole braced word.  braced word runs all the way to the closing brace.
            else if (InTraits.BracedTreatment == ScannerBracedTreatment.Whole)
            {
                Ix = ScanCloseBrace(
                    InBoundedString.String,
                    braceIx, InBoundedString.Ex, InTraits.QuoteEncapsulation);
                if (Ix == -1)
                {
                    throw new ApplicationException(
                              "Closing brace not found starting at position " +
                              braceIx + " in " + InBoundedString.String);
                }
                Lx       = Ix - InWordBx + 1;
                wordText = InBoundedString.String.Substring(InWordBx, Lx);
                if (InWordBx == braceIx)
                {
                    InOutResults.SetWord(
                        wordText, WordClassification.ContentBraced, InWordBx, braceChar);
                }
                else
                {
                    InOutResults.SetWord(
                        wordText, WordClassification.NamedBraced, InWordBx, braceChar);
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Construct the Stmt from string with the cursor position AT the first word
        /// of the statement.
        /// TextTraits are the traits of the first word cursor.
        /// </summary>
        /// <param name="InString"></param>
        /// <param name="InCsr"></param>
        public Stmt(string InStmtText, WordCursor InStartCsr)
        {
            StmtTraits         traits  = new StmtTraits(InStartCsr.TextTraits);
            StmtWord           topWord = StmtElem.FirstPass(InStmtText, InStartCsr, traits);
            StmtWordListCursor wlCsr   = topWord.SubWords.PositionBegin();

            Parse_Common(InStmtText, wlCsr, traits);
        }
Beispiel #12
0
        // ----------------------- PositionBeginWord -----------------------------
        // position at begin of string to scan.
        public static WordCursor PositionBeginWord(string Text, TextTraits Traits)
        {
            WordCursor word = new WordCursor( );

            word.Position = RelativePosition.Begin;
            word.SetTraits(Traits);
            return(word);
        }
        // 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);
        }
        // ------------------------ ScanNextWord -------------------------
        // Scans to the next word in the string. ( a word being the text bounded by the
        // delimeter and whitespace characters as spcfd in the TextTraits argument )
        // Return null when end of string.
        public static WordCursor ScanNextWord(
            string Text,
            WordCursor CurrentWord)
        {
            BoundedString boundedString = new BoundedString(Text);
            WordCursor    res           = ScanNextWord(boundedString, CurrentWord);

            return(res);
        }
 // ------------------------- AssignDelimPart ---------------------------
 // set the delim properies of the cursor to the corr values in another
 // cursor.
 public void AssignDelimPart(WordCursor InWord)
 {
     mDelimBx                = InWord.DelimBx;
     mDelim                  = InWord.mDelim;
     mDelimIsWhitespace      = InWord.mDelimIsWhitespace;
     this.DelimClass         = InWord.mDelimClass;
     mWhitespaceFollowsWord  = InWord.mWhitespaceFollowsWord;
     mWhitespaceFollowsDelim = InWord.mWhitespaceFollowsDelim;
 }
Beispiel #16
0
 public void BeginValue( )
 {
     mCsr = new WordCursor( )
            .SetTraits(CsvString.mTraits)
            .SetString(CsvString.String);
     mCsr.Position      = RelativePosition.Begin;
     mValueNx           = -1;
     mAtFinalEmptyValue = false;
 }
Beispiel #17
0
        /// <summary>
        /// position a cursor before a character location in the string.
        /// </summary>
        /// <param name="InText"></param>
        /// <param name="InIx"></param>
        /// <returns></returns>
        public static WordCursor PositionBefore(string InText, int InIx, TextTraits InTraits)
        {
            WordCursor csr = new WordCursor();

            csr.Position   = RelativePosition.Before;
            csr.WordBx     = InIx;
            csr.TextTraits = InTraits;
            return(csr);
        }
Beispiel #18
0
 public StmtWord(
     string InStmtText,
     StmtWord InParent, WordCursor InWordCursor, WordCompositeCode InCompositeCode)
 {
     mStmtText      = InStmtText;
     mSubWords      = null;
     mWordCursor    = InWordCursor;
     mCompositeCode = InCompositeCode;
     Parent         = InParent;
 }
Beispiel #19
0
        public static StmtWord FirstPass(string InStmtText, StmtTraits InTraits)
        {
            StmtWord topWord = new StmtWord(InStmtText, null, null);

            WordCursor csr = Scanner.PositionBeginWord(InStmtText, InTraits);

            FirstPass(InStmtText, InTraits, csr, topWord);

            return(topWord);
        }
Beispiel #20
0
        // build the first pass StmtWord tree starting from a WordCursor position in the
        // stmt text.
        public static StmtWord FirstPass(
            string InStmtText, WordCursor InStartCsr, StmtTraits InTraits)
        {
            WordCursor csr     = null;
            StmtWord   topWord = new StmtWord(InStmtText, null, null);

            csr = Scanner.PositionBeforeWord(InStartCsr);
            FirstPass(InStmtText, InTraits, csr, topWord);
            return(topWord);
        }
Beispiel #21
0
        public WordCursor PositionBefore(int InIx, TextTraits InTraits)
        {
            WordCursor csr = new WordCursor();

            ThrowOutsideBounds(InIx);
            csr.Position   = RelativePosition.Before;
            csr.WordBx     = InIx;
            csr.TextTraits = InTraits;
            return(csr);
        }
Beispiel #22
0
 public WordCursor(WordCursor InWord)
 {
     mWordValue         = InWord.mWordValue;
     mWordBx            = InWord.WordBx;
     mDelimBx           = InWord.DelimBx;
     mDelim             = InWord.mDelim;
     mDelimIsWhitespace = InWord.mDelimIsWhitespace;
     mRltv   = InWord.mRltv;
     mTraits = InWord.mTraits;
     mString = InWord.mString;
 }
Beispiel #23
0
 public void NextValue()
 {
     if (mCursor.Position == RelativePosition.Begin)
     {
         mCursor = Scanner.ScanFirstWord(mCsvString, mTraits);
     }
     else
     {
         mCursor = Scanner.ScanNextWord(mCsvString, mCursor);
     }
 }
Beispiel #24
0
        // ------------------------ ScanFirstWord -------------------------
        public static WordCursor ScanFirstWord(
            BoundedString InBoundedString, TextTraits InTraits)
        {
            WordCursor csr = new WordCursor();

            csr.Position   = RelativePosition.Begin;
            csr.TextTraits = InTraits;
            WordCursor res = ScanNextWord(InBoundedString, csr);

            return(res);
        }
Beispiel #25
0
        public CsvCursor(string InCsvString)
        {
            mTraits = new TextTraits();
            mTraits.DividerPatterns.AddDistinct(",", Enums.DelimClassification.DividerSymbol);
            mTraits.OpenNamedBracedPatterns.Replace("[", Enums.DelimClassification.OpenNamedBraced);

            mCursor            = new WordCursor();
            mCursor.TextTraits = mTraits;
            mCursor.Position   = RelativePosition.Begin;
            mCsvString         = InCsvString;
        }
Beispiel #26
0
 bool Parse_Assignment_IsMemberDelim(WordCursor InCsr)
 {
     if (InCsr.DelimClass != DelimClassification.DividerSymbol)
     {
         return(false);
     }
     else if
     (TopStmt.StmtTraits.ExpressionPatterns.Contains(InCsr.DelimValue[0]) == true)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 public WordCursor(WordCursor InWord)
 {
     mWord                   = InWord.mWord;
     mWordBx                 = InWord.WordBx;
     mDelimBx                = InWord.DelimBx;
     mDelim                  = InWord.mDelim;
     mDelimIsWhitespace      = InWord.mDelimIsWhitespace;
     this.DelimClass         = InWord.mDelimClass;
     mWhitespaceFollowsWord  = InWord.mWhitespaceFollowsWord;
     mWhitespaceFollowsDelim = InWord.mWhitespaceFollowsDelim;
     mRltv                   = InWord.mRltv;
     mTraits                 = InWord.mTraits;
     mString                 = InWord.mString;
     mStayAtFlag             = InWord.mStayAtFlag;
     mVirtualCursor          = InWord.mVirtualCursor;
 }
        /// <summary>
        /// calc if the word starting at InBx is part of a path.
        /// </summary>
        /// <param name="InBoundedString"></param>
        /// <param name="InTraits"></param>
        /// <param name="InBx"></param>
        /// <returns></returns>
        private static bool ScanWord_IsolateDelim_IsPathPart(
            BoundedString InBoundedString, TextTraits InTraits, int InBx)
        {
            bool rc = false;

            WordCursor csr = InBoundedString.PositionBefore(InBx, InTraits);

            csr = ScanNextWord(InBoundedString, csr);

            if ((csr.IsPathPart == true))
            {
                rc = true;
            }

            return(rc);
        }
Beispiel #29
0
 bool Parse_CSV_IsAcceptableDelimiter(WordCursor InCsr)
 {
     if (InCsr.DelimClass == DelimClassification.EndOfString)
     {
         return(true);
     }
     else if
     ((InCsr.DelimClass == DelimClassification.DividerSymbol) &&
      (InCsr.DelimValue == ","))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        // --------------------------- ScanWord_IsolateDelim_SetDelimIsWhitespace ----------
        private static void ScanWord_IsolateDelim_SetDelimIsWhitespace(
            BoundedString InBoundedString, TextTraits InTraits,
            WordCursor InOutResults, int InWsIx)
        {
            // store the actual string of whitespace characters. ( the whitespace can be
            // checked later to see if it contains tabs or newlines )
            ScanPatternResults spr = ScanNotEqual(
                InBoundedString.String, InWsIx, InBoundedString.Ex,
                InTraits.WhitespacePatterns);

            string delimVlu = spr.ScannedOverString;

            InOutResults.SetDelim(
                InBoundedString, delimVlu, InWsIx, DelimClassification.Whitespace);

            InOutResults.DelimIsWhitespace = true;
        }