module Beekeeper.Core.Identifiers where

import qualified Data.List as List
import Language.Python.Common.SrcLocation (SrcSpan)

data Location = Path FilePath | Span SrcSpan deriving Eq

data PythonTree a b = ModuleTree {moduleNode :: a,
                                  children   :: [PythonTree a b],
                                  location   :: Location}
                    | SourceTree {sourceNode :: b,
                                  children   :: [PythonTree a b],
                                  location   :: Location}

data ModuleName = ModuleName {moduleName :: String}
                | SourceName {moduleName :: String}

-- TODO: this cursor needs a little more structure
type ImportSource = [String]

modulePrefixes :: [String] -> [([String], String)]
modulePrefixes = map (\x -> (x, List.intercalate "." x)) . tail . List.inits

splitOn :: Char -> String -> [String]
splitOn _ [] = []
splitOn delim str = case span (/= delim) str of
  ([], remainder) -> splitOn delim . dropWhile (== delim) $ remainder
  (name, remainder) -> name : splitOn delim remainder
