/// <inheritdoc />
        public SimpleClosedClassSegment(Parser parser, params object[] possibleMatches) : base(parser)
        {
            PossibleMatches = possibleMatches.Select(m =>
            {
                switch (m)
                {
                case string s:
                    return(new[] { s });

                case string[] array:
                    return(array);

                default: throw new ArgumentException($"Invalid match argument {m}");
                }
            }).ToArray();
            PossibleBeginnings = PossibleMatches.Select(a => a[0]).Distinct().ToArray();
            IsPossibleStart    = token => PossibleBeginnings.Contains(token);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public ClosedClassSegmentWithValue(Parser parser, params KeyValuePair <object, T>[] possibleMatches) : base(parser)
        {
            PossibleMatches = possibleMatches.Select(m =>
            {
                switch (m.Key)
                {
                case string s:
                    return(new KeyValuePair <string[], T>(new[] { s }, m.Value));

                case string[] array:
                    return(new KeyValuePair <string[], T>(array, m.Value));

                default: throw new ArgumentException($"Invalid match argument {m}");
                }
            }).ToArray();
            PossibleBeginnings = PossibleMatches.Select(p => p.Key[0]).Distinct().ToArray();
            IsPossibleStart    = token => PossibleBeginnings.Contains(token);
        }