/src/tools/syntax/tree/liberty_ast_non_terminal_node.e

http://github.com/tybor/Liberty · Specman e · 135 lines · 101 code · 20 blank · 14 comment · 0 complexity · 2f019ca5275e86941dc3d6e4a28488c8 MD5 · raw file

  1. -- This file is part of Liberty Eiffel.
  2. --
  3. -- Liberty Eiffel is free software: you can redistribute it and/or modify
  4. -- it under the terms of the GNU General Public License as published by
  5. -- the Free Software Foundation, version 3 of the License.
  6. --
  7. -- Liberty Eiffel is distributed in the hope that it will be useful,
  8. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. -- GNU General Public License for more details.
  11. --
  12. -- You should have received a copy of the GNU General Public License
  13. -- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>.
  14. --
  15. deferred class LIBERTY_AST_NON_TERMINAL_NODE
  16. inherit
  17. EIFFEL_NON_TERMINAL_NODE
  18. rename
  19. name as eiffel_name
  20. end
  21. feature {ANY}
  22. eiffel_name: FIXED_STRING is
  23. do
  24. Result := name.intern
  25. end
  26. name: STRING is
  27. deferred
  28. end
  29. name_at (index: INTEGER): FIXED_STRING is
  30. do
  31. Result := nodes.item(index).name
  32. end
  33. node_at (index: INTEGER): EIFFEL_NODE is
  34. do
  35. Result := nodes.item(index)
  36. end
  37. valid_index (index: INTEGER): BOOLEAN is
  38. do
  39. Result := index.in_range(lower, upper)
  40. end
  41. lower: INTEGER is 0
  42. upper: INTEGER is
  43. do
  44. Result := count - 1
  45. end
  46. count: INTEGER is
  47. deferred
  48. end
  49. is_empty: BOOLEAN is
  50. do
  51. Result := count = 0
  52. end
  53. accept (v: VISITOR) is
  54. do
  55. check False end
  56. end
  57. feature {EIFFEL_GRAMMAR}
  58. set (index: INTEGER; node: EIFFEL_NODE) is
  59. do
  60. nodes.put(node, index)
  61. end
  62. feature {EIFFEL_NODE_HANDLER}
  63. display (output: OUTPUT_STREAM; indent: INTEGER; p: STRING) is
  64. local
  65. i: INTEGER
  66. do
  67. do_indent(output, indent, p)
  68. output.put_character('"')
  69. output.put_string(name)
  70. output.put_line(once "%":")
  71. from
  72. i := lower
  73. until
  74. i > upper
  75. loop
  76. node_at(i).display(output, indent + 1, " * ")
  77. i := i + 1
  78. end
  79. end
  80. generate (o: OUTPUT_STREAM) is
  81. local
  82. i: INTEGER
  83. do
  84. from
  85. i := lower
  86. until
  87. i > upper
  88. loop
  89. node_at(i).generate(o)
  90. i := i + 1
  91. end
  92. generate_forgotten(o)
  93. end
  94. feature {}
  95. possible_counts: SET[INTEGER] is
  96. deferred
  97. end
  98. nodes: FAST_ARRAY[EIFFEL_NODE]
  99. make (a_name: like eiffel_name; a_names: TRAVERSABLE[FIXED_STRING]) is
  100. require
  101. valid_name(a_name)
  102. possible_counts.has(a_names.count)
  103. do
  104. create nodes.make(a_names.count)
  105. ensure
  106. nodes.count = a_names.count
  107. end
  108. valid_name (a_name: like eiffel_name): BOOLEAN is
  109. do
  110. Result := a_name = eiffel_name
  111. end
  112. invariant
  113. count = nodes.count
  114. possible_counts.has(count)
  115. end