# std/scan

One comment- and string-aware cursor over foreign text (CSS, ICU messages, HTML templates, SDL) for generators.

Offsets are byte offsets. The scanner is a record advanced through `modify` functions, which keep `line`/`col` in sync. `until`, `untilStr` and `balanced` skip over quoted strings and line and block comments, so a delimiter inside one never ends the scan. Block comments do not nest: the first `blockClose` closes one, as in CSS and C.

## Scanner

`type`, at line 13.

```vyrn
type Scanner = {
    src: String,
    pos: Int64,
    line: Int64,
    col: Int64,
    // The line-comment marker ("//", "#", ...); "" disables line comments.
    lineComment: String,
    // The block-comment open/close markers ("/*" and "*/" for CSS); "" for
    // `blockOpen` disables block comments. Non-nesting.
    blockOpen: String,
    blockClose: String,
    // Primary and secondary quote bytes (34 for ", 39 for '); -1 disables.
    quote1: Int64,
    quote2: Int64,
    // The escape byte inside a quoted string (92 for backslash); -1 disables.
    escape: Int64,
}
```

A cursor over `src`, with 1-based `line`/`col` and its lexical config.

## newScanner

`fn`, at line 33.

```vyrn
fn newScanner(src: String) -> Scanner
```

A Vyrn-flavored scanner: `//` line comments, `"`/`'` strings, `\` escape. Vyrn has no block comments, so `blockOpen`/`blockClose` are disabled.

## cssScanner

`fn`, at line 50.

```vyrn
fn cssScanner(src: String) -> Scanner
```

A CSS-flavored scanner: no line comments, `/* */` block comments, `"`/`'` strings, `\` escape.

## scanner

`fn`, at line 67.

```vyrn
fn scanner(
    src: String,
    lineComment: String,
    blockOpen: String,
    blockClose: String,
    quote1: Int64,
    quote2: Int64,
    escape: Int64,
) -> Scanner
```

A fully configured scanner. Pass `""` for `lineComment`/`blockOpen` to disable that comment kind and `-1` for any disabled byte.

## atEnd

`fn`, at line 90.

```vyrn
fn atEnd(sc: Scanner) -> Bool
```

## peek

`fn`, at line 95.

```vyrn
fn peek(sc: Scanner) -> Int64
```

The current byte, or `-1` at end of input.

## peekAt

`fn`, at line 103.

```vyrn
fn peekAt(sc: Scanner, n: Int64) -> Int64
```

The byte `n` ahead, or `-1` past the end.

## looksAt

`fn`, at line 112.

```vyrn
fn looksAt(sc: Scanner, s: String) -> Bool
```

Whether the input at the cursor begins with `s`.

## advance

`fn`, at line 136.

```vyrn
fn advance(sc: modify Scanner) -> Unit
```

Advances one byte, keeping `line`/`col` in sync.

## skipWs

`fn`, at line 174.

```vyrn
fn skipWs(sc: modify Scanner) -> Unit
```

Skips ASCII whitespace and comments.

## ident

`fn`, at line 203.

```vyrn
fn ident(sc: modify Scanner) -> String
```

Consumes a `[A-Za-z0-9_]+` run and returns it (empty if none here).

## quotedString

`fn`, at line 218.

```vyrn
fn quotedString(sc: modify Scanner) -> Option<String>
```

If the cursor is at a quote, consumes the quoted run and returns its inner text with escapes as written; the caller decodes its own dialect. `None` if not at a quote. An unterminated string returns the text to end of input.

## until

`fn`, at line 264.

```vyrn
fn until(sc: modify Scanner, stop: Int64) -> String
```

Consumes up to, not including, the first top-level byte `stop`, skipping quoted strings and comments, and returns the consumed text. Stops at end of input if `stop` never appears at the top level.

## untilStr

`fn`, at line 278.

```vyrn
fn untilStr(sc: modify Scanner, stop: String) -> String
```

Like `until`, but for the multi-byte string `stop`. The cursor is left on `stop`.

## balanced

`fn`, at line 293.

```vyrn
fn balanced(sc: modify Scanner, open: Int64, close: Int64) -> String
```

With the cursor at byte `open`, consumes the balanced region through the matching `close` (nesting, string and comment aware) and returns the text between them. An unbalanced region returns everything to end of input. Not at `open`: returns `""` and consumes nothing.

---

From https://vyrn-lang.github.io/docs/std/scan.html — generated by `site/export.vyrn` from the Vyrn repository.
