{-# language BangPatterns #-}
{-# language BinaryLiterals #-}
{-# language DataKinds #-}
{-# language DeriveFunctor #-}
{-# language DerivingStrategies #-}
{-# language DuplicateRecordFields #-}
{-# language GADTSyntax #-}
{-# language KindSignatures #-}
{-# language LambdaCase #-}
{-# language MagicHash #-}
{-# language MultiWayIf #-}
{-# language NamedFieldPuns #-}
{-# language PolyKinds #-}
{-# language RankNTypes #-}
{-# language ScopedTypeVariables #-}
{-# language StandaloneDeriving #-}
{-# language TypeApplications #-}
{-# language UnboxedSums #-}
{-# language UnboxedTuples #-}
module Data.Bytes.Parser.Unsafe
(
Parser(..)
, cursor
, expose
, unconsume
, jump
) where
import Prelude hiding (length)
import Data.Primitive (ByteArray)
import Data.Bytes.Types (Bytes(..))
import Data.Bytes.Parser.Internal (Parser(..),uneffectful)
import Data.Bytes.Parser.Internal (InternalResult(..))
cursor :: Parser e s Int
cursor = uneffectful $ \Bytes{offset,length} ->
InternalSuccess offset offset length
expose :: Parser e s ByteArray
expose = uneffectful $ \Bytes{length,offset,array} ->
InternalSuccess array offset length
unconsume :: Int -> Parser e s ()
unconsume n = uneffectful $ \Bytes{length,offset} ->
InternalSuccess () (offset - n) (length + n)
jump :: Int -> Parser e s ()
jump ix = uneffectful $ \(Bytes{length,offset}) ->
InternalSuccess () ix (length + (offset - ix))