# 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 *
                    #print("   SUBS:", arg, ', ', params[idx], ', ', thisMacro)
                    replacement=params[idx]
                    if thisMacro=='BlowPOP':
                        replacement=BlowPOPMacro(replacement)
                    elif thisMacro=='DESLASH':
                        replacement=deSlashMacro(replacement)
                    newText=newText.replace(arg, replacement)
                    idx+=1
                #print("     NEW TEXT:", newText)
                newString += inputString[currentPos:match.start()+len(match.group(1))]+ newText
                currentPos=EndPos
                subsWereMade=True
            newString+=inputString[currentPos:]
            inputString=newString
    #print("     RETURN STRING:[", inputString, ']')
    # Last, replace the text into inputString
    return inputString

def extractObjectsOrPatterns(ProgSpec, clsNames, macroDefs, objectSpecResults,description):
    newClasses=[]
    for spec in objectSpecResults:
        s=spec[0]
        if s == "model" or s == "struct" or s == "string" or s == "stream":
            newName=extractObjectSpecs(ProgSpec, clsNames, spec, s,description)
            if newName!=None: newClasses.append(newName)
        elif s == "do":
            extractPatternSpecs(ProgSpec, clsNames, spec)
        elif s == "#define":
            extractMacroSpec(macroDefs, spec)
        else:

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

                    #print("   SUBS:", arg, ', ', params[idx], ', ', thisMacro)
                    replacement=params[idx]
                    if thisMacro=='BlowPOP':
                        replacement=BlowPOPMacro(replacement)
                    elif thisMacro=='DESLASH':
                        replacement=deSlashMacro(replacement)
                    newText=newText.replace(arg, replacement)
                    idx+=1
                #print("     NEW TEXT:", newText)
                newString += inputString[currentPos:match.start()+len(match.group(1))]+ newText
                currentPos=EndPos
                subsWereMade=True
            newString+=inputString[currentPos:]
            inputString=newString
    #print("     RETURN STRING:[", inputString, ']')
    # Last, replace the text into inputString
    return inputString

def extractObjectsOrPatterns(ProgSpec, clsNames, macroDefs, objectSpecResults,description):
    newClasses=[]
    for spec in objectSpecResults:
        s=spec[0]
        if s == "model" or s == "struct" or s == "string" or s == "stream":
            newName=extractObjectSpecs(ProgSpec, clsNames, spec, s,description)
            if newName!=None: newClasses.append(newName)
        elif s == "do":
            extractPatternSpecs(ProgSpec, clsNames, spec)
        elif s == "#define":
            extractMacroSpec(macroDefs, spec)
        else:

            cdErr("Error in extractObjectsOrPatterns; expected 'object' or 'do' and got '{}'".format(spec[0]))