{-# LANGUAGE UnboxedTuples, MagicHash, RecordWildCards #-}
{-|
Module      : Parsley.Internal.Backend.Machine.Types.Input
Description : Packaging of offsets and positions.
License     : BSD-3-Clause
Maintainer  : Jamie Willis
Stability   : experimental

Exposes abstractions for working with combined offset and position information. `Input` is used
for static augmented information, and `Input#` is a raw combination of the two components.

@since 1.8.0.0
-}
module Parsley.Internal.Backend.Machine.Types.Input (module Parsley.Internal.Backend.Machine.Types.Input) where

import Parsley.Internal.Backend.Machine.InputRep           (Rep)
import Parsley.Internal.Backend.Machine.Types.Base         (Pos)
import Parsley.Internal.Backend.Machine.Types.Input.Offset (Offset(offset), mkOffset)
--import Parsley.Internal.Backend.Machine.Types.Input.Pos    ()
import Parsley.Internal.Common.Utils                       (Code)

{-|
Packages known static information about offsets (via `Offset`) with static information about positions
(currently unavailable).

@since 1.8.0.0
-}
data Input o = Input {
    Input o -> Offset o
off  :: Offset o,
    Input o -> Code Pos
pos :: Code Pos
  }

{-|
Packages a dynamic offset with a dynamic position.

@since 1.8.0.0
-}
data Input# o = Input# {
    Input# o -> Code (Rep o)
off#  :: Code (Rep o),
    Input# o -> Code Pos
pos#  :: Code Pos
  }

{-|
Strips away static information, returning the raw dynamic components.

@since 1.8.0.0
-}
fromInput :: Input o -> Input# o
fromInput :: Input o -> Input# o
fromInput Input{Code Pos
Offset o
pos :: Code Pos
off :: Offset o
pos :: forall o. Input o -> Code Pos
off :: forall o. Input o -> Offset o
..} = Code (Rep o) -> Code Pos -> Input# o
forall o. Code (Rep o) -> Code Pos -> Input# o
Input# (Offset o -> Code (Rep o)
forall o. Offset o -> Code (Rep o)
offset Offset o
off) Code Pos
pos

{-|
Given a unique identifier, forms a plainly annotated static combination of position and offset.

@since 1.8.0.0
-}
toInput :: Word -> Input# o -> Input o
toInput :: Word -> Input# o -> Input o
toInput Word
u Input#{Code Pos
Code (Rep o)
pos# :: Code Pos
off# :: Code (Rep o)
pos# :: forall o. Input# o -> Code Pos
off# :: forall o. Input# o -> Code (Rep o)
..} = Offset o -> Code Pos -> Input o
forall o. Offset o -> Code Pos -> Input o
Input (Code (Rep o) -> Word -> Offset o
forall o. Code (Rep o) -> Word -> Offset o
mkOffset Code (Rep o)
off# Word
u) Code Pos
pos#