/src/lib/parse/eiffel/eiffel_non_terminal_node_impl.e

http://github.com/tybor/Liberty · Specman e · 137 lines · 95 code · 19 blank · 23 comment · 0 complexity · 20b8a3cf10bb2ba120cbeef7589a0c9c MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class EIFFEL_NON_TERMINAL_NODE_IMPL
  5. inherit
  6. EIFFEL_NON_TERMINAL_NODE
  7. creation {EIFFEL_NODE_FACTORY}
  8. make
  9. feature {ANY}
  10. name: FIXED_STRING
  11. accept (visitor: VISITOR) is
  12. local
  13. v: EIFFEL_NON_TERMINAL_NODE_IMPL_VISITOR
  14. do
  15. v ::= visitor
  16. v.visit_eiffel_non_terminal_node_impl(Current)
  17. end
  18. name_at (index: INTEGER): FIXED_STRING is
  19. do
  20. Result := names.item(index - lower + names.lower)
  21. end
  22. node_at (index: INTEGER): EIFFEL_NODE is
  23. do
  24. Result := nodes.item(index)
  25. end
  26. valid_index (index: INTEGER): BOOLEAN is
  27. do
  28. Result := nodes.valid_index(index)
  29. end
  30. lower: INTEGER is
  31. do
  32. Result := nodes.lower
  33. end
  34. upper: INTEGER is
  35. do
  36. Result := nodes.upper
  37. end
  38. count: INTEGER is
  39. do
  40. Result := nodes.count
  41. end
  42. is_empty: BOOLEAN is
  43. do
  44. Result := nodes.is_empty
  45. end
  46. feature {EIFFEL_GRAMMAR}
  47. set (index: INTEGER; node: EIFFEL_NODE) is
  48. do
  49. nodes.put(node, index)
  50. node.set_parent(Current)
  51. end
  52. feature {EIFFEL_NODE_HANDLER}
  53. display (output: OUTPUT_STREAM; indent: INTEGER; p: STRING) is
  54. local
  55. i: INTEGER
  56. do
  57. do_indent(output, indent, p)
  58. output.put_character('"')
  59. output.put_string(name)
  60. output.put_line(once "%":")
  61. from
  62. i := lower
  63. until
  64. i > upper
  65. loop
  66. node_at(i).display(output, indent + 1, " * ")
  67. i := i + 1
  68. end
  69. end
  70. generate (o: OUTPUT_STREAM) is
  71. local
  72. i: INTEGER
  73. do
  74. from
  75. i := lower
  76. until
  77. i > upper
  78. loop
  79. node_at(i).generate(o)
  80. i := i + 1
  81. end
  82. generate_forgotten(o)
  83. end
  84. feature {}
  85. make (a_name: like name; a_names: like names) is
  86. do
  87. name := a_name
  88. names := a_names
  89. create nodes.make(a_names.count)
  90. ensure
  91. name = a_name
  92. names = a_names
  93. end
  94. names: TRAVERSABLE[FIXED_STRING]
  95. nodes: FAST_ARRAY[EIFFEL_NODE]
  96. invariant
  97. names.count = nodes.count
  98. end -- class EIFFEL_NON_TERMINAL_NODE_IMPL
  99. --
  100. -- Copyright (c) 2009 by all the people cited in the AUTHORS file.
  101. --
  102. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  103. -- of this software and associated documentation files (the "Software"), to deal
  104. -- in the Software without restriction, including without limitation the rights
  105. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  106. -- copies of the Software, and to permit persons to whom the Software is
  107. -- furnished to do so, subject to the following conditions:
  108. --
  109. -- The above copyright notice and this permission notice shall be included in
  110. -- all copies or substantial portions of the Software.
  111. --
  112. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  113. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  114. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  115. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  116. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  117. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  118. -- THE SOFTWARE.