home *** CD-ROM | disk | FTP | other *** search
- ::::::::::::::
- scanners.bdy
- ::::::::::::::
- package body scanners is --| Scan tokens from strings
-
- ----------------------------------------------------------------------------
- -- Local function specs:
-
- function is_Space(C: Character) return boolean;
- --| Return True iff C is a space or tab.
-
- ----------------------------------------------------------------------------
-
- procedure start_Scanner( --| Initialize a scanner
- Scanner: in out Scanner_Type; --| Scanner to be initialized
- S: in string; --| String to be scanned
- Last: in natural --| Last scannable character in S.
- )
- is
-
- begin
- Scanner.Index := S'First;
- Scanner.Max_Index := Last;
- Scanner.First := 1;
- Scanner.Last := 0;
- Scanner.Length := 0;
-
- end start_Scanner;
-
- ----------------------------------------------------------------------------
-
- function is_Empty( --| Return False if Scanner can scan more characters
- Scanner: in Scanner_Type
- ) return boolean is
-
- begin
- return Scanner.Index > Scanner.Max_Index;
-
- end is_Empty;
-
- ----------------------------------------------------------------------------
-
- function is_Alpha( --| Check for alphabetic character
- Scanner: in scanner_Type;
- S: in string
- ) return boolean is
-
- begin
- return Scanner.Index <= scanner.Max_Index and then
- (S(Scanner.Index) in 'a'..'z' or else
- S(Scanner.Index) in 'A'..'Z');
-
- end is_Alpha;
-
- ----------------------------------------------------------------------------
-
- function is_Digit( --| Check for start of unsigned number
- Scanner: in scanner_Type;
- S: in string
- ) return boolean is
-
- begin
- return Scanner.Index <= scanner.Max_Index and then
- S(Scanner.Index) in '0'..'9';
-
- end is_Digit;
-
- ----------------------------------------------------------------------------
-
- function is_Sign( --| Check for '+' or '-'
- Scanner: in scanner_Type;
- S: in string
- ) return boolean is
-
- begin
- return Scanner.Index <= scanner.Max_Index and then
- (S(Scanner.Index) = '+' or else S(Scanner.Index) = '-');
-
- end is_Sign;
-
- ----------------------------------------------------------------------------
-
- function is_Digit_or_Sign( --| Check for start of optionally signed number
- Scanner: in scanner_Type;
- S: in string
- ) return boolean is
-
- begin
- return Scanner.Index <= scanner.Max_Index and then
- (S(Scanner.Index) in '0'..'9'
- or else S(Scanner.Index) = '+' or else S(Scanner.Index) = '-');
-
- end is_Digit_or_Sign;
-
-
- ----------------------------------------------------------------------------
-
- procedure skip_Blanks( --| Skip leading blanks in S
- Scanner: in out Scanner_Type; --| Scanner to be updated
- S: in string --| String being scanned
- ) is
-
- begin
- Scanner.First := Scanner.Index;
- Scanner.Length := 0;
- if Scanner.Index <= Scanner.Max_Index then
- while is_Space(S(Scanner.Index)) loop
- Scanner.Index := Scanner.Index + 1;
- exit when Scanner.Index > Scanner.Max_Index;
- end loop;
- Scanner.Length := Scanner.Index - Scanner.First;
- end if;
-
- end skip_Blanks;
-
- ----------------------------------------------------------------------------
-
- procedure trim_blanks(
- Scanner: in out Scanner_Type;
- S: in string
- ) is
- begin
- while Scanner.First < Scanner.Last and then is_Space(S(Scanner.First)) loop
- Scanner.First := Scanner.First + 1;
- end loop;
- while Scanner.Last >= Scanner.First and then is_Space(S(Scanner.Last)) loop
- Scanner.Last := Scanner.Last - 1;
- end loop;
- Scanner.Length := Scanner.Last - Scanner.First + 1;
-
- end trim_Blanks;
-
- ----------------------------------------------------------------------------
-
- procedure scan_Until( --| Scan until C is found
- Scanner: in out Scanner_Type;
- S: in string;
- C: in character
- )
- is
- Index: natural := Scanner.Index;
-
- begin
- Scanner.Length := 0;
- if Index <= Scanner.Max_Index then
- while S(Index) /= C loop
- Index := Index + 1;
- if Index > Scanner.Max_Index then -- Didn't find C
- return;
- end if;
- end loop;
- Scanner.First := Scanner.Index; -- First character scanned
- Scanner.Length := Index - Scanner.First;
- Scanner.Last := Index - 1;
- Scanner.Index := Index;
- end if;
-
- end scan_Until;
-
- ----------------------------------------------------------------------------
-
- procedure scan_Word( --| Scan past a sequence of non-blank characters
- Scanner: in out Scanner_Type;
- S: in string
- ) is
-
- begin
- Scanner.First := Scanner.Index;
- Scanner.Last := Scanner.First - 1;
- Scanner.Length := 0;
- if Scanner.Index <= Scanner.Max_Index then
- while not is_Space(S(Scanner.Index)) loop
- Scanner.Index := Scanner.Index + 1;
- exit when Scanner.Index > Scanner.Max_Index;
- end loop;
- Scanner.Length := Scanner.Index - Scanner.First;
- Scanner.Last := Scanner.Index - 1;
- end if;
-
- end scan_Word;
-
- ----------------------------------------------------------------------------
-
- procedure scan_Number(
- Scanner: in out scanner_Type;
- S: in string
- ) is
-
- begin
- Scanner.First := Scanner.Index;
- if Scanner.Index <= Scanner.Max_Index then
- if S(Scanner.Index) = '-' or else S(Scanner.Index) = '+' then
- Scanner.Index := Scanner.Index + 1;
- end if;
- while Scanner.Index <= Scanner.Max_Index
- and then S(Scanner.Index) in '0'..'9'
- loop
- Scanner.Index := Scanner.Index + 1;
- end loop;
- end if;
- Scanner.Length := Scanner.Index - Scanner.First;
- Scanner.Last := Scanner.Index - 1;
-
- end scan_Number;
-
- ----------------------------------------------------------------------------
-
- procedure scan_Delimited( --| Scan string delimited by a single character
- Scanner: in out scanner_Type;
- S: in string
- )
- is
- quote: character;
-
- begin
- Scanner.First := Scanner.Index;
- if Scanner.Index <= Scanner.Max_Index then
- quote := S(Scanner.Index);
- Scanner.Index := Scanner.Index + 1;
- Scanner.First := Scanner.Index;
- while Scanner.Index <= Scanner.Max_Index
- and then S(Scanner.Index) /= quote
- loop
- Scanner.Index := Scanner.Index + 1;
- end loop;
- end if;
- Scanner.Length := Scanner.Index - Scanner.First;
- Scanner.Last := Scanner.Index - 1;
- if Scanner.Index <= Scanner.Max_Index
- and then S(Scanner.Index) = quote then -- Null string?
- Scanner.Index := Scanner.Index + 1;
- end if;
-
- end scan_Delimited;
-
- ----------------------------------------------------------------------------
-
- procedure scan_Quoted( --| Scan quoted string
- Scanner: in out scanner_Type;
- S: in out string
- )
- is
- quote: character;
- di: natural;
-
- begin
- Scanner.First := Scanner.Index;
- di := Scanner.Index;
- if Scanner.Index <= Scanner.Max_Index then
- quote := S(Scanner.Index);
- Scanner.Index := Scanner.Index + 1;
- Scanner.First := Scanner.Index;
- di := scanner.Index;
- while Scanner.Index <= Scanner.Max_Index loop
- if S(Scanner.Index) = quote then -- Closing quote?
- if Scanner.Index < Scanner.Max_Index
- and then S(Scanner.Index + 1) = quote then -- Doubled quote?
- Scanner.Index := Scanner.Index + 1; -- skip it
- else
- exit; -- Found closing quote at Scanner.Index
- end if;
- end if;
- S(di) := S(Scanner.Index);
- Scanner.Index := Scanner.Index + 1;
- di := di + 1;
- end loop;
- end if;
- Scanner.Length := di - Scanner.First;
- Scanner.Last := di - 1;
- Scanner.Index := Scanner.Index + 1; -- Skip closing quote
-
- end scan_Quoted;
-
- ----------------------------------------------------------------------------
- -- Local function bodies:
-
- function is_Space(C: Character) return boolean is
- --| Return True iff C is a space or tab.
- begin
- return C = ' ' or else C = ASCII.HT;
-
- end is_Space;
-
- ----------------------------------------------------------------------------
-
- end scanners;
- ::::::::::::::
- scanners.out
- ::::::::::::::
- HALSTEAD COMPLEXITY FOR THE SPECIFICATION OF LIBRARY UNIT scanners
-
-
- PACKAGE SPECIFICATION OF SCANNERS AT LINE 1
-
- UNIQUE OPERATORS 26 UNIQUE OPERANDS 32
- TOTAL OPERATORS 110 TOTAL OPERANDS 32
- VOCABULARY 58
- PROGRAM LENGTH 142 ESTIMATED LENGTH 282.08
- PROGRAM VOLUME 827.83 POTENTIAL VOLUME 140.06
- PROGRAM LEVEL .17 ESTIMATED LEVEL 78.77
- INTELLIGENCE CONTENT 65207.61 PROGRAMMING EFFORT 4892.79
- PROGRAMMING TIME 978.56 LANGUAGE LEVEL 23.70
- DELIVERED ERRORS .94 ESTIMATED ERRORS .28
-
-
- HALSTEAD COMPLEXITY FOR THE BODY OF LIBRARY UNIT scanners
-
-
- PROCEDURE BODY OF SCANNERS.START_SCANNER AT LINE 11
-
- UNIQUE OPERATORS 9 UNIQUE OPERANDS 13
- TOTAL OPERATORS 19 TOTAL OPERANDS 18
- VOCABULARY 22
- PROGRAM LENGTH 37 ESTIMATED LENGTH 76.57
- PROGRAM VOLUME 164.99 POTENTIAL VOLUME 24
- PROGRAM LEVEL .15 ESTIMATED LEVEL 52
- INTELLIGENCE CONTENT 8579.70 PROGRAMMING EFFORT 1134.29
- PROGRAMMING TIME 226.86 LANGUAGE LEVEL 3.49
- DELIVERED ERRORS .22 ESTIMATED ERRORS .05
-
-
- FUNCTION BODY OF SCANNERS.IS_EMPTY AT LINE 29
-
- UNIQUE OPERATORS 8 UNIQUE OPERANDS 4
- TOTAL OPERATORS 10 TOTAL OPERANDS 5
- VOCABULARY 12
- PROGRAM LENGTH 15 ESTIMATED LENGTH 32
- PROGRAM VOLUME 53.76 POTENTIAL VOLUME 8
- PROGRAM LEVEL .15 ESTIMATED LEVEL 5
- INTELLIGENCE CONTENT 268.79 PROGRAMMING EFFORT 361.24
- PROGRAMMING TIME 72.25 LANGUAGE LEVEL 1.19
- DELIVERED ERRORS .07 ESTIMATED ERRORS .02
-
-
- FUNCTION BODY OF SCANNERS.IS_ALPHA AT LINE 40
-
- UNIQUE OPERATORS 15 UNIQUE OPERANDS 10
- TOTAL OPERATORS 25 TOTAL OPERANDS 16
- VOCABULARY 25
- PROGRAM LENGTH 41 ESTIMATED LENGTH 91.13
- PROGRAM VOLUME 190.30 POTENTIAL VOLUME 15.50
- PROGRAM LEVEL .08 ESTIMATED LEVEL 21.33
- INTELLIGENCE CONTENT 4059.71 PROGRAMMING EFFORT 2335.87
- PROGRAMMING TIME 467.17 LANGUAGE LEVEL 1.26
- DELIVERED ERRORS .45 ESTIMATED ERRORS .06
-
-
- FUNCTION BODY OF SCANNERS.IS_DIGIT AT LINE 54
-
- UNIQUE OPERATORS 13 UNIQUE OPERANDS 8
- TOTAL OPERATORS 18 TOTAL OPERANDS 11
- VOCABULARY 21
- PROGRAM LENGTH 29 ESTIMATED LENGTH 72.04
- PROGRAM VOLUME 127.38 POTENTIAL VOLUME 15.50
- PROGRAM LEVEL .12 ESTIMATED LEVEL 13.54
- INTELLIGENCE CONTENT 1724.48 PROGRAMMING EFFORT 1046.54
- PROGRAMMING TIME 209.31 LANGUAGE LEVEL 1.89
- DELIVERED ERRORS .20 ESTIMATED ERRORS .04
-
-
- FUNCTION BODY OF SCANNERS.IS_SIGN AT LINE 67
-
- UNIQUE OPERATORS 14 UNIQUE OPERANDS 8
- TOTAL OPERATORS 23 TOTAL OPERANDS 14
- VOCABULARY 22
- PROGRAM LENGTH 37 ESTIMATED LENGTH 77.07
- PROGRAM VOLUME 164.99 POTENTIAL VOLUME 15.50
- PROGRAM LEVEL .09 ESTIMATED LEVEL 16
- INTELLIGENCE CONTENT 2639.91 PROGRAMMING EFFORT 1755.96
- PROGRAMMING TIME 351.19 LANGUAGE LEVEL 1.46
- DELIVERED ERRORS .34 ESTIMATED ERRORS .05
-
-
- FUNCTION BODY OF SCANNERS.IS_DIGIT_OR_SIGN AT LINE 80
-
- UNIQUE OPERATORS 16 UNIQUE OPERANDS 10
- TOTAL OPERATORS 29 TOTAL OPERANDS 19
- VOCABULARY 26
- PROGRAM LENGTH 48 ESTIMATED LENGTH 97.22
- PROGRAM VOLUME 225.38 POTENTIAL VOLUME 15.50
- PROGRAM LEVEL .07 ESTIMATED LEVEL 23.75
- INTELLIGENCE CONTENT 5352.89 PROGRAMMING EFFORT 3276.61
- PROGRAMMING TIME 655.32 LANGUAGE LEVEL 1.07
- DELIVERED ERRORS .63 ESTIMATED ERRORS .08
-
-
- PROCEDURE BODY OF SCANNERS.SKIP_BLANKS AT LINE 95
-
- UNIQUE OPERATORS 15 UNIQUE OPERANDS 10
- TOTAL OPERATORS 33 TOTAL OPERANDS 31
- VOCABULARY 25
- PROGRAM LENGTH 64 ESTIMATED LENGTH 91.13
- PROGRAM VOLUME 297.05 POTENTIAL VOLUME 15.50
- PROGRAM LEVEL .05 ESTIMATED LEVEL 41.33
- INTELLIGENCE CONTENT 12278.14 PROGRAMMING EFFORT 5691.68
- PROGRAMMING TIME 1138.34 LANGUAGE LEVEL .81
- DELIVERED ERRORS 1.10 ESTIMATED ERRORS .10
-
-
- PROCEDURE BODY OF SCANNERS.TRIM_BLANKS AT LINE 115
-
- UNIQUE OPERATORS 15 UNIQUE OPERANDS 8
- TOTAL OPERATORS 41 TOTAL OPERANDS 33
- VOCABULARY 23
- PROGRAM LENGTH 74 ESTIMATED LENGTH 81.91
- PROGRAM VOLUME 334.71 POTENTIAL VOLUME 15.50
- PROGRAM LEVEL .05 ESTIMATED LEVEL 35.20
- INTELLIGENCE CONTENT 11781.88 PROGRAMMING EFFORT 7226.36
- PROGRAMMING TIME 1445.27 LANGUAGE LEVEL .72
- DELIVERED ERRORS 1.39 ESTIMATED ERRORS .11
-
-
- PROCEDURE BODY OF SCANNERS.SCAN_UNTIL AT LINE 132
-
- UNIQUE OPERATORS 17 UNIQUE OPERANDS 14
- TOTAL OPERATORS 38 TOTAL OPERANDS 37
- VOCABULARY 31
- PROGRAM LENGTH 75 ESTIMATED LENGTH 122.56
- PROGRAM VOLUME 366.15 POTENTIAL VOLUME 24
- PROGRAM LEVEL .07 ESTIMATED LEVEL 60.94
- INTELLIGENCE CONTENT 22313.32 PROGRAMMING EFFORT 5585.93
- PROGRAMMING TIME 1117.19 LANGUAGE LEVEL 1.57
- DELIVERED ERRORS 1.08 ESTIMATED ERRORS .12
-
-
- PROCEDURE BODY OF SCANNERS.SCAN_WORD AT LINE 159
-
- UNIQUE OPERATORS 16 UNIQUE OPERANDS 11
- TOTAL OPERATORS 42 TOTAL OPERANDS 41
- VOCABULARY 27
- PROGRAM LENGTH 83 ESTIMATED LENGTH 102.05
- PROGRAM VOLUME 393.88 POTENTIAL VOLUME 15.50
- PROGRAM LEVEL .04 ESTIMATED LEVEL 56.38
- INTELLIGENCE CONTENT 22205.13 PROGRAMMING EFFORT 10007.14
- PROGRAMMING TIME 2001.43 LANGUAGE LEVEL .61
- DELIVERED ERRORS 1.93 ESTIMATED ERRORS .13
-
-
- PROCEDURE BODY OF SCANNERS.SCAN_NUMBER AT LINE 181
-
- UNIQUE OPERATORS 19 UNIQUE OPERANDS 14
- TOTAL OPERATORS 49 TOTAL OPERANDS 48
- VOCABULARY 33
- PROGRAM LENGTH 97 ESTIMATED LENGTH 133.78
- PROGRAM VOLUME 489.31 POTENTIAL VOLUME 15.50
- PROGRAM LEVEL .03 ESTIMATED LEVEL 70.74
- INTELLIGENCE CONTENT 34612 PROGRAMMING EFFORT 15443.24
- PROGRAMMING TIME 3088.65 LANGUAGE LEVEL .49
- DELIVERED ERRORS 2.97 ESTIMATED ERRORS .16
-
-
- PROCEDURE BODY OF SCANNERS.SCAN_DELIMITED AT LINE 205
-
- UNIQUE OPERATORS 17 UNIQUE OPERANDS 11
- TOTAL OPERATORS 60 TOTAL OPERANDS 61
- VOCABULARY 28
- PROGRAM LENGTH 121 ESTIMATED LENGTH 107.54
- PROGRAM VOLUME 579.68 POTENTIAL VOLUME 15.50
- PROGRAM LEVEL .03 ESTIMATED LEVEL 78.94
- INTELLIGENCE CONTENT 45760.71 PROGRAMMING EFFORT 21674.78
- PROGRAMMING TIME 4334.96 LANGUAGE LEVEL .41
- DELIVERED ERRORS 4.17 ESTIMATED ERRORS .19
-
-
- PROCEDURE BODY OF SCANNERS.SCAN_QUOTED AT LINE 235
-
- UNIQUE OPERATORS 20 UNIQUE OPERANDS 12
- TOTAL OPERATORS 76 TOTAL OPERANDS 80
- VOCABULARY 32
- PROGRAM LENGTH 156 ESTIMATED LENGTH 129.45
- PROGRAM VOLUME 780 POTENTIAL VOLUME 15.50
- PROGRAM LEVEL .02 ESTIMATED LEVEL 96
- INTELLIGENCE CONTENT 74880.01 PROGRAMMING EFFORT 39243.30
- PROGRAMMING TIME 7848.66 LANGUAGE LEVEL .31
- DELIVERED ERRORS 7.55 ESTIMATED ERRORS .26
-
-
- FUNCTION BODY OF SCANNERS.IS_SPACE AT LINE 274
-
- UNIQUE OPERATORS 11 UNIQUE OPERANDS 4
- TOTAL OPERATORS 13 TOTAL OPERANDS 5
- VOCABULARY 15
- PROGRAM LENGTH 18 ESTIMATED LENGTH 46.05
- PROGRAM VOLUME 69.50 POTENTIAL VOLUME 8
- PROGRAM LEVEL .12 ESTIMATED LEVEL 3.64
- INTELLIGENCE CONTENT 252.72 PROGRAMMING EFFORT 603.73
- PROGRAMMING TIME 120.75 LANGUAGE LEVEL .92
- DELIVERED ERRORS .12 ESTIMATED ERRORS .02
-
-
- PACKAGE BODY OF SCANNERS AT LINE 1
-
- UNIQUE OPERATORS 22 UNIQUE OPERANDS 1
- TOTAL OPERATORS 22 TOTAL OPERANDS 1
- VOCABULARY 23
- PROGRAM LENGTH 23 ESTIMATED LENGTH 98.10
- PROGRAM VOLUME 104.03 POTENTIAL VOLUME 4.75
- PROGRAM LEVEL .05 ESTIMATED LEVEL .09
- INTELLIGENCE CONTENT 9.46 PROGRAMMING EFFORT 2277.68
- PROGRAMMING TIME 455.54 LANGUAGE LEVEL .22
- DELIVERED ERRORS .44 ESTIMATED ERRORS .03
-
-
- ::::::::::::::
- scanners.spc
- ::::::::::::::
- package scanners is --| Scan tokens from strings
-
- --| Overview
- --| This package is used to break strings into tokens in a very simple
- --| but efficient manner. For maximum efficiency, the scanner type
- --| is not private so that it can be used directly. The following
- --| conventions are adopted to allow the Ada string handling primitives
- --| to be used to maximum advantage:
- --|-
- --| 1. Strings are never copied. The scanner type contains First and
- --| Last components so that slices may be used to obtain the desired
- --| tokens (substrings).
- --|
- --| 2. The scanner type does not include a copy of the string being
- --| scanned, also to avoid copying strings.
- --|
- --| 3. The Length component of a scanner is always set to the length of the
- --| item scanned. If it is zero it means that no such item was found,
- --| either because it wasn't there or because the scanner is exhausted.
- --| The is_Empty operation may be used to determint if a scanner is
- --| exhausted (usually before attempting to scan something).
- --|
- --| 4. All operations have well defined behavior for any consistent input.
- --| There are no exceptions declared in this package or raised directly
- --| by the operations in the package.
- --|+
-
- -- Types --
-
- type scanner_type is
- record
- Index: natural; --| Index of next character to be scanned
- Max_Index: natural; --| Index of last scannable character
- First: natural; --| Index of first character of the result of a scan
- Last: Natural; --| Index of last character of the result of a scan
- Length: Natural; --| Length of the item scanned.
- end record;
-
- ------------------------------------------------------------------------
-
- procedure start_Scanner( --| Initialize a scanner
- Scanner: in out Scanner_Type; --| Scanner to be initialized
- S: in string; --| String to be scanned
- Last: in natural --| Last scannable character in S.
- );
-
- --| Effects: Initialize Scanner for scanning S. S and Last are
- --| typically obtained by calling text_io.Get_Line. The first character
- --| scanned will be S'First and the last character scanned will be Last,
- --| which will generally be different from S'Last.
-
- --| N/A: Requires, Modifies, Raises
-
- ------------------------------------------------------------------------
-
- function is_Empty( --| Return False if Scanner can scan more characters
- Scanner: in Scanner_Type
- ) return boolean;
-
- --| Effects: Return True iff Scanner.Index > Scanner.Max_Index.
- --| N/A: Requires, Modifies, Raises
-
- ------------------------------------------------------------------------
-
- function is_Alpha( --| Check for alphabetic character
- Scanner: in scanner_Type;
- S: in string
- ) return boolean;
-
- --| Effects: Return True iff S(Scanner.Index) is an alphabetic character.
- --| Requires: Scanner must have been created on S using start start_Scanner
- --| prior to calling this routine.
-
- --| N/A: Modifies, Raises
-
- ------------------------------------------------------------------------
-
- function is_Digit( --| Check for start of unsigned number
- Scanner: in scanner_Type;
- S: in string
- ) return boolean;
-
- --| Effects: Return True iff S(Scanner.Index) is a decimal digit.
- --| Requires: Scanner must have been created on S using start start_Scanner
- --| prior to calling this routine.
-
- --| N/A: Modifies, Raises
-
- ------------------------------------------------------------------------
-
- function is_Sign( --| Check for '+' or '-'
- Scanner: in scanner_Type;
- S: in string
- ) return boolean;
-
- --| Effects: Return True iff S(Scanner.Index) is '+' or '-'
- --| Requires: Scanner must have been created on S using start start_Scanner
- --| prior to calling this routine.
-
- --| N/A: Modifies, Raises
-
- ------------------------------------------------------------------------
-
- function is_Digit_or_Sign( --| Check for start of optionally signed number
- Scanner: in scanner_Type;
- S: in string
- ) return boolean;
-
- --| Effects: Return True iff S(Scanner.Index) is '+', '-', or a decimal digit.
- --| Requires: Scanner must have been created on S using start start_Scanner
- --| prior to calling this routine.
- --| N/A: Modifies, Raises
-
- ------------------------------------------------------------------------
-
- procedure skip_Blanks( --| Skip leading blanks and tabs in S
- Scanner: in out Scanner_Type; --| Scanner to be updated
- S: in string --| String being scanned
- );
-
- --| Effects: Increment Scanner.Index until S(Scanner.Index) is neither a
- --| blank nor a tab character, or until it is greater than Scanner.Max_Index.
-
- --| Requires: Scanner must have been created on S using start start_Scanner
- --| prior to calling this routine.
-
- --| N/A: Modifies, Raises
-
- ------------------------------------------------------------------------
-
- procedure trim_blanks(
- Scanner: in out Scanner_Type;
- S: in string
- );
-
- --| Effects: Adjust Scanner.First and Scanner.Last such that
- --| S(Scanner.First..Scanner.Last) contains neither leading nor trailing
- --| blanks or tabs. Scanner.Length is adjusted accordingly. This is
- --| useful to remove blanks after a call to scan_Delimited, Scan_Quoted,
- --| scan_Until, etc.
-
- --| Requires: Scanner must have been created on S using start start_Scanner
- --| prior to calling this routine.
-
- --| N/A: Modifies, Raises
-
- ------------------------------------------------------------------------
-
- procedure scan_Until( --| Scan up to but not including character C
- Scanner: in out Scanner_Type;
- S: in string;
- C: in character
- );
-
- --| Effects: Scan in string S starting at Scanner.Index until the character
- --| C is encountered or the string ends. On return, if Scanner.Length > 0
- --| then S(Scanner.First..Scanner.Last) contains the characters that
- --| appeared before C and Scanner(Index) = C. If C was not found, then
- --| the scanner is not affected except to set Scanner.Length to 0.
-
- --| Requires: Scanner must have been created on S using start start_Scanner
- --| prior to calling this routine.
-
- --| N/A: Modifies, Raises
-
- ------------------------------------------------------------------------
-
- procedure scan_Word( --| Scan past a sequence of non-blank characters
- Scanner: in out Scanner_Type;
- S: in string
- );
-
- --| Effects: Scan in string S for a sequence of non-blank characters,
- --| starting at Scanner.Index. On return, if Scanner.Length > 0
- --| then S(Scanner.First..Scanner.Last) is a word and Scanner.Index is
- --| just past the end of the word (Scanner.Last+1), ready to scan the next
- --| item.
-
- --| Requires: Scanner must have been created on S using start start_Scanner
- --| prior to calling this routine. The scanner must be at a non blank
- --| character (the beginning of a word) or nothing will be scanned.
-
- --| N/A: Modifies, Raises
-
- ------------------------------------------------------------------------
-
- procedure scan_Number(
- Scanner: in out scanner_Type;
- S: in string
- );
-
- --| Effects: Scan in string S for a sequence of numeric characters,
- --| optionally preceeded by a sign (+/-), starting at Scanner.Index. On
- --| return, if Scanner.Length > 0 then S(Scanner.First..Scanner.Last) is a
- --| number and Scanner.Index is just past the end of the number
- --| (Scanner.Last+1), ready to scan the next item.
-
- --| Requires: Scanner must have been created on S using start start_Scanner
- --| prior to calling this routine. Scanner must be positioned at a digit
- --| or sign (+/-) when this routine is called or nothing will be scanned.
-
- --| N/A: Modifies, Raises
-
- ------------------------------------------------------------------------
-
- procedure scan_Delimited( --| Scan string delimited by a single character
- Scanner: in out scanner_Type;
- S: in string
- );
-
- --| Effects: The character S(Scanner.Index) is considered a "quote".
- --| Scanner.First is set to the Scanner.Index+1, and Scanner.Index is
- --| incremented until another "quote" is encountered or the end of the
- --| string is reached. On return, Scanner.Last is the index of the closing
- --| "quote" or the last character in S if no closing "quote" was found.
-
- --| Requires: Scanner must have been created on S using start start_Scanner
- --| prior to calling this routine.
- --| N/A: Modifies, Raises
-
- ------------------------------------------------------------------------
-
- procedure scan_Quoted( --| Scan quoted string
- Scanner: in out scanner_Type;
- S: in out string
- );
-
- --| Effects: The character S(Scanner.Index) is considered a "quote".
- --| The string S is scanned for a closing "quote". During the scan,
- --| two quotes in a row are replaced by a single quote. On return,
- --| Scanner.First is the first character of the quoted string, and
- --| Scanner.Last is the last character. (The outermost quotes are
- --| not included.) Scanner.Index is the first character after the
- --| closing quote, Scanner.Length is the number of characters in the
- --| quoted string. Note that the string being scanned (S) is modified
- --| by this routine (to remove the extra quotes, if any).
-
- --| Requires: Scanner must have been created on S using start start_Scanner
- --| prior to calling this routine.
-
- --| N/A: Modifies, Raises
-
- ------------------------------------------------------------------------
-
- end scanners;
-