def generateMainFunctionality(classes, tags): # TODO: Some deInitialize items should automatically run during abort(). # TODO: System initCode should happen first in initialize, last in deinitialize. runCode = progSpec.fetchTagValue(tags, 'runCode') Platform = progSpec.fetchTagValue(tags, 'Platform') if Platform != 'Android': mainFuncCode = """ me void: main( ) <- { initialize(String.join(" ", args)) """ + runCode + """ deinitialize() endFunc() } """ if Platform == 'Android': mainFuncCode = """ me void: runDogCode() <- { """ + runCode + """ } """ progSpec.addObject(classes[0], classes[1], 'GLOBAL', 'struct', 'SEQ') codeDogParser.AddToObjectFromText( classes[0], classes[1], progSpec.wrapFieldListInObjectDef('GLOBAL', mainFuncCode), 'Java start-up code')
def CreateStructsForStringModels(classes, newClasses, tags): # Define fieldResult struct #~ structsName = 'fetchResult' #~ StructFieldStr = "mode [fetchOK, fetchNotReady, fetchSyntaxError, FetchIO_Error] : FetchResult" #~ progSpec.addObject(classes[0], classes[1], structsName, 'struct', 'SEQ') #~ codeDogParser.AddToObjectFromText(classes[0], classes[1], progSpec.wrapFieldListInObjectDef(structsName, StructFieldStr)) if len(newClasses)==0: return populateBaseRules() global extracterFunctionAccumulator extracterFunctionAccumulator="" global nextParseNameID nextParseNameID=0 numStringStructs=0 for className in newClasses: if className[0] == '!': continue ObjectDef = classes[0][className] if(ObjectDef['stateType'] == 'string'): className=className[1:] cdlog(1, " Writing parse system for "+className) numStringStructs+=1 fields = ObjectDef["fields"] configType= ObjectDef['configType'] classTags = ObjectDef['tags'] if 'StartSymbol' in classTags: writeParserWrapperFunction(classes, className) SeqOrAlt='' if configType=='SEQ': SeqOrAlt='parseSEQ' # seq has {} elif configType=='ALT': SeqOrAlt='parseALT' # alt has [] normedObjectName = className.replace('::', '_') if normedObjectName==className: normedObjectName+='_str' # Write the rules for all the fields, and a parent rule which is either SEQ or ALT, and REP/OPT as needed. cdlog(2, "CODING Parser Rules for {}".format(normedObjectName)) ruleID = writeNonTermParseRule(classes, tags, normedObjectName, fields, SeqOrAlt, '', 3) if SeqOrAlt=='parseSEQ': [memObj, memVersionName]=fetchMemVersion(classes, className) if memObj!=None: Write_Extracter(classes, className, className, 2) else: cdlog(2, "NOTE: Skipping {} because it has no struct version defined.".format(className)) if numStringStructs==0: return ExtracterCode = extracterFunctionAccumulator ############ Add struct parser parserCode=genParserCode() codeDogParser.AddToObjectFromText(classes[0], classes[1], parserCode, 'Parser for '+className) structsName='EParser' progSpec.addObject(classes[0], classes[1], structsName, 'struct', 'SEQ') codeDogParser.AddToObjectFromText(classes[0], classes[1], progSpec.wrapFieldListInObjectDef(structsName, ExtracterCode), 'class '+structsName)
def generateMainFunctionality(classes, tags): # TODO: Make initCode, runCode and deInitCode work better and more automated by patterns. # TODO: Some deInitialize items should automatically run during abort(). # TODO: Deinitialize items should happen in reverse order. runCode = progSpec.fetchTagValue(tags, 'runCode') mainFuncCode=""" me void: main() <- { //initialize() """ + runCode + """ //deinitialize() } """ progSpec.addObject(classes[0], classes[1], 'GLOBAL', 'struct', 'SEQ') codeDogParser.AddToObjectFromText(classes[0], classes[1], progSpec.wrapFieldListInObjectDef('GLOBAL', mainFuncCode ), 'Swift start-up code')
def extractObjectSpecs(ProgSpec, classNames, spec, stateType): className=spec.objectName[0] configType="unknown" if(spec.sequenceEl): configType="SEQ" elif(spec.alternateEl):configType="ALT" ###########Grab optional Object Tags if 'tagDefList' in spec: #change so it generates an empty one if no field defs #print "spec.tagDefList = ",spec.tagDefList objTags = extractTagDefs(spec.tagDefList) else: objTags = {} taggedName = progSpec.addObject(ProgSpec, classNames, className, stateType, configType) progSpec.addObjTags(ProgSpec, className, stateType, objTags) extractFieldDefs(ProgSpec, className, stateType, spec.fieldDefs) return taggedName
def extractObjectSpecs(ProgSpec, classNames, spec, stateType, description): className = spec.classDef[0] configType = "unknown" if (spec.sequenceEl): configType = "SEQ" elif (spec.alternateEl): configType = "ALT" ###########Grab optional Object Tags if 'tagDefList' in spec: #change so it generates an empty one if no field defs #print("spec.tagDefList = ",spec.tagDefList) objTags = extractTagDefs(spec.tagDefList) else: objTags = {} taggedName = progSpec.addObject(ProgSpec, classNames, className, stateType, configType, description) progSpec.addObjTags(ProgSpec, className, stateType, objTags) extractFieldDefs(ProgSpec, className, stateType, spec.fieldDefs) ############Grab optional typeArgList if 'typeArgList' in spec[1]: typeArgList = extractTypeArgList(spec[1].typeArgList) progSpec.addTypeArgList(className, typeArgList) return taggedName