| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit.Parser.Json.Lexer
Description
Fast imperative JSON tokenizer over strict ByteString.
Complementary to the combinator path in Circuit.Parser.Json: it trades
compositionality for raw speed — a single unsafeIndex pass emitting
zero-copy slices. Structural tokens only; validation (number grammar,
escape legality, nesting) belongs to the layer above.
Synopsis
- data JsonToken
- runJsonLexerBS :: ByteString -> Either (Int, String) [JsonToken]
Tokens
A flat JSON structural token. TString and TNumber payloads are
zero-copy slices of the input; a TString keeps its escapes intact.
Constructors
| TBraceOpen | |
| TBraceClose | |
| TBrackOpen | |
| TBrackClose | |
| TComma | |
| TColon | |
| TString ByteString | |
| TNumber ByteString | |
| TTrue | |
| TFalse | |
| TNull |
Running
runJsonLexerBS :: ByteString -> Either (Int, String) [JsonToken] Source #
Tokenize a strict ByteString.
On failure, returns the byte offset and a message.
>>>runJsonLexerBS (C.pack "{\"a\": [1, true]}")Right [TBraceOpen,TString "a",TColon,TBrackOpen,TNumber "1",TComma,TTrue,TBrackClose,TBraceClose]
>>>runJsonLexerBS (C.pack "[1")Right [TBrackOpen,TNumber "1"]
>>>runJsonLexerBS (C.pack "\"ab")Left (3,"unterminated string")
>>>runJsonLexerBS (C.pack "nul")Left (0,"bad literal")
>>>runJsonLexerBS (C.pack "@")Left (0,"unexpected byte 64")