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


import re
import progSpec
import codeDogParser
from progSpec import cdlog, cdErr
        S+=Write_ALT_Extracter(classes, ToStructName, fields, 'SRec', '', 'tmpStr', '    ', -1, logLvl)

    seqExtracter =  "\n    void: "+nameForFunc+"(our stateRec: SRec0, their "+ToStructName+": memStruct, their EParser: EP) <- {\n" + S + "    }\n"
    extracterFunctionAccumulator += seqExtracter
    #print "########################## extracterFunctionAccumulator\n",extracterFunctionAccumulator,"\n#####################################\n"

def writeParserWrapperFunction(classes, className):
    S='''
struct EParser{
    me uint64: sourceID

    our <CLASSNAME>: Parse_<CLASSNAME>(me string: textIn) <- {
        our <CLASSNAME>: result
        initParseFromString("<CLASSNAME>", textIn)
        doParse()
        if (doesParseHaveError()) {
            print("Parse Error:" + errorMesg + "\\n")
        } else {
            our stateRec: topItem <- topDownResolve(lastTopLevelItem, "")
            Allocate(result)
            syntax.Extract_<CLASSNAME>_to_<CLASSNAME>(topItem, result, self)
        }
        return(result)
    }
}
struct <CLASSNAME>ExtracterThread: inherits=Threads{
    their Threaded_<CLASSNAME>ParseAndExtractor: ctrls
    our stateRec: parseTree
    our <CLASSNAME>: topItem


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


# Path: stringStructs.py
import re
import progSpec
import codeDogParser
from progSpec import cdlog, cdErr

        S+=Write_ALT_Extracter(classes, ToStructName, fields, 'SRec', '', 'tmpStr', '    ', -1, logLvl)

    seqExtracter =  "\n    void: "+nameForFunc+"(our stateRec: SRec0, their "+ToStructName+": memStruct, their EParser: EP) <- {\n" + S + "    }\n"
    extracterFunctionAccumulator += seqExtracter
    #print "########################## extracterFunctionAccumulator\n",extracterFunctionAccumulator,"\n#####################################\n"

def writeParserWrapperFunction(classes, className):
    S='''
struct EParser{
    me uint64: sourceID

    our <CLASSNAME>: Parse_<CLASSNAME>(me string: textIn) <- {
        our <CLASSNAME>: result
        initParseFromString("<CLASSNAME>", textIn)
        doParse()
        if (doesParseHaveError()) {
            print("Parse Error:" + errorMesg + "\\n")
        } else {
            our stateRec: topItem <- topDownResolve(lastTopLevelItem, "")
            Allocate(result)
            syntax.Extract_<CLASSNAME>_to_<CLASSNAME>(topItem, result, self)
        }
        return(result)
    }
}
struct <CLASSNAME>ExtracterThread: inherits=Threads{
    their Threaded_<CLASSNAME>ParseAndExtractor: ctrls
    our stateRec: parseTree
    our <CLASSNAME>: topItem


    void: init(their Threaded_<CLASSNAME>ParseAndExtractor: Ctrls, our stateRec: ParseTree, our <CLASSNAME>: TopItem) <- {