PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/src/tools/errors/liberty_position.e

http://github.com/tybor/Liberty
Specman e | 137 lines | 117 code | 6 blank | 14 comment | 7 complexity | 489cae717d5e94090579b261111a4a9c 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_POSITION
 16
 17feature {ANY}
 18   is_unknown: BOOLEAN is
 19      deferred
 20      end
 21
 22   show (stream: OUTPUT_STREAM) is
 23      require
 24         not is_unknown
 25      do
 26         set_error_position
 27         if file /= Void then
 28            stream.put_string(once "in file ")
 29            stream.put_string(file.out)
 30         end
 31         stream.put_string(once " at line ")
 32         stream.put_integer(line)
 33         stream.put_string(once ", column ")
 34         stream.put_integer(column)
 35         debug
 36            stream.put_string(once " (index: ")
 37            stream.put_integer(index)
 38            stream.put_string(once "):")
 39         end
 40         stream.put_new_line
 41      end
 42
 43feature {}
 44   line, column: INTEGER
 45   file: FIXED_STRING
 46   index: INTEGER
 47   source: STRING is
 48      deferred
 49      end
 50
 51   set_error_position is
 52      require
 53         source /= Void
 54         index.in_range(source.lower, source.upper)
 55      local
 56         i, l, c: INTEGER
 57      do
 58         if line = 0 then
 59            from
 60               l := 1
 61               c := 1
 62               i := 1
 63            until
 64               i = index
 65            loop
 66               if source.item(i) = '%N' then
 67                  l := l + 1
 68                  c := 1
 69               else
 70                  c := c + 1
 71               end
 72               i := i + 1
 73            end
 74            line := l
 75            column := c
 76         end
 77      ensure
 78         line > 0
 79         column > 0
 80      end
 81
 82feature {LIBERTY_ERROR}
 83   emit (stream: OUTPUT_STREAM) is
 84      local
 85         l, c, i, a: INTEGER
 86         arrow: STRING
 87      do
 88         show(stream)
 89         if index <= source.upper then
 90            i := 1
 91            from
 92               l := 1
 93            until
 94               l = line
 95            loop
 96               if source.item(i) = '%N' then
 97                  l := l + 1
 98               end
 99               i := i + 1
100            end
101            from
102               c := 1
103               arrow := ""
104            until
105               c = column
106            loop
107               if source.item(i) = '%T' then
108                  arrow.extend('%T')
109               else
110                  arrow.extend(' ')
111               end
112               stream.put_character(source.item(i))
113               c := c + 1
114               i := i + 1
115            end
116            from
117            until
118               i > source.count or else source.item(i) = '%N'
119            loop
120               stream.put_character(source.item(i))
121               i := i + 1
122            end
123            stream.put_new_line
124            from
125               a := 1
126            until
127               a > arrow.count
128            loop
129               stream.put_character(arrow.item(a))
130               a := a + 1
131            end
132            stream.put_character('^')
133            stream.put_new_line
134         end
135      end
136
137end