RewriteRuleNodeStream.cs revision 324c4644fee44b9898524c09511bd33c3f12e2df
1/*
2[The "BSD licence"]
3Copyright (c) 2005-2007 Kunle Odutola
4Copyright (c) 2007 Johannes Luber
5All rights reserved.
6
7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions
9are met:
101. Redistributions of source code MUST RETAIN the above copyright
11   notice, this list of conditions and the following disclaimer.
122. Redistributions in binary form MUST REPRODUCE the above copyright
13   notice, this list of conditions and the following disclaimer in
14   the documentation and/or other materials provided with the
15   distribution.
163. The name of the author may not be used to endorse or promote products
17   derived from this software without specific prior WRITTEN permission.
184. Unless explicitly state otherwise, any contribution intentionally
19   submitted for inclusion in this work to the copyright owner or licensor
20   shall be under the terms and conditions of this license, without any
21   additional terms or conditions.
22
23THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*/
34
35
36namespace Antlr.Runtime.Tree {
37	using System;
38	using System.Collections.Generic;
39
40	/// <summary>
41	/// Queues up nodes matched on left side of -> in a tree parser. This is
42	/// the analog of RewriteRuleTokenStream for normal parsers.
43	/// </summary>
44	public class RewriteRuleNodeStream : RewriteRuleElementStream {
45		public RewriteRuleNodeStream(ITreeAdaptor adaptor, string elementDescription)
46			: base(adaptor, elementDescription) {
47		}
48
49		/// <summary>Create a stream with one element</summary>
50		public RewriteRuleNodeStream(
51			ITreeAdaptor adaptor,
52			string elementDescription,
53			object oneElement
54		) : base(adaptor, elementDescription, oneElement) {
55		}
56
57		/// <summary>Create a stream, but feed off an existing list</summary>
58		public RewriteRuleNodeStream(
59			ITreeAdaptor adaptor,
60			string elementDescription,
61            IList<object> elements
62		) : base(adaptor, elementDescription, elements) {
63		}
64
65		public object NextNode() {
66            return NextTree();
67		}
68
69		override protected object ToTree(object el) {
70			return adaptor.DupNode(el);
71		}
72
73        protected override object Dup(object el) {
74            // we dup every node, so don't have to worry about calling dup; short-
75            // circuited next() so it doesn't call.
76            throw new NotSupportedException("dup can't be called for a node stream.");
77        }
78    }
79}
80