abs_cursor.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand        --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------


abstract class $CURSOR{ETP < $IS_EQ, STP < $STRING{ETP}}

abstract class $CURSOR{ETP < $IS_EQ, STP < $STRING{ETP}} is -- This abstraction specifies the functionality required of generic -- cursor scanning objects of all kinds. -- -- The purpose of the cursor class is to extract sections of strings -- (also called sequences or streams) and, where appropriate, perform -- conversions to common program attribute values in the process of scanning. -- This permits perfectly general scanning which depends only on the correct -- interpretation of the string contents and structure. -- -- Since the string is not consumed by scanning, it is possible also to -- perform test on contents/structure in order to 'synchronise' the program -- with the data involved. -- -- Unless altered by use of the set_skip operation, the skip element -- defaults to void. -- Version 1.1 Apr 99. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 12 Jan 97 kh Original developed from STR_CURSOR -- 8 Apr 99 kh Minor changes for Version 8 of text classes index : CARD ; -- This feature returns the current cursor position. buffer : STP ; -- This feature is the buffer into which the cursor is pointing. skip_val : ETP ; -- This feature is the currently set skip value fo the cursor. is_done : BOOL ; -- This predicate returns true if and only if the cursor position is -- beyond the last item in the buffer. advance ; -- This routine advances the cursor to the next string element. It is -- an error if the end of the string was reached before this routine is -- called. advance : SAME ; -- This routine advances the cursor to the next string element as above -- and returns the updated value of self. retract ; -- This routine retracts the cursor to point to the previous string -- element. It is an error if the current value of the cursor indicated the -- beginning of the string before this routine was called. retract : SAME ; -- This routine retracts the cursor to point to the previous string -- element. It is an error if the current value of the cursor indicated the -- beginning of the string before this routine was called. It then returns -- the updated value of the cursor. item : ETP ; -- This routine returns the string element indicated by the current -- value of the cursor -- or void if an error condition exists. It does -- NOT advance the cursor. reassign( str : STP ) ; -- This routine changes the string to which this cursor is pointing, -- so that the current element is the first. Any error condition is -- cleared. clear ; -- This routine resets the cursor to be indicating an empty string -- and clears any error condition. set_index( new_posn : CARD ) ; -- This routine resets the index position to new_posn, provided that -- that is a valid index for the buffer, then clears any end of buffer -- condition. set_skip( val : ETP ) ; -- This routine sets the value of the element used in all skipping -- operations - until this is next set. The default value depends on -- the element class. set_skip( val : ETP ) : SAME ; -- This routine sets the value of the element used in all skipping -- operations - until this is next set. It then returns self. -- The following operations all skip various parts of the string. -- It is not an error if such skipping reaches the end of the -- string. skip_over ; -- This routine advances the cursor until the current element is -- different from the currently set skip element value. skip_over : SAME ; -- This routine advances the cursor until the current element is -- different from the currently set skip element value. It then returns self. skip_over( elem : ETP ) ; -- This routine sets elem to be the currently set skip element value -- and then advances the cursor over the first element which is equal -- to that value - then restoring the currently set skip element value -- to its former value. skip_over( elem : ETP ) : SAME ; -- This routine sets elem to be the currently set skip element value -- and then advances the cursor over the first element which is equal -- to that value - then restoring the currently set skip element value -- to its former value. It then returns self. skip_to ; -- This routine advances the cursor until the current element is equal -- to the currently set skip element value. skip_to : SAME ; -- This routine advances the cursor until the current element is equal -- to the currently set skip element value. It then returns self. skip_to( elem : ETP ) ; -- This routine sets elem to be the currently set skip element value -- and then advances the cursor until the current element is equal -- to that value - then restoring the currently set skip element value -- to its former value. skip_to( elem : ETP ) : SAME ; -- This routine sets elem to be the currently set skip element value -- and then advances the cursor until the current element is equal -- to that value - then restoring the currently set skip element value -- to its former value. It then returns self. skip_block( start_delimiter, finish_delimiter : ETP ) ; -- Providing that the current string element is start_delimiter, this -- routine skips further string elements up to and including the matching -- occurrence of finish_delimiter. It is an ERROR if the start delimiter -- is found but not the finishing one. is_value( val : ETP ) : BOOL ; -- This routine returns true if and only if the current string element -- has the value val, otherwise false. remaining : CARD ; -- This routine returns the number of items yet to be scanned in -- the buffer. get_item : ETP ; -- This routine returns the currently indicated item and advances -- the cursor value by one. Note that it is not an error condition if -- the cursor cannot be advanced as the current cursor value indicates -- the last element in the string. get_upto : STP ; -- This routine scans the string from the current element, skipping -- until a value which is not the current value of skip_val is found, then -- up to the next occurrence of the current value of the skip_val, -- returning the string scanned NOT including the skip element found. -- It is NOT an error if the skip element is not detected before the end of -- the string. get_upto( count : CARD ) : STP ; -- This routine returns the string starting at the current element -- until either the given count is reached or the end of the string, -- whichever occurs first. get_upto( elem : ETP ) : STP ; -- This routine returns the string starting at the current element -- until either the element with the value elem is reached or the end of -- the string, whichever occurs first. It is an error if elem is not -- detected before the end of the string. get_remainder : STP ; -- This routine returns the remainder of the string from the current -- element. get_rest_upto( elem : ETP ) : STP ; -- This routine returns the string starting at the current element -- until either the element with the value elem is reached or the end of -- the string, whichever occurs first. It is NOT an error if elem is not -- detected before the end of the string. get_block( start_delimiter, finish_delimiter : ETP ) : STP ; -- Providing that the current string element is start_delimiter, this -- routine returns further string elements up to and including the first -- occurrence of finish_delimiter, otherwise void. It is an error if, -- having detected the start_delimiter value, finish_delimiter is not -- detected before the end of the string. -- The final group of items is concerned with error indications. error : CURSOR_ERRORS ; -- This is a value associated with the string cursor indicating what, -- if any error has occurred and not been cleared. clear_error ; -- This routine resets the error value to 'No Error'. has_error : BOOL ; -- This routine returns true if and only if the cursor has encountered -- an error which has not been cleared. end ; -- $CURSOR{ETP}

abstract class $TEXT_CURSOR{ETP, STP} < $CURSOR{ETP,STP}

abstract class $TEXT_CURSOR{ETP, STP} < $CURSOR{ETP,STP} is -- This abstraction specifies the functionality required of text cursor -- scanning objects for given text string types which are additional to those -- specified for all cursors. -- Version 1.0 Apr 99. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 8 Apr 99 kh Original for Version 8 of text classes. line_no : CARD ; -- This feature returns the current line number in the text string as -- determined by increment since the last setting of the number. comment_start : STP ; comment_end : STP ; -- The above two features are the current value of the string which is -- the start of a comment token and the end of comment token for the buffered -- string. reset_line( val : CARD ) ; -- This routine resets the value of the current line in the buffer to -- the given value. Control of this value is not defined by the scanner. is_line_mark : BOOL ; -- This predicate returns true if and only if the cursor is positioned at -- a line mark. The cursor is not moved. set_comment_start( char : ETP ) ; -- This routine sets the start of comment token to be the single given -- character value. set_comment_start( str : STP ) ; -- This routine sets the start of commen token to be the given character -- string. set_comment_end( char : ETP ) ; -- This routine sets the end of comment token to be the given value. set_comment_end( str : STP ) ; -- This routine sets the end of comment token to be the given string. skip_comment : BOOL ; -- This routine returns true if and only if a comment starts at -- the current index position and has been skipped. If the end of comment -- token has not been set or is void then the comment is deemed to extend to -- the current line end. skip_space ; -- This routine skips space elements - in so doing treating any comments -- as single space elements. Note that those string elements which are -- considered to be a space are otherwise culturally defined. skip_space : SAME ; -- This routine skips space elements - in so doing treating any comments -- as single space elements. Note that those string elements which are -- considered to be a space are otherwise culturally defined. Self is -- returned. skip_over_line ; -- This routine skips items in the buffer up to and beyond the next line -- mark in the string. skip_word ; -- This routine skips characters up to, but not including, the next -- space element. skip_word : SAME ; -- This routine skips characters up to, but not including, the next -- space element before returning self. skip_to( str : STP ) ; -- This routine skips up to, but not including, the first element of -- the next copy of str found in the string. skip_to( str : STP ) : SAME ; -- This routine skips up to, but not including, the first element of -- the next copy of str found in the string before returning self. skip_over( str : STP ) ; -- This routine advances the cursor to find the string str. It -- positions the cursor to indicate the string element beyond the last -- element of str or at the end of the string if this is found during -- the string scan. skip_over( str : STP ) : SAME ; -- This routine advances the cursor to find the string str. It -- positions the cursor to indicate the string element beyond the last -- element of str or at the end of the string if this is found during -- the string scan, before returning self. get_char : ETP ; -- This routine returns the character at the current index position and -- then advances the index by one character. It is a synonym for get_item. get_line_mark : STP ; -- This routine skips items in the buffer up to the next line_mark which -- is returned. get_word : STP ; -- This routine skips space up to the next non-space character and then -- retrieves the remaining string up to the end of the string or up to a space -- character whichever is detected first. get_word( max_size : CARD ) : STP ; -- This routine skips any leading space and then retrieves a word up to -- max_size long or until the end of the string has been reached or a space -- is detected. get_upto_char( ch : ETP ) : STP ; -- This routine retrieves the string up to the next occurrence of ch -- or until the string is finished. get_pred( predicate : ROUT{ETP} : BOOL ) : STP ; -- This routine retrieves the string up to the next character for which -- the given predicate returns false or until the string is finished. get_str : STP ; -- This routine returns the string starting at the current position up to -- and including the next end of line mark. get_upto_cut( cut_set : STP ) : STP ; -- This routine retrieves the string from the current position upto, but -- not including any character appearing in the cut_set (which is considered -- as a set of characters. get_over_cut( cut_set : STP ) : STP ; -- This routine retrieves the string from the current position upto and -- including any character appearing in the cut_set (which is considered as -- a set of characters. current_line : STP ; -- This routine returns the string which is the entire current line in -- the source string. line!( once escape : ETP, -- may be void! out line_num : CARD ) : SAME ; -- This iter assembles one or more source lines into a logical line, -- omitting comment lines and stripping unwanted line marks at the end -- as necessary. The iter then returns a new string cursor indexed at -- the first non-space element of the line found - or quits! end ; -- $TEXT_CURSOR{ETP}