Exemple #1
0
    def highlightAllDocument(self):
        block = self.document().begin()
        self.processor.startParsing(self.syntax.scopeName)
        stack = [[self.syntax.grammar, None]]
        while block.isValid():
            text = block.text()
            self.syntax.parseLine(stack, text, self.processor)
            userData = block.userData()
            if userData is None:
                userData = PMXBlockUserData()
                block.setUserData(userData)

            self.setupBlockUserData(text, block, userData)

            blockState = len(stack)
            if blockState != self.SINGLE_LINE:
                userData.setProcessorState(
                    (copy(stack), copy(self.processor.scopes())))
            userData.textHash = hash(text) + hash(
                self.syntax.scopeName) + blockState
            block.setUserState(blockState)

            self.rehighlightBlock(block)
            block = block.next()
            yield
        self.processor.endParsing(self.syntax.scopeName)
Exemple #2
0
    def realtime_highlight(self, text):
        userData = self.currentBlock().userData()
        if userData is not None and userData.textHash == hash(text) + hash(self.syntax.scopeName) + self.previousBlockState():
            self.applyFormat(userData)
        else:
            self.processor.startParsing(self.syntax.scopeName)
            if self.previousBlockState() == self.MULTI_LINE:
                #Recupero una copia del stack y los scopes del user data
                stack, scopes = self.currentBlock().previous().userData().processorState()
                #Set copy, not original
                stack = stack[:]
                self.processor.setScopes(scopes[:])
            else:
                #Creo un stack y scopes nuevos
                stack = [[self.syntax.grammar, None]]
    
            # A parserar mi amor, vamos a parsear mi amor
            self.syntax.parseLine(stack, text, self.processor)
            self.processor.endParsing(self.syntax.scopeName)
                        
            if userData is None:
                userData = PMXBlockUserData()
                self.setCurrentBlockUserData(userData)

            self.setupBlockUserData(text, self.currentBlock(), userData)
            
            blockState = self.SINGLE_LINE if len(stack) == 1 else self.MULTI_LINE
            if blockState == self.MULTI_LINE:
                userData.setProcessorState((copy(stack), copy(self.processor.scopes())))
            userData.textHash = hash(text) + hash(self.syntax.scopeName) + blockState
            
            self.setCurrentBlockState(blockState)
            self.applyFormat(userData)
Exemple #3
0
    def realtime_highlight(self, text):
        userData = self.currentBlock().userData()
        if userData is not None and userData.textHash == hash(text) + hash(
                self.syntax.scopeName) + self.previousBlockState():
            self.applyFormat(userData)
        else:
            self.processor.startParsing(self.syntax.scopeName)
            if self.previousBlockState() not in [
                    self.SINGLE_LINE, self.NO_STATE
            ]:
                #Recupero una copia del stack y los scopes del user data
                stack, scopes = self.currentBlock().previous().userData(
                ).processorState()
                #Set copy, not original
                stack = stack[:]
                self.processor.setScopes(scopes[:])
            else:
                #Creo un stack y scopes nuevos
                stack = [[self.syntax.grammar, None]]

            # A parserar mi amor, vamos a parsear mi amor
            self.syntax.parseLine(stack, text, self.processor)
            self.processor.endParsing(self.syntax.scopeName)

            if userData is None:
                userData = PMXBlockUserData()
                self.setCurrentBlockUserData(userData)

            self.setupBlockUserData(text, self.currentBlock(), userData)

            blockState = len(stack)

            if blockState != self.SINGLE_LINE:
                userData.setProcessorState(
                    (copy(stack), copy(self.processor.scopes())))
            userData.textHash = hash(text) + hash(
                self.syntax.scopeName) + blockState

            self.setCurrentBlockState(blockState)
            self.applyFormat(userData)
    def highlightAllDocument(self):
        block = self.document().begin()
        self.processor.startParsing(self.syntax.scopeName)
        stack = [[self.syntax.grammar, None]]
        while block.isValid():
            text = block.text()
            self.syntax.parseLine(stack, text, self.processor)
            userData = block.userData()
            if userData is None:
                userData = PMXBlockUserData()
                block.setUserData(userData)

            self.setupBlockUserData(text, block, userData)

            blockState = len(stack)
            if blockState != self.SINGLE_LINE:
                userData.setProcessorState((copy(stack), copy(self.processor.scopes())))
            userData.textHash = hash(text) + hash(self.syntax.scopeName) + blockState
            block.setUserState(blockState)

            self.rehighlightBlock(block)
            block = block.next()
            yield
        self.processor.endParsing(self.syntax.scopeName)