class STR_CURSOR |
---|
**** | Class for stepping through strings extracting information. For strings, cursors are used to sequentially read out the components of a string. They may be used to perform a similar function to that played by "scanf" in C without need for functions with a variable number of arguments. This approach is actually much more general since it allows for testing for the presence of an `BOOL', for example, at a given point in the string. If we were wrong about the structure of the string, then the attribute `error' will be set to a non-zero value. |
attr buf:STR; |
---|
attr comment_char1,comment_char2: CHAR; |
---|
attr comment_char1,comment_char2: CHAR; |
---|
attr error:INT; |
---|
attr index:INT; |
---|
attr is_done:BOOL; |
---|
attr line_no:INT; |
---|
attr error:INT; |
---|
const Bad_Block: INT := 8; |
---|
const Bad_Boolean:INT := 7; |
---|
const Bad_Char: INT := 9; |
---|
const Bad_Digit:INT := 1; |
---|
const Bad_Prefix:INT := 6; |
---|
const Cut_Set_Member_Not_Found:INT := 5; |
---|
const Int_No_Bits:INT := 32; |
---|
const Max_Int_Digits:INT := 9; |
---|
const Max_Real_Digits:INT := 30; |
---|
const No_Error:INT := 0; |
---|
const Past_BOBuf:INT := 3; |
---|
const Past_EOBuf:INT := 2; |
---|
const Too_Many_Digits:INT := 4; |
---|
advance_one_char |
---|
**** | Advance the cursor one position forward |
advance_one_char:SAME |
---|
clear |
---|
**** | Reset to an empty string |
clear_error |
---|
**** | Reset the error value |
create(s:STR):SAME |
---|
current_line_str: STR |
---|
**** | A string consisting of the current line |
current_loc_str(cursor_char: CHAR): STR |
---|
**** | A string consisting of a blank line except for the cursor_char which is at the current location within that line. Eg. If the cursor is at the third word of the line "this is a test" This function will return the string " ^" Useful for printing out error messages |
error_string: STR |
---|
**** | Returns a string version of the current error status |
get_binary:INT |
---|
**** | BIN ::= OPT_SIGN '0b' (0 | 1)+ OPT_SIGN ::= '+' | '-' | '\0'and stops at the first non-binary digit found.leading 0's ignored. '-' prefix gives 2's complement of following binary number. |
get_block(begin_delim, fin_delim: CHAR): STR |
---|
**** | Return a block if the current character = begin_delim |
get_bool:BOOL |
---|
**** | Only accepts "true" and "false" for consistency with sather spec |
get_char(c: CHAR) |
---|
get_char:CHAR |
---|
get_flt:FLT |
---|
get_fltd:FLTD |
---|
**** | Accepts real numbers of format:
__FLTD_________::=_SIGNED_INT_{'.'_{UNSIGNED_INT}_{'e'_SIGNED_INT} __SIGNED_INT___::=_{'+'_|_'-'_|_'\0'}_UNSIGNED_INT __UNSIGNED_INT_::=_(0_.._9)+ no spaces allowed between components of FLTD |
get_hex:INT |
---|
**** |
__HEX_::=_OPT_SIGN_('0x'_|_'0X')_HEX_DIGIT+ __OPT_SIGN_::=_'+'_|_'-'_|_'\0' __HEX_DIGIT_::=_('0'_.._'9')_|_('a'_.._'f')_|_('A'_.._'F') __'-'_prefix_gives_2's_complement_of_following_hex_dnumber |
get_int:INT |
---|
**** | decimal format optionally signed with '+', '-', or '\0' |
get_octal:INT |
---|
**** | OCT ::= '0o' (0 .. 7)+ stoping at first non-octal digit found.leading 0's ignored. '-' prefix gives 2's complement of following octal number. |
get_opt_int:INT |
---|
**** | if int is not present then no error. |
get_opt_sign:BOOL |
---|
**** | returns 'true' if '-' is found, else 'false'.advances index by 1 if '-' or '+' is found, else index not advanced. |
get_rest_str: STR |
---|
**** | Return the portion of the string after the current loc |
get_str:STR |
---|
**** | get string up to and including '\n' or end of buf. |
get_str_cut(cut_set:STR):STR |
---|
**** | get string up to and including cut_set member found. |
get_str_upto(t: CHAR): STR |
---|
**** | Return the next chunk of string upto the character "t" or until the end of the string |
get_str_upto_cut(cut_set:STR):STR |
---|
**** | get string up to but NOT including cut_set member found. |
get_up_to(c:CHAR):STR |
---|
get_word(max_char_count:INT):STR |
---|
**** | get a word up to max_char_count CHAR's long |
get_word:STR |
---|
has_error: BOOL |
---|
**** | Returns true if the cursor has encountered an error |
int:INT |
---|
**** | to support str_curs.sa's int which accepts any of the 4 formats:1) decimal, 2) binary, 3) hex, 4) octal.unlike str_curs.sa, this only sets error code and doesn't raise anexception. |
item:CHAR |
---|
**** | Return the current item or '\0' if done |
reassign(s:STR) |
---|
**** | Change the string that `self' points to Clear any error value |
retract_one_char |
---|
retract_one_char:SAME |
---|
set_comment_syntax(char1: CHAR) |
---|
set_comment_syntax(char1,char2: CHAR) |
---|
skip_block(begin_delim, fin_delim: CHAR) |
---|
skip_if_comment_start: BOOL |
---|
**** | Returns true if a comment was skipped |
skip_over(s:STR) |
---|
**** | Skip characters upto _and including_ the word "s". |
skip_space |
---|
**** | Advance the scanner over space characters |
skip_space:SAME |
---|
**** | Same as skip_space, but return self |
skip_thru(c:CHAR) |
---|
**** | Skip characters until (not including) the character 'c' |
skip_thru(c:CHAR):SAME |
---|
**** | Same as skip_thru, return self |
skip_thru(s:STR) |
---|
**** | Skip characters upto (not including) the word "s" Translated from STR::search. |
skip_thru(s:STR):SAME |
---|
skip_word |
---|
**** | Skip characters until (not including) a space character is hit. |
skip_word:SAME |
---|
**** | Same as skip_word, but return self |
split(c: CHAR): FLIST{STR} |
---|
**** | Split the remainder of the string into chunks demarcated by the split character "c" |
test_bool: BOOL |
---|
**** | Return true if the next string could be interpreted as a bool |
attr buf:STR; |
---|
attr comment_char1,comment_char2: CHAR; |
---|
attr comment_char1,comment_char2: CHAR; |
---|
get_frac:FLTD |
---|
**** | starting at leftmost digit, read in decimal fraction |
get_unsigned_int:INT |
---|
**** | Doesn't skip spaces: assumes that either "sign" or "decimal point" has just been fetched. |
get_unsigned_int_as_fltd:FLTD |
---|
**** | doesn't skip spaces: assumes that
__either_"sign"_or_"decimal_point"_has_just_been_fetched. |
get_unsigned_unprefixed_binary:INT |
---|
get_unsigned_unprefixed_hex:INT |
---|
get_unsigned_unprefixed_octal:INT |
---|
attr index:INT; |
---|
attr is_done:BOOL; |
---|
attr line_no:INT; |
---|
skip_double_char_comment: BOOL |
---|
skip_single_char_comment: BOOL |
---|