1 /* 2 [The "BSD licence"] 3 Copyright (c) 2005-2007 Kunle Odutola 4 Copyright (c) 2007 Johannes Luber 5 All rights reserved. 6 7 Redistribution and use in source and binary forms, with or without 8 modification, are permitted provided that the following conditions 9 are met: 10 1. Redistributions of source code MUST RETAIN the above copyright 11 notice, this list of conditions and the following disclaimer. 12 2. 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. 16 3. The name of the author may not be used to endorse or promote products 17 derived from this software without specific prior WRITTEN permission. 18 4. 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 23 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 36 namespace Antlr.Runtime.Tree { 37 using System; 38 using System.Collections.Generic; 39 40 /// <summary> 41 /// </summary> 42 /// <remarks></remarks> 43 /// <example></example> 44 public class RewriteRuleTokenStream : RewriteRuleElementStream { RewriteRuleTokenStream(ITreeAdaptor adaptor, string elementDescription)45 public RewriteRuleTokenStream(ITreeAdaptor adaptor, string elementDescription) 46 : base(adaptor, elementDescription) { 47 } 48 49 /// <summary> 50 /// Create a stream with one element 51 /// </summary> RewriteRuleTokenStream( ITreeAdaptor adaptor, string elementDescription, object oneElement )52 public RewriteRuleTokenStream( 53 ITreeAdaptor adaptor, 54 string elementDescription, 55 object oneElement 56 ) : base(adaptor, elementDescription, oneElement) { 57 } 58 59 /// <summary>Create a stream, but feed off an existing list</summary> RewriteRuleTokenStream( ITreeAdaptor adaptor, string elementDescription, IList<object> elements )60 public RewriteRuleTokenStream( 61 ITreeAdaptor adaptor, 62 string elementDescription, 63 IList<object> elements 64 ) : base(adaptor, elementDescription, elements) { 65 } 66 67 /// <summary> 68 /// Get next token from stream and make a node for it. 69 /// </summary> 70 /// <remarks> 71 /// ITreeAdaptor.Create() returns an object, so no further restrictions possible. 72 /// </remarks> NextNode()73 public virtual object NextNode() { 74 return adaptor.Create((IToken) NextTree()); 75 } 76 NextToken()77 public virtual IToken NextToken() { 78 return (IToken) NextTree(); 79 } 80 81 /// <summary> 82 /// 83 /// Don't convert to a tree unless they explicitly call NextTree(). 84 /// This way we can do hetero tree nodes in rewrite. 85 /// </summary> ToTree(object el)86 override protected object ToTree(object el) { 87 return el; 88 } 89 Dup(object el)90 protected override object Dup(object el) { 91 throw new NotSupportedException("dup can't be called for a token stream."); 92 } 93 } 94 } 95