import itertools

from thinglang.lexer.values.identifier import Identifier

"""
The internal ordering of core types used by the compiler and runtime
"""

INTERNAL_TYPE_COUNTER = itertools.count(1)

# TODO: map dynamically at runtime

INTERNAL_TYPE_ORDERING = {
    Identifier("text"): next(INTERNAL_TYPE_COUNTER),
    Identifier("number"): next(INTERNAL_TYPE_COUNTER),
    Identifier("bool"): next(INTERNAL_TYPE_COUNTER),
    Identifier("list"): next(INTERNAL_TYPE_COUNTER),
    Identifier("map"): next(INTERNAL_TYPE_COUNTER),
    Identifier("iterator"): next(INTERNAL_TYPE_COUNTER),
    Identifier("Console"): next(INTERNAL_TYPE_COUNTER),
    Identifier("File"): next(INTERNAL_TYPE_COUNTER),
    Identifier("Directory"): next(INTERNAL_TYPE_COUNTER),
    Identifier("Time"): next(INTERNAL_TYPE_COUNTER),
    Identifier("Exception"): next(INTERNAL_TYPE_COUNTER)
}

import glob

import os

from thinglang.lexer.values.identifier import Identifier

"""
The internal ordering of core types used by the compiler and runtime
"""

CURRENT_PATH = os.path.dirname(os.path.abspath(__file__))
SOURCE_PATTERN = os.path.join(CURRENT_PATH,  'source/**/*.thing')


def list_types():
    for path in glob.glob(SOURCE_PATTERN, recursive=True):
        name = os.path.basename(path).replace('.thing', '')
        yield name, path


PRIMITIVE_TYPES = [
    'text',
    'number'
]

INTERNAL_SOURCES = {Identifier(name): path for name, path in list_types()}
Remove manual INTERNAL_TYPE_ORDERING map in favor of explicit import tables