# 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 *
fieldDef.setParseAction(logFieldDef)

#########################################   P A R S E R   S T A R T   S Y M B O L
progSpecParser = Group(Optional(buildSpecList.setParseAction(logBSL)) + tagDefList.setParseAction(logTags) + objectList)("progSpecParser")
libTagParser = Group(Optional(buildSpecList.setParseAction(logBSL)) + tagDefList.setParseAction(logTags) + (modelTypes|Keyword("do")|Keyword("#define")|StringEnd()))("libTagParser")

# # # # # # # # # # # # #   E x t r a c t   P a r s e   R e s u l t s   # # # # # # # # # # # # #
def parseInput(inputStr):
    cdlog(2, "Parsing build-specs...")
    progSpec.saveTextToErrFile(inputStr)
    try:
        localResults = progSpecParser.parseString(inputStr, parseAll=True)
    except ParseBaseException as pe:
        cdErr( "While parsing: {}".format( pe))
    return localResults

autoClassNameIdx = 1
def extractTagDefs(tagResults):
    global autoClassNameIdx
    localTagStore = {}

    for tagSpec in tagResults:
        tagVal = tagSpec.tagValue[0]
        if ((not isinstance(tagVal, str)) and len(tagVal)>=2):
            if(tagVal.tagListContents): #tagVal is tagList
                tagValues=[]
                for each in tagVal.tagListContents:
                    tagValues.append(each.tagValue[0])
            elif(tagVal.tagDefList):   #tagVal is tagMap
                tagValues=extractTagDefs(tagVal.tagDefList)

# 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 *

fieldDef.setParseAction(logFieldDef)

#########################################   P A R S E R   S T A R T   S Y M B O L
progSpecParser = Group(Optional(buildSpecList.setParseAction(logBSL)) + tagDefList.setParseAction(logTags) + objectList)("progSpecParser")
libTagParser = Group(Optional(buildSpecList.setParseAction(logBSL)) + tagDefList.setParseAction(logTags) + (modelTypes|Keyword("do")|Keyword("#define")|StringEnd()))("libTagParser")

# # # # # # # # # # # # #   E x t r a c t   P a r s e   R e s u l t s   # # # # # # # # # # # # #
def parseInput(inputStr):
    cdlog(2, "Parsing build-specs...")
    progSpec.saveTextToErrFile(inputStr)
    try:
        localResults = progSpecParser.parseString(inputStr, parseAll=True)
    except ParseBaseException as pe:
        cdErr( "While parsing: {}".format( pe))
    return localResults

autoClassNameIdx = 1
def extractTagDefs(tagResults):
    global autoClassNameIdx
    localTagStore = {}

    for tagSpec in tagResults:
        tagVal = tagSpec.tagValue[0]
        if ((not isinstance(tagVal, str)) and len(tagVal)>=2):
            if(tagVal.tagListContents): #tagVal is tagList
                tagValues=[]
                for each in tagVal.tagListContents:
                    tagValues.append(each.tagValue[0])
            elif(tagVal.tagDefList):   #tagVal is tagMap
                tagValues=extractTagDefs(tagVal.tagDefList)

            elif("tagType" in tagVal):