コード例 #1
0
ファイル: Parser.Char.cs プロジェクト: raizam/Pidgin
        /// <summary>
        /// Creates a parser which parses and returns a single character, in a case insensitive manner.
        /// The parser returns the actual character parsed.
        /// </summary>
        /// <param name="character">The character to parse</param>
        /// <returns>A parser which parses and returns a single character</returns>
        public static Parser <char, char> CIChar(char character)
        {
            var theChar  = char.ToLowerInvariant(character);
            var expected = ImmutableSortedSet.CreateRange(
                new[]
            {
                new Expected <char>(Rope.Create(char.ToUpperInvariant(character))),
                new Expected <char>(Rope.Create(char.ToLowerInvariant(character)))
            }
                );

            return(Token(c => char.ToLowerInvariant(c) == theChar)
                   .WithExpected(expected));
        }
コード例 #2
0
ファイル: Parser.OneOf.cs プロジェクト: 07101994/Pidgin
        /// <summary>
        /// Creates a parser which parses and returns one of the specified characters, in a case insensitive manner.
        /// The parser returns the actual character parsed.
        /// </summary>
        /// <param name="chars">A sequence of characters to choose between</param>
        /// <returns>A parser which parses and returns one of the specified characters, in a case insensitive manner.</returns>
        public static Parser <char, char> CIOneOf(IEnumerable <char> chars)
        {
            if (chars == null)
            {
                throw new ArgumentNullException(nameof(chars));
            }
            var cs      = chars.Select(char.ToLowerInvariant).ToArray();
            var builder = ImmutableSortedSet.CreateBuilder <Expected <char> >();

            foreach (var c in cs)
            {
                builder.Add(new Expected <char>(Rope.Create(char.ToLowerInvariant(c))));
                builder.Add(new Expected <char>(Rope.Create(char.ToUpperInvariant(c))));
            }
            return(Parser <char>
                   .Token(c => Array.IndexOf(cs, char.ToLowerInvariant(c)) != -1)
                   .WithExpected(builder.ToImmutable()));
        }
コード例 #3
0
 public TokenParser(TToken token)
     : base(ImmutableSortedSet.Create(new Expected <TToken>(Rope.Create(token))))
 {
     _token = token;
 }
コード例 #4
0
ファイル: Rope.cs プロジェクト: raizam/Pidgin
 public static Rope <T> CreateRange <T>(IEnumerable <T> items)
 => Rope <T> .Create(items.ToImmutableArray());
コード例 #5
0
ファイル: Rope.cs プロジェクト: raizam/Pidgin
 public static Rope <T> Create <T>(T item)
 => Rope <T> .Create(ImmutableArray.Create(item));
コード例 #6
0
ファイル: Parser.Token.cs プロジェクト: 07101994/Pidgin
 private protected override ImmutableSortedSet <Expected <TToken> > CalculateExpected()
 => ImmutableSortedSet.Create(new Expected <TToken>(Rope.Create(_token)));
コード例 #7
0
ファイル: Parser.OneOf.cs プロジェクト: 07101994/Pidgin
        /// <summary>
        /// Creates a parser which parses and returns one of the specified characters.
        /// </summary>
        /// <param name="chars">A sequence of characters to choose between</param>
        /// <returns>A parser which parses and returns one of the specified characters</returns>
        public static Parser <char, char> OneOf(IEnumerable <char> chars)
        {
            if (chars == null)
            {
                throw new ArgumentNullException(nameof(chars));
            }
            var cs = chars.ToArray();

            return(Parser <char>
                   .Token(c => Array.IndexOf(cs, c) != -1)
                   .WithExpected(ImmutableSortedSet.CreateRange(cs.Select(c => new Expected <char>(Rope.Create(c))))));
        }