⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 highlight.py

📁 一段进行语法分析、语法加亮的程序。目前仅进行了语法分析
💻 PY
📖 第 1 页 / 共 2 页
字号:
            #single_maps[x[0][0]][x[0][1:2]][x[0]]=x
            single_maps[x[0][0]][x[0]]=x

        
    while(curpos < len(aimstr) ):
        #print "curpos = " + str(curpos)
        Matched = False
        ## try to find the block obj
        for x in block_signs:
            if aimstr[curpos:curpos+len(x[0])]==x[0] :
                if isinstance(x[1],type('') )  :
                    endpos = aimstr.find(x[1],curpos+len(x[0]) )
                    if endpos  < 0:
                        endpos = len(aimstr)
                else:
                    mch=x[1].match( aimstr, curpos+len(x[0]))
                    if mch  :
                        endpos = mch.end()
                    else:
                        endpos = len(aimstr)
                x[2](aimstr[curpos:endpos])
                curpos= endpos
                Matched= True
                break
        
        ## try to find the single obj       
        if not Matched :
            maxlen=0
            maxmatch=None
            # Method 1
            #if ( aimstr[curpos:curpos+1] in identified_header  ):
            #    le=identified_sign[0].match(aimstr,curpos ).end()-curpos
            #maxmatch=findmatch(aimstr, curpos, single_signs , True, le )
            #if (  maxmatch ):
            #    maxlen= len(maxmatch[0])
            #
            
            # include Method2 as Methdo3
            a0=aimstr[curpos:curpos+1]
            if single_maps.has_key(a0):
                mlist=single_maps[a0].values()
                single_signs=mlist
            
                # Method 2    
                for x in single_signs:
                   # this can be mo effectivly by search the single signs with 1/2 mehtod
                    if len(x[0])>maxlen and x[0].lower()==aimstr[curpos:curpos+len(x[0]) ].lower() :
                        if ( aimstr[curpos:curpos+1] in identified_header  and aimstr[curpos+len(x[0]):curpos+len(x[0])+1] in identified ):
                            continue
                        maxlen=len(x[0])
                        maxmatch=x
            for x in reg_signs:
                matchobj=x[0].match(aimstr, curpos)
                if matchobj and matchobj.end()-curpos > maxlen :
                    maxlen= matchobj.end()-curpos
                    maxmatch=x

            if maxlen > 0 :
                maxmatch[1](aimstr[curpos:curpos+maxlen])
                curpos = curpos+maxlen
                Matched = True
                continue
        
        ## try to find next obj
        if not Matched :
            mch=identified_sign[0].match(aimstr,curpos ) or blank_sign[0].match(aimstr,curpos)
            if mch :
                #assert mch.end() > curpos
                DEFAULT_ACTION(aimstr[curpos:mch.end()])
                curpos=mch.end()
            else :
                DEFAULT_ACTION(aimstr[curpos:curpos+1])
                curpos=curpos+1

                
if __name__=="__main__":
    fp=file(__file__)
    m=''
    for x in fp.readlines():
        m=m+x
    print len(m)
    HightLightString(m)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -