PageRenderTime 50ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/runtime/Java/src/main/java/org/antlr/runtime/tree/RewriteRuleTokenStream.java

https://bitbucket.org/jwalton/antlr3
Java | 78 lines | 35 code | 10 blank | 33 comment | 0 complexity | 906c2d66ef8d94dad664f0fb230c6b3c MD5 | raw file
  1. /*
  2. [The "BSD license"]
  3. Copyright (c) 2005-2009 Terence Parr
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. 1. Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. 3. The name of the author may not be used to endorse or promote products
  14. derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. package org.antlr.runtime.tree;
  27. import org.antlr.runtime.Token;
  28. import java.util.List;
  29. public class RewriteRuleTokenStream extends RewriteRuleElementStream {
  30. public RewriteRuleTokenStream(TreeAdaptor adaptor, String elementDescription) {
  31. super(adaptor, elementDescription);
  32. }
  33. /** Create a stream with one element */
  34. public RewriteRuleTokenStream(TreeAdaptor adaptor,
  35. String elementDescription,
  36. Object oneElement)
  37. {
  38. super(adaptor, elementDescription, oneElement);
  39. }
  40. /** Create a stream, but feed off an existing list */
  41. public RewriteRuleTokenStream(TreeAdaptor adaptor,
  42. String elementDescription,
  43. List<Object> elements)
  44. {
  45. super(adaptor, elementDescription, elements);
  46. }
  47. /** Get next token from stream and make a node for it */
  48. public Object nextNode() {
  49. Token t = (Token)_next();
  50. return adaptor.create(t);
  51. }
  52. public Token nextToken() {
  53. return (Token)_next();
  54. }
  55. /** Don't convert to a tree unless they explicitly call nextTree.
  56. * This way we can do hetero tree nodes in rewrite.
  57. */
  58. @Override
  59. protected Object toTree(Object el) {
  60. return el;
  61. }
  62. @Override
  63. protected Object dup(Object el) {
  64. throw new UnsupportedOperationException("dup can't be called for a token stream.");
  65. }
  66. }