wireform-core-0.2.0.1: Shared FFI primitives for wireform format packages
Safe HaskellNone
LanguageGHC2021

Wireform.Parser.Switch

Description

Efficient literal branching using Template Haskell.

Compiles string-literal case branches into a trie of primitive byte comparisons with grouped bounds checks.

@

Synopsis

Documentation

TH literal splices

char :: Char -> Q Exp Source #

$(char 'x') compiles to word8 0xNN for ASCII characters, or the appropriate multi-byte UTF-8 sequence otherwise. Only ASCII is supported for now.

string :: String -> Q Exp Source #

$(string "foo") compiles to byteString "foo".

Helpers used by generated code (not for direct use)

switchFailed :: Parser m e a Source #

Fail without consuming input.

switchBranch :: Int -> Parser m e a -> Parser m e a -> Parser m e a Source #

Branch on an ensure check: if enough bytes, run t; else f.

switchAnyWord8Unsafe :: Parser m e Word8 Source #

Unsafe read — caller must have ensured at least 1 byte.

switchPeekWord8Unsafe :: Parser m e Word8 Source #

Peek the next byte without consuming. Used by the trie code generator so that a wildcard-branch falling back to the current node's terminal action does not eat a byte that belongs to whatever runs after the switch.

(Previously the generator used switchAnyWord8Unsafe for the byte dispatch, which consumed the byte and then ran the terminal action past that byte. For input like "1,…" on a switch with literals "1", "1.0", "1.00", that meant the "1" terminal action ran from after the comma — silently breaking every quality-weighted Accept-* parser whose first entry used q=1.)

switchSkip1 :: Parser m e () Source #

Skip one byte (used after switchPeekWord8Unsafe has decided a child branch matches).