PageRenderTime 67ms CodeModel.GetById 58ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/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--
 15deferred class LIBERTY_AST_NON_TERMINAL_NODE
 16
 17inherit
 18   EIFFEL_NON_TERMINAL_NODE
 19      rename
 20         name as eiffel_name
 21      end
 22
 23feature {ANY}
 24   eiffel_name: FIXED_STRING is
 25      do
 26         Result := name.intern
 27      end
 28
 29   name: STRING is
 30      deferred
 31      end
 32
 33   name_at (index: INTEGER): FIXED_STRING is
 34      do
 35         Result := nodes.item(index).name
 36      end
 37
 38   node_at (index: INTEGER): EIFFEL_NODE is
 39      do
 40         Result := nodes.item(index)
 41      end
 42
 43   valid_index (index: INTEGER): BOOLEAN is
 44      do
 45         Result := index.in_range(lower, upper)
 46      end
 47
 48   lower: INTEGER is 0
 49
 50   upper: INTEGER is
 51      do
 52         Result := count - 1
 53      end
 54
 55   count: INTEGER is
 56      deferred
 57      end
 58
 59   is_empty: BOOLEAN is
 60      do
 61         Result := count = 0
 62      end
 63
 64   accept (v: VISITOR) is
 65      do
 66         check False end
 67      end
 68
 69feature {EIFFEL_GRAMMAR}
 70   set (index: INTEGER; node: EIFFEL_NODE) is
 71      do
 72         nodes.put(node, index)
 73      end
 74
 75feature {EIFFEL_NODE_HANDLER}
 76   display (output: OUTPUT_STREAM; indent: INTEGER; p: STRING) is
 77      local
 78         i: INTEGER
 79      do
 80         do_indent(output, indent, p)
 81         output.put_character('"')
 82         output.put_string(name)
 83         output.put_line(once "%":")
 84         from
 85            i := lower
 86         until
 87            i > upper
 88         loop
 89            node_at(i).display(output, indent + 1, " * ")
 90            i := i + 1
 91         end
 92      end
 93
 94   generate (o: OUTPUT_STREAM) is
 95      local
 96         i: INTEGER
 97      do
 98         from
 99            i := lower
100         until
101            i > upper
102         loop
103            node_at(i).generate(o)
104            i := i + 1
105         end
106         generate_forgotten(o)
107      end
108
109feature {}
110   possible_counts: SET[INTEGER] is
111      deferred
112      end
113
114   nodes: FAST_ARRAY[EIFFEL_NODE]
115
116   make (a_name: like eiffel_name; a_names: TRAVERSABLE[FIXED_STRING]) is
117      require
118         valid_name(a_name)
119         possible_counts.has(a_names.count)
120      do
121         create nodes.make(a_names.count)
122      ensure
123         nodes.count = a_names.count
124      end
125
126   valid_name (a_name: like eiffel_name): BOOLEAN is
127      do
128         Result := a_name = eiffel_name
129      end
130
131invariant
132   count = nodes.count
133   possible_counts.has(count)
134
135end