<= [[opensource:codebricklayer:start|CodeBricklayer]] ====== Python Source====== {{template>:meta:template:pageinfo#tpl |desc=Python source code of CodeBricklayer.}} ===== Usage ===== * Describe a [[opensource:codebricklayer:blueprint|blueprint]] that tells the codeBricklayer how to code. * Run command python codeBricklayer.py -s blueprint -d dstfile. * ''-s'' specifies the blueprint. * ''-d'' specifies the destination file. If not specified, codeBricklayer will __output code to the current tty__. ===== Source ===== # Author: Siyuan Liu # Date : 3/22/2023 # Purpose: # Reduce coding time. ''' Change Log: 3/24/2023: - Support self-defined separator - Supports clearing the specified string if it does not match any module ''' import argparse import re # repa = re.compile(r'\s+') repa = re.compile(r'\n') re_cond = re.compile(r'\$<.+?>') class codeBricklayer: def __init__(self, blueprint, house): self.src = open(blueprint, 'r') self.brick = {} self.id = [] self.dst = None self.code_arch = '' if house is not None: self.dst = open(house, 'w+') def parseArch(self): while True: line = self.src.readline() if '...' in line: break while True: line = self.src.readline() if '...' not in line: self.code_arch += line else: break # print(self.code_arch) def bricklay(self): self.src.seek(0, 0) while True: line = self.src.readline() if '---' in line: break # Get the Specified separator line = self.src.readline() separator = line.strip() # print(separator) # Identifier of the brick line = self.src.readline() line = re.sub(repa, '', line) ids = line.split(separator) # print(ids) while True: line = self.src.readline() if '---' not in line: line = re.sub(repa, '', line) bricks = line.split(separator) num = len(bricks) # print(bricks) code = self.code_arch # process $<> cond_blk = re.findall(re_cond, code) # print(cond_blk) for blk in cond_blk: new_blk = blk matched = False for i in range(len(ids)): id = "${%s}" % (ids[i]) if id not in new_blk: continue if i