~/bend-docscommunity

src/rules/correctness/escape.bend checks

raw source on the hub · import 0x013e0f9a479bbebad5ed196725eede95/src/rules/correctness/escape.bend as Escape

rule escape: a string or char literal with \0 then a digit, as in "\033[1m". Bend's escapes are \n \t \r \0 \\ \' \" and \u{..}; it has no octal, so \033 is NUL and then the chars "33" (nohzafk esc_bad: the bytes 00 33 33, not ESC), with no error. Write the code point, \u{1B}. Other unknown escapes (\x1b, \e) the checker rejects on its own.

5 imports
import Base
import ../../src.bend as Src
import ../../finding.bend as F
import ../../syntax/lex.bend as Lex
import ../../lazy/lazy.bend as Lazy

Types

type Sym source · line 15 · raw

Data

a literal's char as the rule reads it: a backslash, a 0, another digit, or anything else. Read once, so the scan below matches constructors, not char literals.

Definitions

def sym source · line 22 · raw

@cc:Char -> Sym

a char as a Sym

def syms source · line 30 · raw

@cs:List<&2, Char> -> List<&2, Sym>

a literal's chars as Syms

def octal source · line 38 · raw

@ss:Sym -> Maybe<&2, Char>

the Sym's char when it is an octal digit

def run.if source · line 48 · raw

@mm:Maybe<&2, Char> -> @rest:List<&2, Char> -> List<&2, Char>

keep the octal digit, and those after it

def run source · line 56 · raw

@ss:List<&2, Sym> -> @nn:Nat -> List<&2, Char>

the octal digits (at most two) right after the \0, in order

def value source · line 66 · raw

@cs:List<&2, Char> -> @+acc:U32 -> U32

the digits' octal value

def hexd source · line 74 · raw

@+nn:U32 -> String

a hex digit

def hex source · line 78 · raw

@+nn:U32 -> String

a value under 256 in hex, without leading zeros

def finding source · line 82 · raw

@+ds:List<&2, Char> -> @+path:String -> @+line:U32 -> @+col:U32 -> 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding

the finding for \0 at a column, the digits after it in ds

def after source · line 91 · raw

@ss:List<&2, Sym> -> @+path:String -> @+line:U32 -> @+col:U32 -> @more:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>

after a \0 at a column: a finding when a digit follows

def scan source · line 101 · raw

@ss:List<&2, Sym> -> @+path:String -> @+line:U32 -> @+col:U32 -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>

a literal's Syms from a column; an escape is its backslash and one char

def check.go source · line 112 · raw

@toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> @+path:String -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>

def check source · line 124 · raw

@ss:0x013e0f9a479bbebad5ed196725eede95/src/src.Src -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>

the rule