## string.scanner -- stateful string scanning
This module implements string scanner which advances through target string on successful match, keeping current position and last matched sub-string.
### Index
namespace [str](#str)
class [Scanner](#scanner)
- [Scanner](#scanner_ctor)(_context_: string, _pos_ = 0) => Scanner
- [.context](#context)(invar _self_: Scanner) => string
- [.pos](#pos)(invar _self_: Scanner) => int
- [.pos=](#pos)(_self_: Scanner, _value_: int)
- [.rest](#rest)(invar _self_: Scanner) => int
- [append](#append)(_self_: Scanner, _str_: string)
- [fetch](#fetch)(_self_: Scanner, _count_: int) => string
- [peek](#peek)(invar _self_: Scanner, _count_: int) => string
- [scan](#scan)(_self_: Scanner, _pattern_: string) => int
- [seek](#seek)(_self_: Scanner, _pattern_: string) => int
- [matched](#matched)(invar _self_: Scanner, _group_ = 0) => string
- [matchedPos](#matchedpos)(invar _self_: Scanner, _group_ = 0) => tuple<start: int, end: int>|none
- [line](#line)(invar _self_: Scanner) => int
- [follows](#follows)(invar _self_: Scanner, _pattern_: string) => bool
- [precedes](#precedes)(invar _self_: Scanner, _pattern_: string) => bool
### Classes
#### `str::Scanner`
Provides way to successively process textual data using Dao string patterns.
#### Methods
```ruby
Scanner(context: string, pos = 0) => Scanner
```
Constructs scanner operating on string *context* starting at position *pos*
```ruby
.context(invar self: Scanner) => string
```
String being scanned
```ruby
.pos(invar self: Scanner) => int
.pos=(self: Scanner, value: int)
```
Current position
```ruby
.rest(invar self: Scanner) => int
```
Number of bytes left to scan (from the current position to the end of the context)
```ruby
append(self: Scanner, str: string)
```
Appends *str* to the context
```ruby
fetch(self: Scanner, count: int) => string
```
Returns *count* bytes starting from the current position and advances the scanner
**Errors:** `Param` when *count* < 0
```ruby
peek(invar self: Scanner, count: int) => string
```
Returns *count* bytes starting from the current position without advancing the scanner
```ruby
scan(self: Scanner, pattern: string) => int
```
Mathes *pattern* immediately at the current position; on success, the scanner is advanced and its last match information is updated. Returns the number of bytes the scanner has advanced through
```ruby
scan(self: Scanner, pattern: string) => int
```
Mathes *pattern* anywhere in the string after the current position; on success, the scanner is advanced and its last match information is updated. Returns the number of bytes the scanner has advanced through
```ruby
matched(invar self: Scanner, group = 0) => string
```
The last matched sub-string or its group *group* (if *group* is greater then zero)
```ruby
matchedPos(invar self: Scanner, group = 0) => tuple|none
```
Position of the last matched sub-string or its group *group* (if *group* is greater then zero)
```ruby
line(invar self: Scanner) => int
```
Line number at the current position
```ruby
follows(invar self: Scanner, pattern: string) => bool
```
Matches *pattern* immediately before the current position without affecting the state of the scanner
```ruby
precedes(invar self: Scanner, pattern: string) => bool
```
Matches *pattern* immediately after the current position without affecting the state of the scanner