translateLabelEx scope _ nsid (L1.L1RelOrAbsPathNoInt pss isabs rp) = do
  let ra = L1.L1RelOrAbsPath pss isabs rp
  findScopedSymbolByRAPath pss nsid ra $ \nsc labelName ->
    case M.lookup (L1.l1IdBS labelName) (L2.l2nsLabels nsc) of
      Just l -> Just $ L2.L2ExReferenceLabel pss l
      Nothing ->
        case M.lookup (L1.l1IdBS labelName) (L2.l2nsNamedValues nsc) of
          Just nv -> Just $ L2.L2ExReferenceValue pss nv
          Nothing -> case M.lookup (L1.l1IdBS labelName) (L2.l2nsClassValues nsc) of
            Just cv -> Just $ L2.L2ExReferenceClassValue pss cv
            Nothing -> Nothing

-- | Translates an L1Label to an L2Label, giving an appropriate error if the
--   label is something other than an ensemble label.
translateLabelEx scope _ nsid (L1.L1RelOrAbsPathNoInt pss isabs rp) = do
  let ra = L1.L1RelOrAbsPath pss isabs rp
  findScopedSymbolByRAPath pss nsid ra $ \nsc labelName ->
    case M.lookup (L1.l1IdBS labelName) (L2.l2nsLabels nsc) of
      Just l -> Just $ L2.L2ExReferenceLabel pss l
      Nothing ->
        case M.lookup (L1.l1IdBS labelName) (L2.l2nsNamedValues nsc) of
          Just nv -> Just $ L2.L2ExReferenceValue pss nv
          Nothing -> case M.lookup (L1.l1IdBS labelName) (L2.l2nsClassValues nsc) of
            Just cv -> Just $ L2.L2ExReferenceClassValue pss cv
            Nothing -> Nothing

-- | Translates an L1Label to an L2Label, giving an appropriate error if the
--   label is something other than an ensemble label.
translateLabelEx scope _ nsid (L1.L1RelOrAbsPathNoInt pss isabs rp) = do
  let ra = L1.L1RelOrAbsPath pss isabs rp
  findScopedSymbolByRAPath pss nsid ra $ \nsc labelName ->
    case M.lookup (L1.l1IdBS labelName) (L2.l2nsLabels nsc) of
      Just l -> Just $ L2.L2ExReferenceLabel pss l
      Nothing ->
        case M.lookup (L1.l1IdBS labelName) (L2.l2nsNamedValues nsc) of
          Just nv -> Just $ L2.L2ExReferenceValue pss nv
          Nothing -> case M.lookup (L1.l1IdBS labelName) (L2.l2nsClassValues nsc) of
            Just cv -> Just $ L2.L2ExReferenceClassValue pss cv
            Nothing -> Nothing

-- | Translates an L1Label to an L2Label, giving an appropriate error if the
--   label is something other than an ensemble label.