The (text parse)
library is inspired and compatible with Oleg
Kiselyov's input parsing library. You can use this library in place of his
'input-parse.scm'
and 'look-for-str.scm'
.
Looks for a string str from the input port in-port. The optional argument max-no-char limits the maxmum number of characters to be read from the port; the search span is until EOF.
If str is found, the function returns the number of characters it has read from the port, and the port is set to read the first char after that (that is, after the str). If str is not found, the function returns #f.
Note: Although this procedure has ``?'` in its name, it may return non-boolean value, contrary to the Scheme convention.
In the following functions, char-list refers to one of the following.
A character set which defined in SRFI-14.
A list of characters, character sets and/or symbol *eof*
.
That denotes a set of characters. If a symbol *eof*
is included, the EOF
condition is also included. Without *eof*
, the EOF condition is regarded
as an error.
Reads a character from the port and looks it up in the char-list of expected characters. If the read character was found among the expected, it is returned. Otherwise, the procedure writes a nasty message using string as a comment, and quits.
Char-list/number must be either char-list or number.
If it is a number; skips the specified number of characters from the port and returns #f.
If it is a char-list; reads and skips characters from the port until one of the
break characters is encountered. This break character is returned. The break
characters are specified as the char-list. This list may include EOF, which is
to be coded as a symbol *eof*
.
Advances the port to the first character that is not a member of the char-list -- or till the EOF, whichever occurs sooner. This character or the EOF object is returned. This character is left on the stream.
Advances to the next character in the port and peeks at it. This function is useful when parsing LR(1)-type languages.
Skips any number of characters in prefix-char-list, then collects the characters until it sees break-char-list. The collected characters are returned as a string. The break character remains in the port.
If the function encounters EOF and *eof*
is not included in
break-char-list, an error is signalled with comment is included in the
message.
Reads and collects the characters as far as it belongs to char-list/pred, then returns them as a string. The first character that doesn't belong to char-list/pred remains on the port.
Char-list/pred may be a char-list or a predicate that takes a character. If it is a predicate, each character is passed to it, and the character is regarded to ``belong to'' char-list/pred when it returns a true value.
Reads up to n characters, collects them into a string, and returns it. If the input stream contains less characters, the returns string contains as many characters available.
This function is similar with get-string-n
.