# Path: progSpec.py
# def cdlog(lvl, mesg):
#     global MaxLogLevelToShow
#     global lastLogMesgs
#     global highestLvl
#     highestLvl=lvl
#     resizeLogArray(lvl)
#     lastLogMesgs[lvl]=mesg
#     for i in range(highestLvl+1, len(lastLogMesgs)):
#         lastLogMesgs[i]=''
#     if(lvl<=MaxLogLevelToShow):
#         if(lvl==0): print('')
#         printAtLvl(lvl, mesg, '|    ')
# 
# def cdErr(mesg):
#     global lastLogMesgs
#     global highestLvl
#     highestLvl+=1
#     lastLogMesgs[highestLvl]="\n\nError: "+mesg
#     exit(1)
# 
# def logLvl():
#     return highestLvl+1


import re
import progSpec
from progSpec import cdlog, cdErr, logLvl
from pyparsing import *
    inputString = doMacroSubstitutions(tmpMacroDefs, inputString)

    progSpec.saveTextToErrFile(inputString)
    try:
        localResults = libTagParser.parseString(inputString, parseAll = False)
    except ParseException as pe:
        cdErr( "While parsing lib tags: {}".format( pe))

    tagStore = extractTagDefs(localResults.libTagParser.tagDefList)
    return tagStore

def parseCodeDogString(inputString, ProgSpec, clsNames, macroDefs, description):
    tmpMacroDefs={}
    inputString = comment_remover(inputString)
    extractMacroDefs(tmpMacroDefs, inputString)
    inputString = doMacroSubstitutions(tmpMacroDefs, inputString)
    LogLvl=logLvl()
    cdlog(LogLvl, "PARSING: "+description+"...")
    results = parseInput(inputString)
    cdlog(LogLvl, "EXTRACTING: "+description+"...")
    tagStore = extractTagDefs(results.progSpecParser.tagDefList)
    buildSpecs = extractBuildSpecs(results.progSpecParser.buildSpecList)
    newClasses = extractObjectsOrPatterns(ProgSpec, clsNames, macroDefs, results.progSpecParser.objectList,description)
    classes = [ProgSpec, clsNames]
    return[tagStore, buildSpecs, classes, newClasses]

def AddToObjectFromText(ProgSpec, clsNames, inputStr, description):
    macroDefs = {} # This var is not used here. If needed, make it an argument.
    inputStr = comment_remover(inputStr)
    #print('####################\n',inputStr, "\n######################^\n\n\n")

# Path: progSpec.py
# def cdlog(lvl, mesg):
#     global MaxLogLevelToShow
#     global lastLogMesgs
#     global highestLvl
#     highestLvl=lvl
#     resizeLogArray(lvl)
#     lastLogMesgs[lvl]=mesg
#     for i in range(highestLvl+1, len(lastLogMesgs)):
#         lastLogMesgs[i]=''
#     if(lvl<=MaxLogLevelToShow):
#         if(lvl==0): print('')
#         printAtLvl(lvl, mesg, '|    ')
# 
# def cdErr(mesg):
#     global lastLogMesgs
#     global highestLvl
#     highestLvl+=1
#     lastLogMesgs[highestLvl]="\n\nError: "+mesg
#     exit(1)
# 
# def logLvl():
#     return highestLvl+1


# Path: codeDogParser.py
import re
import progSpec
from progSpec import cdlog, cdErr, logLvl
from pyparsing import *

    inputString = doMacroSubstitutions(tmpMacroDefs, inputString)

    progSpec.saveTextToErrFile(inputString)
    try:
        localResults = libTagParser.parseString(inputString, parseAll = False)
    except ParseException as pe:
        cdErr( "While parsing lib tags: {}".format( pe))

    tagStore = extractTagDefs(localResults.libTagParser.tagDefList)
    return tagStore

def parseCodeDogString(inputString, ProgSpec, clsNames, macroDefs, description):
    tmpMacroDefs={}
    inputString = comment_remover(inputString)
    extractMacroDefs(tmpMacroDefs, inputString)
    inputString = doMacroSubstitutions(tmpMacroDefs, inputString)
    LogLvl=logLvl()
    cdlog(LogLvl, "PARSING: "+description+"...")
    results = parseInput(inputString)
    cdlog(LogLvl, "EXTRACTING: "+description+"...")
    tagStore = extractTagDefs(results.progSpecParser.tagDefList)
    buildSpecs = extractBuildSpecs(results.progSpecParser.buildSpecList)
    newClasses = extractObjectsOrPatterns(ProgSpec, clsNames, macroDefs, results.progSpecParser.objectList,description)
    classes = [ProgSpec, clsNames]
    return[tagStore, buildSpecs, classes, newClasses]

def AddToObjectFromText(ProgSpec, clsNames, inputStr, description):
    macroDefs = {} # This var is not used here. If needed, make it an argument.
    inputStr = comment_remover(inputStr)
    #print('####################\n',inputStr, "\n######################^\n\n\n")

    errLevl=logLvl(); cdlog(errLevl, 'Parsing: '+description)