Parse() public méthode

Parse - move to next token.
public Parse ( ) : string
Résultat string
Exemple #1
0
        /// <summary>
        /// Parses a sub-formatter
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="outputIndex">the index in the output record for the sub-formatter</param>
        /// <returns>the parsed <see cref="ISubFormatter"/></returns>
        private ISubFormatter ParseSubFormatter(Lexer lexer, ref int outputIndex)
        {
            var element = lexer.Parse();
            var column  = element.IndexOf(':');

            if (column != -1)
            {
                outputIndex = int.Parse(element.Substring(0, column)) - 1;
                element     = element.Substring(column + 1);
            }
            ISubFormatter subFormatter;
            Match         match;

            if ((match = StringConstantRegex.Match(element)).Success)
            {
                var constant = lexer.Parse();
                constant     = constant.Substring(1, constant.Length - 2);
                subFormatter = GetStringConstantFormatter(GetN(match), constant, outputIndex);
            }
            else if ((match = HexOfSpaceRegex.Match(element)).Success)
            {
                if (lexer.Current != null && lexer.Current.StartsWith("'"))
                {
                    subFormatter = GetHexConstantFormatter(GetN(match), lexer.Parse(), outputIndex);
                }
                else
                {
                    subFormatter = GetStringConstantFormatter(GetN(match), " ", outputIndex);
                }
            }
            else
            {
                var start  = int.Parse(element) - 1;
                var length = lexer.ParseInt();
                if (NumberFormats.Contains(lexer.Current))
                {
                    subFormatter = ParseEditFormatter(start, length, outputIndex, lexer);
                }
                else
                {
                    subFormatter = new CopyFormatter
                    {
                        InputIndex  = start,
                        Length      = length,
                        OutputIndex = outputIndex
                    };
                }
            }
            outputIndex += subFormatter.Length;

            return(subFormatter);
        }
        /// <summary>
        /// Parses an <see cref="IFilter{T}"/>.
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="defaultFormat">the default format</param>
        /// <returns>an <see cref="IFilter{T}"/></returns>
        private IFilter <byte[]> ParseFilter(Lexer lexer, string defaultFormat)
        {
            IFilter <byte[]> filter = null;

            if (lexer.MoveNext())
            {
                if (lexer.Current == OpeningPar)
                {
                    filter = ParseFilter(lexer, defaultFormat);
                    lexer.Parse(ClosingPar);
                }
                else
                {
                    string format1;
                    string format2;
                    var    leftAccessor  = ParseAccessor(lexer, defaultFormat, out format1);
                    var    op            = lexer.Parse();
                    var    rightAccessor = ParseAccessor(lexer, defaultFormat, out format2);
                    var    format        = format1 ?? format2;
                    filter = GetFilter(leftAccessor, rightAccessor, format, op);
                }

                if (lexer.Current == Or)
                {
                    var disjunction = new DisjunctionFilter <byte[]>
                    {
                        Filters = new List <IFilter <byte[]> >
                        {
                            filter, ParseFilter(lexer, defaultFormat)
                        }
                    };
                    filter = disjunction;
                }
                else if (lexer.Current == And)
                {
                    var conjunction = new ConjunctionFilter <byte[]>
                    {
                        Filters = new List <IFilter <byte[]> >
                        {
                            filter, ParseFilter(lexer, defaultFormat)
                        }
                    };
                    filter = conjunction;
                }
            }

            return(filter);
        }
Exemple #3
0
        // Retrieves the parameter of a command so that it can be parsed by a specific parser.
        private static string ParseCommandParameters(Lexer lexer)
        {
            var start = lexer.Index;

            lexer.Parse(OpeningPar);

            while (lexer.MoveNext() && lexer.Current != ClosingPar)
            {
            }

            var length = lexer.Index - start - 1;

            lexer.Parse(ClosingPar);

            return(lexer.SubString(start, length));
        }
Exemple #4
0
        /// <summary>
        /// Parses an accessor.
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="defaultFormat">the default format</param>
        /// <returns>the parsed <see cref="IAccessor{T}"/></returns>
        private IAccessor <decimal> ParseAccessor(Lexer lexer, string defaultFormat)
        {
            var start  = lexer.ParseInt() - 1;
            var length = lexer.ParseInt();
            var format = defaultFormat;

            if (Formats.Contains(lexer.Current) || lexer.Current.StartsWith(AsciiDecimalFormat))
            {
                format = lexer.Parse();
            }
            return((IAccessor <decimal>)GetAccessor(start, length, format, Encoding));
        }
        /// <summary>
        /// Parses an individual comparer.
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="defaultFormat">the default format</param>
        /// <returns>a single <see cref="IComparer{T}"/></returns>
        private IComparer <byte[]> ParseComparer(Lexer lexer, string defaultFormat)
        {
            var    start  = lexer.ParseInt() - 1;
            var    length = lexer.ParseInt();
            string format;

            if (lexer.Current == AscendingOrder || lexer.Current == DescendingOrder)
            {
                // if we have the order token no format is specified, thus use the default one
                format = defaultFormat;
            }
            else
            {
                // otherwise the current token is the format
                format = lexer.Parse();
            }
            var ascending = lexer.Current == AscendingOrder;

            IComparer <byte[]> comparer;

            if (format == StringFormat)
            {
                comparer = new StringComparer
                {
                    Encoding     = Encoding,
                    SortEncoding = SortEncoding,
                    Ascending    = ascending,
                    Start        = start,
                    Length       = length
                };
            }
            else
            {
                var accessor = GetAccessor(start, length, format, Encoding) as IAccessor <decimal>;
                comparer = new DefaultComparer <decimal> {
                    Ascending = ascending, Accessor = accessor
                };
            }

            return(comparer);
        }
Exemple #6
0
        /// <summary>
        /// Gets a formatter from its configuration card.
        /// </summary>
        /// <param name="configuration">a formatter configuration card</param>
        /// <returns>the corresponding <see cref="LegacyFormatter"/></returns>
        public LegacyFormatter GetFormatter(string configuration)
        {
            var lexer = new Lexer(configuration);
            IList <ISubFormatter> formatters = null;

            if (lexer.MoveNext())
            {
                var parentheses = lexer.Current == OpeningPar;
                if (parentheses)
                {
                    lexer.MoveNext();
                }
                formatters = ParseSubFormatters(lexer);
                if (parentheses)
                {
                    lexer.Parse(ClosingPar);
                }
            }

            return(new LegacyFormatter {
                Formatters = formatters, Encoding = Encoding
            });
        }
        // Retrieves the parameter of a command so that it can be parsed by a specific parser.
        private static string ParseCommandParameters(Lexer lexer)
        {
            var start = lexer.Index;
            lexer.Parse(OpeningPar);

            while (lexer.MoveNext() && lexer.Current != ClosingPar) { }

            var length = lexer.Index - start - 1;
            lexer.Parse(ClosingPar);

            return lexer.SubString(start, length);
        }
Exemple #8
0
        /// <summary>
        /// Parses an <see cref="IFilter{T}"/>.
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="defaultFormat">the default format</param>
        /// <returns>an <see cref="IFilter{T}"/></returns>
        private IFilter<byte[]> ParseFilter(Lexer lexer, string defaultFormat)
        {
            IFilter<byte[]> filter = null;

            if (lexer.MoveNext())
            {
                if (lexer.Current == OpeningPar)
                {
                    filter = ParseFilter(lexer, defaultFormat);
                    lexer.Parse(ClosingPar);
                }
                else
                {
                    string format1;
                    string format2;
                    var leftAccessor = ParseAccessor(lexer, defaultFormat, out format1);
                    var op = lexer.Parse();
                    var rightAccessor = ParseAccessor(lexer, defaultFormat, out format2);
                    var format = format1 ?? format2;
                    filter = GetFilter(leftAccessor, rightAccessor, format, op);
                }

                if (lexer.Current == Or)
                {
                    var disjunction = new DisjunctionFilter<byte[]>
                    {
                        Filters = new List<IFilter<byte[]>>
                        {
                            filter, ParseFilter(lexer, defaultFormat)
                        }
                    };
                    filter = disjunction;
                }
                else if (lexer.Current == And)
                {
                    var conjunction = new ConjunctionFilter<byte[]>
                    {
                        Filters = new List<IFilter<byte[]>>
                        {
                            filter, ParseFilter(lexer, defaultFormat)
                        }
                    };
                    filter = conjunction;
                }
            }

            return filter;
        }
        public string ExtractElement(Lexer lexer, string Info, int recordLength)
        {
            string Content = "";
            int currentLength = 0;
            while (Info != ClosingPar)
            {
                
                var parentheses = Info == (OpeningPar);
                if (parentheses)
                {
                    Info = lexer.Parse();
                }
                var matches = headerRegex.Matches(Info);
                if (matches.Count == 1)
                {
                    string[] tokens = Info.Split(':');
                    if (tokens.Length == 2)
                    {
                        int lengthOfField = Convert.ToInt16(tokens[0]);
                        String temp = tokens[1].PadLeft(lengthOfField - currentLength, space);
                        Content += temp;
                        currentLength += temp.Length;

                    }

                }
                else if (Info.Contains("/") && string.IsNullOrWhiteSpace(Info.Replace("/", "")))
                {
                    if (recordLength == 0)
                    {
                        Content += Info.Replace("/", System.Environment.NewLine);
                    }
                    else
                    {
                        if (currentLength < recordLength)
                        {
                            String x = "".PadRight(recordLength - currentLength, space);
                            Content += x;
                        }
                    }
                   
                    currentLength = 0;
                }
                else
                {
                     String temp = Info.Replace("'", "");
                     Content += temp;
                     currentLength += temp.Length;
                }
               
                Info = lexer.Parse();
                if (string.IsNullOrWhiteSpace(Info))
                {
                    break;
                }
            }
            return Content;
        }
Exemple #10
0
 /// <summary>
 /// Parses an accessor.
 /// </summary>
 /// <param name="lexer">the lexer to read the tokens from</param>
 /// <param name="defaultFormat">the default format</param>
 /// <returns>the parsed <see cref="IAccessor{T}"/></returns>
 private IAccessor<decimal> ParseAccessor(Lexer lexer, string defaultFormat)
 {
     var start = lexer.ParseInt() - 1;
     var length = lexer.ParseInt();
     var format = defaultFormat;
     if (Formats.Contains(lexer.Current))
     {
         format = lexer.Parse();
     }
     return (IAccessor<decimal>) GetAccessor(start, length, format, Encoding);
 }
        /// <summary>
        /// Parses an individual comparer.
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="defaultFormat">the default format</param>
        /// <returns>a single <see cref="IComparer{T}"/></returns>
        private IComparer<byte[]> ParseComparer(Lexer lexer, string defaultFormat)
        {
            var start = lexer.ParseInt() - 1;
            var length = lexer.ParseInt();
            string format;

            if (lexer.Current == AscendingOrder || lexer.Current == DescendingOrder)
            {
                // if we have the order token no format is specified, thus use the default one
                format = defaultFormat;
            }
            else
            {
                // otherwise the current token is the format
                format = lexer.Parse();
            }
            var ascending = lexer.Current == AscendingOrder;

            IComparer<byte[]> comparer;
            if (format == StringFormat)
            {
                comparer = new StringComparer
                {
                    Encoding = Encoding,
                    SortEncoding = SortEncoding,
                    Ascending = ascending,
                    Start = start,
                    Length = length
                };
            }
            else
            {
                var accessor = GetAccessor(start, length, format, Encoding) as IAccessor<decimal>;
                comparer = new DefaultComparer<decimal> { Ascending = ascending, Accessor = accessor };
            }

            return comparer;
        }
Exemple #12
0
        /// <summary>
        /// Parses a numeric edit formatter.
        /// </summary>
        /// <param name="start">the index of the first byte to read in the input record</param>
        /// <param name="length">the length of the column to read in the input record</param>
        /// <param name="outputIndex">the index in the output record for the sub-formatter</param>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <returns>the parsed <see cref="NumericEditFormatter"/></returns>
        private NumericEditFormatter ParseEditFormatter(int start, int length, int outputIndex, Lexer lexer)
        {
            var format  = lexer.Parse();
            var pattern = lexer.Parse();

            string edit;
            string positiveSign = DefaultPositiveSign;
            string negativeSign = DefaultNegativeSign;

            if (pattern == "EDIT=")
            {
                var sb = new StringBuilder();
                lexer.Parse(OpeningPar);
                do
                {
                    sb.Append(",").Append(lexer.Current);
                } while (lexer.MoveNext() && lexer.Current != ClosingPar);
                edit = sb.ToString().Substring(1);
                lexer.Parse(ClosingPar);
            }
            else
            {
                var mask = Masks[pattern];
                edit         = mask.Pattern;
                positiveSign = mask.PositiveSign;
                negativeSign = mask.NegativeSign;
            }
            var editLength = edit.Length;

            while (IsPartOfEdit(lexer.Current))
            {
                var element = lexer.Parse();
                if (element.StartsWith(Length))
                {
                    editLength = int.Parse(element.Substring(Length.Length));
                }
                else
                {
                    lexer.Parse(OpeningPar);
                    positiveSign = lexer.Parse();
                    if (lexer.Current == ClosingPar)
                    {
                        // We actually only have the negative sign
                        negativeSign = positiveSign;
                        positiveSign = DefaultPositiveSign;
                    }
                    else
                    {
                        negativeSign = lexer.Parse();
                    }
                    lexer.Parse(ClosingPar);
                }
            }

            return(new NumericEditFormatter
            {
                Accessor = (IAccessor <decimal>)GetAccessor(start, length, format, Encoding),
                Edit = edit, Encoding = Encoding, Length = editLength,
                PositiveSign = positiveSign, NegativeSign = negativeSign, OutputIndex = outputIndex
            });
        }