PageRenderTime 18ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/src/lib/parse/parse_atom.e

http://github.com/tybor/Liberty
Specman e | 133 lines | 94 code | 11 blank | 28 comment | 2 complexity | 839a558486379c3a92120f39a9714241 MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4deferred class PARSE_ATOM[C_ -> PARSE_CONTEXT]
  5   --
  6   -- A part of the PARSE_TABLE.
  7   --
  8
  9insert
 10   TRISTATE_VALUES
 11   PARSER_FACET
 12
 13feature {ANY}
 14   name: FIXED_STRING
 15   table: PARSE_TABLE[C_]
 16
 17   is_coherent: BOOLEAN
 18      require
 19         table /= Void
 20      deferred
 21      ensure
 22         must_be_coherent: Result
 23      end
 24
 25   pretty_print_on (stream: OUTPUT_STREAM)
 26      require
 27         stream.is_connected
 28      deferred
 29      end
 30
 31feature {PARSE_TABLE}
 32   set (a_name: ABSTRACT_STRING; a_table: like table)
 33      require
 34         name = Void
 35         table = Void
 36         not a_name.is_empty
 37         a_table /= Void
 38      do
 39         name := a_name.intern
 40         table := a_table
 41      ensure
 42         name = a_name.intern
 43         table = a_table
 44      end
 45
 46   set_table (a_table: like table)
 47      require
 48         a_table /= Void
 49      do
 50         table := a_table
 51      ensure
 52         table = a_table
 53      end
 54
 55   set_default_tree_builders (non_terminal_builder: PROCEDURE[TUPLE[FIXED_STRING, TRAVERSABLE[FIXED_STRING]]]; terminal_builder: PROCEDURE[TUPLE[FIXED_STRING, PARSER_IMAGE]])
 56      require
 57         is_coherent
 58      deferred
 59      end
 60
 61feature {PARSER_FACET}
 62   parse (context: C_): TRISTATE
 63         -- The Result is `yes' if the parsing succeeded, `no' if there was a syntax error, or `maybe' if the
 64         -- parse could complete with some more text.
 65      require
 66         context /= Void
 67      deferred
 68      ensure
 69         context.actions.count >= old context.actions.count
 70         ;(Result /= yes) implies context.buffer.current_index = old context.buffer.current_index and then context.actions.count = old context.actions.count
 71      end
 72
 73feature {}
 74   add_error_position (error: STRING; buffer: MINI_PARSER_BUFFER)
 75      local
 76         n, l, c: INTEGER
 77      do
 78         n := buffer.current_index
 79         from
 80            l := 1
 81            c := 1
 82            buffer.set_current_index(buffer.lower)
 83         until
 84            buffer.current_index = n
 85         loop
 86            if buffer.current_character = '%N' then
 87               l := l + 1
 88               c := 1
 89            else
 90               c := c + 1
 91            end
 92            buffer.next
 93         end
 94         if not error.is_empty then
 95            error.extend(' ')
 96         end
 97         error.append(once "at line ")
 98         l.append_in(error)
 99         error.append(once ", column ")
100         c.append_in(error)
101      end
102
103   print_error_position (o: OUTPUT_STREAM; buffer: MINI_PARSER_BUFFER)
104      local
105         s: STRING
106      do
107         s := once ""
108         s.clear_count
109         add_error_position(s, buffer)
110         o.put_string(s)
111      end
112
113end -- class PARSE_ATOM
114--
115-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
116--
117-- Permission is hereby granted, free of charge, to any person obtaining a copy
118-- of this software and associated documentation files (the "Software"), to deal
119-- in the Software without restriction, including without limitation the rights
120-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
121-- copies of the Software, and to permit persons to whom the Software is
122-- furnished to do so, subject to the following conditions:
123--
124-- The above copyright notice and this permission notice shall be included in
125-- all copies or substantial portions of the Software.
126--
127-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
128-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
129-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
130-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
131-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
132-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
133-- THE SOFTWARE.