module Momo.Subst
  ( Subst
  , path
  ) where

import Data.Map qualified as Map

import Momo.Ident qualified as Ident
import Momo.Path (Path)
import Momo.Path qualified as Path

type Subst = Ident.Table Path

path :: Path -> Subst -> Path
path :: Path -> Subst -> Path
path Path
p Subst
sub =
  case Path
p of
    Path.Ident Ident
i ->
      case Ident -> Subst -> Maybe Path
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Ident
i Subst
sub of
        Maybe Path
Nothing ->
          Path
p
        Just Path
p' ->
          Path
p'
    Path.Dot Path
root Text
field ->
      Path -> Text -> Path
Path.Dot (Path -> Subst -> Path
path Path
root Subst
sub) Text
field