Ejemplo n.º 1
0
        public TextTraits(TextTraits Traits)
            : this()
        {
            mWhitespacePatterns.Replace(Traits.mWhitespacePatterns);
            mNewLinePatterns.Replace(Traits.mNewLinePatterns);

            mDividerPatterns.Replace(Traits.mDividerPatterns);
            this.DividerDelimClasses = Traits.DividerDelimClasses;
            mCommentToEndPatterns.Replace(Traits.mCommentToEndPatterns);

            mQuotePatterns.Replace(Traits.mQuotePatterns);
            this.VerbatimLiteralPattern = Traits.VerbatimLiteralPattern;

            mExpressionPatterns.Replace(Traits.mExpressionPatterns);
            mEndStmtPatterns.Replace(Traits.mEndStmtPatterns);
            mOpenNamedBracedPatterns.Replace(Traits.mOpenNamedBracedPatterns);
            mOpenContentBracedPatterns.Replace(Traits.mOpenContentBracedPatterns);
            mOpenBracedPatterns  = null;
            mCloseBracedPatterns = null;

            mPathSepPatterns.Replace(Traits.mPathSepPatterns);

            mNonWordPatterns = null;
            mQem             = Traits.mQem;
            mFormSentencesFromWhitespaceDelimWords =
                Traits.mFormSentencesFromWhitespaceDelimWords;
        }
Ejemplo n.º 2
0
 public CsvBuilder()
 {
     mTraits = new TextTraits();
     mTraits.DividerPatterns.AddDistinct(",", Enums.DelimClassification.DividerSymbol);
     mTraits.OpenNamedBracedPatterns.Replace("(", Enums.DelimClassification.OpenNamedBraced);
     mTraits.QuoteEncapsulation = QuoteEncapsulation.Double;
 }
Ejemplo n.º 3
0
        public WordValue(string InValue, TextTraits InTraits)
        {
            CharObjectPair results = Stringer.CalcWordClassification(InValue, InTraits);

            CommonConstruct(
                InValue, (WordClassification)results.b, InTraits, results.a);
        }
Ejemplo n.º 4
0
        // ------------------------ ScanFirstWord -------------------------
        public static WordCursor ScanFirstWord(string InString, TextTraits InTraits)
        {
            BoundedString boundedString = new BoundedString(InString);
            WordCursor    res           = ScanFirstWord(boundedString, InTraits);

            return(res);
        }
Ejemplo n.º 5
0
 public CsvString( )
 {
     Empty( );
     mTraits            = new TextTraits( );
     mTraits.DelimChars = new char[] { ',' };
     mTraits.BraceChars = new char[] { '(' };
 }
        // ----------------------- 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_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_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);
        }
Ejemplo n.º 9
0
 public ScanNonWordxResults(
     TextTraits InTextTraits, ScannerNonWord InNonWord, ScanCharResults InCharResults)
 {
     mTextTraits  = InTextTraits;
     mNonWord     = InNonWord;
     mCharResults = InCharResults;
 }
        // ----------------------- 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);
                }
            }
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
 // ----------------------------- constructor ---------------------------
 public WordCursor()
 {
     EmptyWordParts();
     mTraits         = null;
     mString         = null;
     mStayAtFlag     = false;
     mVirtualCursor  = enumVirtualCursor.None;
     this.DelimClass = DelimClassification.NotAssigned;
 }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
 void ConstructCommon()
 {
     Empty();
     mTraits = new TextTraits();
     mTraits.DividerPatterns.AddDistinct(",", DelimClassification.DividerSymbol);
     mTraits.OpenNamedBracedPatterns.Replace("(", DelimClassification.OpenNamedBraced);
     mTraits.QuoteEncapsulation = QuoteEncapsulation.Double;
     EncapsulateValues          = false;
 }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        IsolateNumericLiteral(
            ScanStream ScanStream,
            TextTraits Traits,
            int Bx)
        {
            // for now, all numeric literals are simple integers.
            // have to expand to determine if a float, decimal, what the sign is,
            // what the precision is.
            LiteralType litType = LiteralType.Integer;

            string             litText = null;
            PatternScanResults nonWord = null;

            // step from char to char. Look for a char that is not part of the
            // numeric literal.
            int ix    = Bx;
            int litEx = Bx;

            while (true)
            {
                if (ix >= ScanStream.Stream.Length)
                {
                    break;
                }
                char ch1 = ScanStream.Stream[ix];
                if (Char.IsDigit(ch1) == false)
                {
                    break;
                }

                litEx = ix;
                ix   += 1;
            }

            // isolate the numeric literal.
            int lx = litEx - Bx + 1;

            litText = ScanStream.Substring(Bx, lx);

            // isolate the delim that follows that numeric literal.
            int bx = litEx + 1;

            if (bx < ScanStream.Stream.Length)
            {
                nonWord = Scanner.ScanEqualAny(ScanStream.Stream, bx, Traits.DelimPatterns);
//        foundPat = rv.Item1;
//        foundIx = rv.Item2;
//        foundLx = rv.Item3;
//        nonWord = rv.Item3;
            }

            return(new Tuple <LiteralType, string, PatternScanResults>(
                       litType, litText, nonWord));
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
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;
 }
Ejemplo n.º 19
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;
        }
Ejemplo n.º 20
0
        public static TextLinesWordCursor ScanFirstWord(
            TextLines InLines, TextTraits InTraits)
        {
            TextLinesWordCursor csr = new TextLinesWordCursor();

            csr.Position   = RelativePosition.Begin;
            csr.TextTraits = InTraits;

            TextLinesWordCursor res = ScanNextWord(InLines, csr);

            return(res);
        }
Ejemplo n.º 21
0
        public TextWord(string Value, WordClassification WordClass, TextTraits Traits)
        {
            char?braceChar = null;

            if (WordClass.IsOpenBraced())
            {
                braceChar = Value[0];
                if (Traits.IsOpenBraceChar(braceChar.Value) == false)
                {
                    throw new ApplicationException("not an open brace char");
                }
            }

            CommonConstruct(Value, WordClass, Traits, braceChar);
        }
Ejemplo n.º 22
0
 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);
        }
        // --------------------------- 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;
        }
Ejemplo n.º 25
0
        private void CommonConstruct(
            string InValue, WordClassification InClass, TextTraits InTraits, char InBraceChar)
        {
            mValue     = InValue;
            mClass     = InClass;
            mTraits    = InTraits;
            mBraceChar = InBraceChar;

            // depending on word class, brace char must be specified or be blanks.
            if ((mClass == WordClassification.Braced) ||
                (mClass == WordClassification.NameBraced))
            {
                if (mBraceChar == ' ')
                {
                    throw(new ApplicationException("Brace character of braced word is missing"));
                }
            }
        }
        // -------------------- ScanWord_IsolatexWord ---------------------------
        private static TextLinesWordCursor ScanWord_IsolatexWord(
            TextLines InLines,
            TextLinesCursor InBxCsr,
            TextTraits InTraits)
        {
            TextLinesWordCursor tlwc   = null;
            TextLinesCursor     csr    = null;
            TextLinesCursor     endcsr = null;
            ScanPatternResults  spr    = null;

            csr = new TextLinesCursor(InBxCsr);
            char ch1 = InBxCsr.CursorChar;

            // look ahead to see if this word is braced.
            if (IsOpenQuoteChar(ch1) == false)
            {
                spr =
                    ScanEqualAny(csr.LineData, csr.LineOx, csr.LineData.Length - 1, InTraits.NonWordPatterns);
            }
            else
            {
                spr = new ScanPatternResults(-1);
            }

            // the rule is only braced words can span multiple lines. so if the word is
            // not braced, it can be parsed by the more general purpose IsolatexWord method.
            if ((IsOpenQuoteChar(ch1) == true) ||
                (InTraits.IsOpenBraceChar(spr.FoundChar.Value) == false))
            {
                ScanBoundedString bs = new ScanBoundedString(csr.LineData);
                WordCursor        wc = new WordCursor();
                wc.SetTraits(InTraits);
                ScanWord_IsolateWord(bs, csr.LineOx, ref wc, InTraits);
                endcsr =
                    new TextLinesCursor(csr.LinesNode, wc.ScanEx, AcRelativePosition.At);
                tlwc = new TextLinesWordCursor(wc, csr, endcsr);
            }

            else
            {
            }

            return(tlwc);
        }
Ejemplo n.º 27
0
        // ------------------------ AdvanceNextWord -------------------------
        // 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 void AdvancexNextWord(
            string InString,
            WordCursor InOutWordCursor,
            TextTraits InTraits)
        {
            int                Bx;
            BoundedString      boundedString = new BoundedString(InString);
            ScanPatternResults spr           = null;

            // calc scan start position
            Bx = ScanWord_CalcStartBx(boundedString, InOutWordCursor);

            // empty the word parts of the cursor.
            InOutWordCursor.EmptyWordParts();

            // advance past whitespace
            if (Bx <= boundedString.Ex)
            {
                Bx = ScanNotEqual(
                    boundedString.String, Bx, boundedString.Ex,
                    InTraits.WhitespacePatterns).FoundPos;
            }

            // got the start of something. scan for the delimeter ( could be the current char )
            spr = null;
            if (Bx <= boundedString.Ex)
            {
                spr = ScanWord_IsolateWord(boundedString, Bx, ref InOutWordCursor, InTraits);
            }

            // depending on the word, isolate and store the delim that follows.
            ScanWord_IsolateDelim(boundedString, spr, ref InOutWordCursor, InTraits);

            // current word position.
            if (InOutWordCursor.ScanEx == -1)
            {
                InOutWordCursor.Position = RelativePosition.End;
            }
            else
            {
                InOutWordCursor.Position = RelativePosition.At;
            }
        }
Ejemplo n.º 28
0
        // ------------------------ 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 InString,
            WordCursor InCurrentWord,
            TextTraits InTraits)
        {
            int        Bx;
            WordCursor results = new WordCursor( )
                                 .SetString(InString)
                                 .SetTraits(InTraits);

            // calc scan start position
            Bx = ScanWord_CalcStartBx(InString, InCurrentWord);

            // advance past whitespace
            if (Bx < InString.Length)
            {
                Bx = ScanNotEqual(InString, Bx, InTraits.WhitespaceChars).ResultPos;
            }

            // got the start of something. scan for the delimeter ( could be the current char )
            if (Bx < InString.Length)
            {
                ScanWord_IsolateWord(InString, Bx, ref results, InTraits);
            }

            // depending on the word, isolate and store the delim that follows.
            ScanWord_IsolateDelim(InString, Bx, ref results, InTraits);

            // current word position.
            if (results.ScanEx == -1)
            {
                results.RelativePosition = AcRelativePosition.End;
            }
            else
            {
                results.RelativePosition = AcRelativePosition.At;
            }

            return(results);
        }
Ejemplo n.º 29
0
        public TextWord(string Text, LiteralType LiteralType, TextTraits Traits)
        {
            mValue       = Text;
            _LiteralType = LiteralType;

            if (this.LiteralType.IsNumeric( ))
            {
                mClass = WordClassification.Numeric;
            }
            else if (this.LiteralType.IsQuoted( ))
            {
                mClass = WordClassification.Quoted;
            }
            else
            {
                throw new ApplicationException(
                          "LiteralType is not supported. " + LiteralType.ToString());
            }

            mTraits    = Traits;
            _BraceChar = null;
        }
Ejemplo n.º 30
0
        // ------------------------ AdvanceNextWord -------------------------
        // 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 void AdvanceNextWord(
            string InString,
            WordCursor InOutWordCursor,
            TextTraits InTraits)
        {
            int Bx;

            // calc scan start position
            Bx = ScanWord_CalcStartBx(InString, InOutWordCursor);

            // empty the word parts of the cursor.
            InOutWordCursor.EmptyWord( );

            // advance past whitespace
            if (Bx < InString.Length)
            {
                Bx = ScanNotEqual(InString, Bx, InTraits.WhitespaceChars).ResultPos;
            }

            // got the start of something. scan for the delimeter ( could be the current char )
            if (Bx < InString.Length)
            {
                ScanWord_IsolateWord(InString, Bx, ref InOutWordCursor, InTraits);
            }

            // depending on the word, isolate and store the delim that follows.
            ScanWord_IsolateDelim(InString, Bx, ref InOutWordCursor, InTraits);

            // current word position.
            if (InOutWordCursor.ScanEx == -1)
            {
                InOutWordCursor.RelativePosition = AcRelativePosition.End;
            }
            else
            {
                InOutWordCursor.RelativePosition = AcRelativePosition.At;
            }
        }