qmrparser (version 0.1.5)

streamParser: Generic interface for character processing, allowing forward and backwards translation.

Description

Generic interface for character processing. It allows going forward sequentially or backwards to a previous arbitrary position.

Each one of these functions performs an operation on or obtains information from a character sequence (stream).

Usage

streamParserNextChar(stream) streamParserNextCharSeq(stream) streamParserPosition(stream) streamParserClose(stream)

Arguments

stream
object containing information about the text to be processed and, specifically, about the next character to be read

Value

streamParserNextChar and streamParserNextCharSeq
Three field list:
  • status"ok" or "eof"
  • charCharacter read (ok) or "" (eof)
  • streamWith information about next character to be read or same position if end of file has been reached ("eof")
streamParserPosition
Three field list:
  • fileName File name or "" if the stream is not associated with a file name
  • lineline number
  • linePoscharacter to be read position within its line
  • streamPoscharacter to be read position from the text beginning
streamParserClose
NULL

Details

  • streamParserNextChar Reads next character, checking if position to be read is correct.

  • streamParserNextCharSeq Reads next character, without checking if position to be read is correct. Implemented since it is faster than streamParserNextChar
  • streamParserPosition Returns information about text position being read.

  • streamParserClose Closes the stream

See Also

streamParserFromFileName streamParserFromString

Examples


stream<- streamParserFromString("Hello world")

cstream <- streamParserNextChar(stream)

while( cstream$status == "ok" ) {
    print(streamParserPosition(cstream$stream))
    print(cstream$char)
    cstream <- streamParserNextCharSeq(cstream$stream)
}

streamParserClose(stream)