/src/lib/parse/eiffel/eiffel_node.e

http://github.com/tybor/Liberty · Specman e · 132 lines · 80 code · 15 blank · 37 comment · 2 complexity · ad597fae909745808dd940e4a69bee07 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. deferred class EIFFEL_NODE
  5. --
  6. -- Provides two basic operations: `display' for debug purposes, and `generate' for more generic node
  7. -- handling.
  8. --
  9. -- Any other operation should be provided by an external VISITOR.
  10. --
  11. -- See also: EIFFEL_NON_TERMINAL_NODE, EIFFEL_LIST_NODE, EIFFEL_TERMINAL_NODE, EIFFEL_IMAGE
  12. --
  13. inherit
  14. VISITABLE
  15. insert
  16. EIFFEL_NODE_HANDLER
  17. feature {ANY}
  18. parent: EIFFEL_NODE
  19. -- the parent node
  20. forgotten: FAST_ARRAY[EIFFEL_NODE]
  21. -- used when this node is in a EIFFEL_LIST_NODE and nodes are between this node and the next one
  22. name: FIXED_STRING is
  23. -- the name of the node in the grammar
  24. deferred
  25. ensure
  26. name /= Void
  27. end
  28. source_line: INTEGER is
  29. deferred
  30. end
  31. source_column: INTEGER is
  32. deferred
  33. end
  34. source_index: INTEGER is
  35. deferred
  36. end
  37. feature {EIFFEL_GRAMMAR}
  38. set_forgotten (a_forgotten: like forgotten) is
  39. do
  40. forgotten := a_forgotten
  41. ensure
  42. forgotten = a_forgotten
  43. end
  44. feature {EIFFEL_NODE_HANDLER} -- Basic operations
  45. display (output: OUTPUT_STREAM; indent: INTEGER; p: STRING) is
  46. -- Display the node in a tree fashion in the provided `output' stream
  47. deferred
  48. end
  49. generate (o: OUTPUT_STREAM) is
  50. -- Generate the node exactly as it was written, including blanks and `forgotten' nodes, onto the
  51. -- provided `output' stream
  52. deferred
  53. end
  54. feature {}
  55. generate_forgotten (o: OUTPUT_STREAM) is
  56. local
  57. i: INTEGER
  58. do
  59. if forgotten /= Void then
  60. from
  61. i := forgotten.lower
  62. until
  63. i > forgotten.upper
  64. loop
  65. forgotten.item(i).generate(o)
  66. i := i + 1
  67. end
  68. end
  69. end
  70. feature {EIFFEL_NON_TERMINAL_NODE, EIFFEL_LIST_NODE}
  71. set_parent (a_parent: like parent) is
  72. require
  73. a_parent /= Void
  74. parent = Void
  75. do
  76. parent := a_parent
  77. ensure
  78. parent = a_parent
  79. end
  80. feature {}
  81. do_indent (output: OUTPUT_STREAM; indent: INTEGER; p: STRING) is
  82. local
  83. i: INTEGER
  84. do
  85. from
  86. i := 1
  87. until
  88. i > indent
  89. loop
  90. output.put_string(once " ")
  91. i := i + 1
  92. end
  93. if p /= Void then
  94. output.put_string(p)
  95. end
  96. end
  97. end -- class EIFFEL_NODE
  98. --
  99. -- Copyright (c) 2009 by all the people cited in the AUTHORS file.
  100. --
  101. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  102. -- of this software and associated documentation files (the "Software"), to deal
  103. -- in the Software without restriction, including without limitation the rights
  104. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  105. -- copies of the Software, and to permit persons to whom the Software is
  106. -- furnished to do so, subject to the following conditions:
  107. --
  108. -- The above copyright notice and this permission notice shall be included in
  109. -- all copies or substantial portions of the Software.
  110. --
  111. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  112. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  113. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  114. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  115. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  116. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  117. -- THE SOFTWARE.