import re


def _tokenizeGlm(inputStr, filePath=True):
    """ Turn a GLM file/string into a linked list of tokens.

    E.g. turn a string like this:
    clock {clockey valley;};
    object house {name myhouse; object ZIPload {inductance bigind; power newpower;}; size 234sqft;};

    Into a Python list like this:
    ['clock','{','clockey','valley','}','object','house','{','name','myhouse',';',
        'object','ZIPload','{','inductance','bigind',';','power','newpower','}','size','234sqft','}']
    """

    if filePath:
        with open(inputStr,'r') as glmFile:
            data = glmFile.read()

    else:
        data = inputStr
    # Get rid of http for stylesheets because we don't need it and it conflicts with comment syntax.
    data = re.sub(r'http:\/\/', '', data)
    # Strip comments.
    data = re.sub(r'\/\/.*\n', '', data)
    # Also strip non-single whitespace because it's only for humans:
    data = data.replace('\r','').replace('\t',' ')
    # Tokenize around semicolons, braces and whitespace.
    tokenized = re.split(r'(;|\}|\{|\s)',data)
    # Get rid of whitespace strings.
    basicList = [x for x in tokenized if x!='' and x!=' ']
    return basicList