예제 #1
0
        void OptimizeSingleItemParsers(IEnumerable <Parser> children)
        {
            var sequences = from r in children.OfType <SequenceParser>()
                            where
                            r.Items.Count == 1 &&
                            r.GetType() == typeof(SequenceParser)
                            select r;
            var alternations = from r in children.OfType <AlternativeParser>()
                               where
                               r.Items.Count == 1 &&
                               r.GetType() == typeof(AlternativeParser)
                               select r;

            var parsers = sequences.Cast <ListParser>().Union(alternations.Cast <ListParser>()).ToList();

            foreach (var parser in parsers)
            {
                var replacement = parser.Items[0];
                if (parser.Name != null)
                {
                    replacement = new UnaryParser {
                        Inner = replacement, Name = parser.Name
                    };
                }
                Replace(new ParserReplaceArgs(parser, replacement));
            }
        }
예제 #2
0
        public static Parser Named(this Parser parser, string name)
        {
            var unary = new UnaryParser(parser);

            unary.Name = name ?? Guid.NewGuid().ToString();
            return(unary);
        }
예제 #3
0
        void OptimizeSingleItemParsers()
        {
            var parsers = from r in Children.OfType <ListParser>()
                          where
                          r.Items.Count == 1 &&
                          (r is SequenceParser || r is AlternativeParser)
                          select r;

            foreach (var parser in parsers.ToList())
            {
                var replacement = parser.Items[0];
                if (parser.Name != null)
                {
                    replacement = new UnaryParser {
                        Inner = replacement, Name = parser.Name
                    };
                }
                Replace(new ParserReplaceArgs(parser, replacement));
            }
        }
예제 #4
0
 protected UnaryParser(UnaryParser other, ParserCloneArgs args)
     : base(other, args)
 {
     Inner = args.Clone(other.Inner);
 }
예제 #5
0
		void OptimizeSingleItemParsers(IEnumerable<Parser> children)
		{
			var sequences = from r in children.OfType<SequenceParser>()
				where
				r.Items.Count == 1
				&& r.GetType() == typeof(SequenceParser)
				select r;
			var alternations = from r in children.OfType<AlternativeParser>()
				where
				r.Items.Count == 1
				&& r.GetType() == typeof(AlternativeParser)
				select r;

			var parsers = sequences.Cast<ListParser>().Union(alternations.Cast<ListParser>()).ToList();
			foreach (var parser in parsers)
			{
				var replacement = parser.Items[0];
				if (parser.Name != null)
				{
					replacement = new UnaryParser { Inner = replacement, Name = parser.Name };
				}
				Replace(new ParserReplaceArgs(parser, replacement));
			}
		}
예제 #6
0
파일: UnaryParser.cs 프로젝트: Myvar/Eclang
 protected UnaryParser(UnaryParser other, ParserCloneArgs args)
     : base(other, args)
 {
     Inner = args.Clone(other.Inner);
 }