Пример #1
0
    def show_highlight(self, view):
        valid_regions = []
        show_highlight = view.settings().get(self.HIGHLIGHT_ENABLED_KEY, False)
        scope = view.settings().get(self.SCOPE_SETTINGS_KEY,
                                    self.DEFAULT_SCOPE)
        icon = view.settings().get(self.ICON_SETTINGS_KEY, self.DEFAULT_ICON)

        if view.name() != 'Find Results':
            return

        for s in view.sel():
            line = view.line(s)
            line_str = view.substr(view.line(s))
            line_num = util.parse_line_number(line_str)

            if util.is_file_path(line_str) or line_num:
                valid_regions.append(line)

        if valid_regions:
            if show_highlight:
                options = sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED
            else:
                options = sublime.HIDDEN

            view.add_regions(self.HIGHLIGHT_REGION_NAME, valid_regions, scope,
                             icon, options)
        else:
            view.erase_regions(self.HIGHLIGHT_REGION_NAME)
Пример #2
0
def rebuild_line_dict():
    """ Preparse to build line number dictionary. """
    state.basic_state.line_numbers, offsets = {}, []
    state.basic_state.bytecode.seek(0)
    scanline, scanpos, last = 0, 0, 0
    while True:
        state.basic_state.bytecode.read(1)  # pass \x00
        scanline = util.parse_line_number(state.basic_state.bytecode)
        if scanline == -1:
            scanline = 65536
            # if parse_line_number returns -1, it leaves the stream pointer here: 00 _00_ 00 1A
            break
        state.basic_state.line_numbers[scanline] = scanpos
        last = scanpos
        util.skip_to(state.basic_state.bytecode, tk.end_line)
        scanpos = state.basic_state.bytecode.tell()
        offsets.append(scanpos)
    state.basic_state.line_numbers[65536] = scanpos
    # rebuild offsets
    state.basic_state.bytecode.seek(0)
    last = 0
    for pos in offsets:
        state.basic_state.bytecode.read(1)
        state.basic_state.bytecode.write(
            str(vartypes.value_to_uint(program_memory_start + pos)))
        state.basic_state.bytecode.read(pos - last - 3)
        last = pos
    # ensure program is properly sealed - last offset must be 00 00. keep, but ignore, anything after.
    state.basic_state.bytecode.write('\0\0\0')
Пример #3
0
def store_line(linebuf):
    """ Store the given line buffer. """
    if state.basic_state.protected:
        raise error.RunError(error.IFC)
    # get the new line number
    linebuf.seek(1)
    scanline = util.parse_line_number(linebuf)
    # check if linebuf is an empty line after the line number
    empty = (util.skip_white_read(linebuf) in tk.end_line)
    pos, afterpos, deleteable, beyond = find_pos_line_dict(scanline, scanline)
    if empty and not deleteable:
        raise error.RunError(error.UNDEFINED_LINE_NUMBER)
    # read the remainder of the program into a buffer to be pasted back after the write
    state.basic_state.bytecode.seek(afterpos)
    rest = state.basic_state.bytecode.read()
    # insert
    state.basic_state.bytecode.seek(pos)
    # write the line buffer to the program buffer
    length = 0
    if not empty:
        # set offsets
        linebuf.seek(3) # pass \x00\xC0\xDE
        length = len(linebuf.getvalue())
        state.basic_state.bytecode.write( '\0' + str(vartypes.integer_to_bytes(vartypes.int_to_integer_unsigned(program_memory_start + pos + length))) + linebuf.read())
    # write back the remainder of the program
    truncate_program(rest)
    # update all next offsets by shifting them by the length of the added line
    update_line_dict(pos, afterpos, length, deleteable, beyond)
    if not empty:
        state.basic_state.line_numbers[scanline] = pos
    # clear all program stacks
    flow.init_program()
    state.basic_state.last_stored = scanline
    def show_highlight(self, view):
        valid_regions = []
        show_highlight = view.settings().get(OpenSearchResultKeys.HIGHLIGHT_ENABLED, False)
        scope = view.settings().get(OpenSearchResultKeys.SCOPE_SETTINGS, self.DEFAULT_SCOPE)
        icon = view.settings().get(OpenSearchResultKeys.ICON_SETTINGS, self.DEFAULT_ICON)
        open_everywhere = view.settings().get(OpenSearchResultKeys.OPEN_EVERYWHERE, False)

        if open_everywhere == False and view.name() != 'Find Results':
            return

        for s in view.sel():
            line = view.line(s)
            line_str = view.substr(view.line(s))
            line_num = parse_line_number(line_str)

            if is_file_path(line_str) or line_num:
                valid_regions.append(line)

        if valid_regions:
            if show_highlight:
                options = sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED
            else:
                options = sublime.HIDDEN

            view.add_regions(
                self.HIGHLIGHT_REGION_NAME, valid_regions, scope, icon, options)
        else:
            view.erase_regions(self.HIGHLIGHT_REGION_NAME)
Пример #5
0
def rebuild_line_dict():
    """ Preparse to build line number dictionary. """
    state.basic_state.line_numbers, offsets = {}, []
    state.basic_state.bytecode.seek(0)
    scanline, scanpos, last = 0, 0, 0
    while True:
        state.basic_state.bytecode.read(1) # pass \x00
        scanline = util.parse_line_number(state.basic_state.bytecode)
        if scanline == -1:
            scanline = 65536
            # if parse_line_number returns -1, it leaves the stream pointer here: 00 _00_ 00 1A
            break
        state.basic_state.line_numbers[scanline] = scanpos
        last = scanpos
        util.skip_to(state.basic_state.bytecode, tk.end_line)
        scanpos = state.basic_state.bytecode.tell()
        offsets.append(scanpos)
    state.basic_state.line_numbers[65536] = scanpos
    # rebuild offsets
    state.basic_state.bytecode.seek(0)
    last = 0
    for pos in offsets:
        state.basic_state.bytecode.read(1)
        state.basic_state.bytecode.write(str(vartypes.integer_to_bytes(vartypes.int_to_integer_unsigned(program_memory_start + pos))))
        state.basic_state.bytecode.read(pos - last - 3)
        last = pos
    # ensure program is properly sealed - last offset must be 00 00. keep, but ignore, anything after.
    state.basic_state.bytecode.write('\0\0\0')
Пример #6
0
    def show_highlight(self, view):
        valid_regions = []
        show_highlight = view.settings().get(
            OpenSearchResultKeys.HIGHLIGHT_ENABLED, False)
        scope = view.settings().get(OpenSearchResultKeys.SCOPE_SETTINGS,
                                    self.DEFAULT_SCOPE)
        icon = view.settings().get(OpenSearchResultKeys.ICON_SETTINGS,
                                   self.DEFAULT_ICON)
        open_everywhere = view.settings().get(
            OpenSearchResultKeys.OPEN_EVERYWHERE, False)

        if open_everywhere == False and view.name() != 'Find Results':
            return

        for s in view.sel():
            line = view.line(s)
            line_str = view.substr(view.line(s))
            line_num = parse_line_number(line_str)

            if is_file_path(line_str) or line_num:
                valid_regions.append(line)

        if valid_regions:
            if show_highlight:
                options = sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED
            else:
                options = sublime.HIDDEN

            view.add_regions(self.HIGHLIGHT_REGION_NAME, valid_regions, scope,
                             icon, options)
        else:
            view.erase_regions(self.HIGHLIGHT_REGION_NAME)
    def show_highlight(self, view):
        valid_regions = []
        show_highlight = view.settings().get(self.HIGHLIGHT_ENABLED_KEY, False)
        scope = view.settings().get(self.SCOPE_SETTINGS_KEY, self.DEFAULT_SCOPE)
        icon = view.settings().get(self.ICON_SETTINGS_KEY, self.DEFAULT_ICON)

        if view.name() != 'Find Results':
            return

        for s in view.sel():
            line = view.line(s)
            line_str = view.substr(view.line(s))
            line_num = util.parse_line_number(line_str)

            if util.is_file_path(line_str) or line_num:
                valid_regions.append(line)

        if valid_regions:
            if show_highlight:
                options = sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED
            else:
                options = sublime.HIDDEN

            view.add_regions(
                self.HIGHLIGHT_REGION_NAME, valid_regions, scope, icon, options)
        else:
            view.erase_regions(self.HIGHLIGHT_REGION_NAME)
Пример #8
0
def detokenise_line(ins, bytepos=None):
    """ Convert a tokenised program line to ascii text. """
    litstring, comment = False, False
    textpos = 0
    current_line = util.parse_line_number(ins)
    if current_line < 0:
        # parse_line_number has returned -1 and left us at: .. 00 | _00_ 00 1A
        # stream ends or end of file sequence \x00\x00\x1A
        return -1, '', 0
    elif current_line == 0 and util.peek(ins) == ' ':
        # ignore up to one space after line number 0
        ins.read(1)
    output = bytearray(str(current_line))
    # write one extra whitespace character after line number
    # unless first char is TAB
    if util.peek(ins) != '\t':
        output += bytearray(' ')
    # detokenise tokens until end of line
    while True:
        s = ins.read(1)
        if not textpos and ins.tell() >= bytepos:
            textpos = len(output)
        if s in tk.end_line:
            # \x00 ends lines and comments when listed,
            # if not inside a number constant
            # stream ended or end of line
            break
        elif s == '"':
            # start of literal string, passed verbatim
            # until a closing quote or EOL comes by
            # however number codes are *printed* as the corresponding numbers,
            # even inside comments & literals
            output += s
            litstring = not litstring
        elif s in tk.number:
            ins.seek(-1, 1)
            representation.detokenise_number(ins, output)
        elif s in tk.linenum:
            # 0D: line pointer (unsigned int) - this token should not be here;
            #     interpret as line number and carry on
            # 0E: line number (unsigned int)
            output += representation.uint_to_str(bytearray(ins.read(2)))
        elif comment or litstring or ('\x20' <= s <= '\x7E'):
            # honest ASCII
            output += s
        elif s == '\x0A':
            # LF becomes LF CR
            output += '\x0A\x0D'
        elif s <= '\x09':
            # controls that do not double as tokens
            output += s
        else:
            ins.seek(-1, 1)
            comment = detokenise_keyword(ins, output)
    return current_line, output, textpos
Пример #9
0
def check_number_start(linebuf):
    """ Check if the given line buffer starts with a line number. """
    # get the new line number
    linebuf.seek(1)
    scanline = util.parse_line_number(linebuf)
    c = util.skip_white_read(linebuf)
    # check if linebuf is an empty line after the line number
    empty = (c in tk.end_line)
    # check if we start with a number
    if c in tk.number:
        raise error.RunError(error.STX)
    return empty, scanline
Пример #10
0
def check_number_start(linebuf):
    """ Check if the given line buffer starts with a line number. """
    # get the new line number
    linebuf.seek(1)
    scanline = util.parse_line_number(linebuf)
    c = util.skip_white_read(linebuf)
    # check if linebuf is an empty line after the line number
    empty = (c in tk.end_line)
    # check if we start with a number
    if c in tk.number:
        raise error.RunError(error.STX)
    return empty, scanline
Пример #11
0
    def run(self, edit):
        for cursor in self.view.sel():
            cur_line = self.view.line(cursor)
            line_str = self.view.substr(cur_line).strip()
            line_num = util.parse_line_number(line_str)

            if self.view.name() != 'Find Results':
                return

            if util.is_file_path(line_str):
                self.open_file_path(line_str)
            elif line_num:
                self.open_file_at_line_num(cur_line, line_num)
    def run(self, edit):
        for cursor in self.view.sel():
            cur_line = self.view.line(cursor)
            line_str = self.view.substr(cur_line).strip()
            line_num = util.parse_line_number(line_str)

            if self.view.name() != 'Find Results':
                return

            if util.is_file_path(line_str):
                self.open_file_path(line_str)
            elif line_num:
                self.open_file_at_line_num(cur_line, line_num)
    def run(self, edit):
        open_everywhere = self.view.settings().get(OpenSearchResultKeys.OPEN_EVERYWHERE, False)
        for cursor in self.view.sel():
            cur_line = self.view.line(cursor)
            line_str = self.view.substr(cur_line).strip()
            line_num = parse_line_number(line_str)

            if open_everywhere == False and self.view.name() != 'Find Results':
                return

            if is_file_path(line_str):
                self.open_file_path(line_str)
            elif line_num:
                self.open_file_at_line_num(cur_line, line_num)
Пример #14
0
    def run(self, edit):
        open_everywhere = self.view.settings().get(
            OpenSearchResultKeys.OPEN_EVERYWHERE, False)
        for cursor in self.view.sel():
            cur_line = self.view.line(cursor)
            line_str = self.view.substr(cur_line).strip()
            line_num = parse_line_number(line_str)

            if open_everywhere == False and self.view.name() != 'Find Results':
                return

            if is_file_path(line_str):
                self.open_file_path(line_str)
            elif line_num:
                self.open_file_at_line_num(cur_line, line_num)
Пример #15
0
def detokenise_line(ins, bytepos=None):
    """ Convert a tokenised program line to ascii text. """
    current_line = util.parse_line_number(ins)
    if current_line < 0:
        # parse_line_number has returned -1 and left us at: .. 00 | _00_ 00 1A
        # stream ends or end of file sequence \x00\x00\x1A
        return -1, '', 0
    elif current_line == 0 and util.peek(ins) == ' ':
        # ignore up to one space after line number 0
        ins.read(1)
    linum = bytearray(str(current_line))
    # write one extra whitespace character after line number
    # unless first char is TAB
    if util.peek(ins) != '\t':
        linum += bytearray(' ')
    line, textpos = detokenise_compound_statement(ins, bytepos)
    return current_line, linum + line, textpos + len(linum) + 1
Пример #16
0
def detokenise_line(ins, bytepos=None):
    """ Convert a tokenised program line to ascii text. """
    current_line = util.parse_line_number(ins)
    if current_line < 0:
        # parse_line_number has returned -1 and left us at: .. 00 | _00_ 00 1A
        # stream ends or end of file sequence \x00\x00\x1A
        return -1, '', 0
    elif current_line == 0 and util.peek(ins) == ' ':
        # ignore up to one space after line number 0
        ins.read(1)
    linum = bytearray(str(current_line))
    # write one extra whitespace character after line number
    # unless first char is TAB
    if util.peek(ins) != '\t':
        linum += bytearray(' ')
    line, textpos = detokenise_compound_statement(ins, bytepos)
    return current_line, linum + line, textpos + len(linum) + 1
Пример #17
0
def detokenise_line(ins, bytepos=None):
    """ Convert a tokenised program line to ascii text. """
    litstring, comment = False, False
    textpos = 0
    current_line = util.parse_line_number(ins)
    if current_line < 0:
        # parse_line_number has returned -1 and left us at: .. 00 | _00_ 00 1A
        # stream ends or end of file sequence \x00\x00\x1A
        return -1, '', 0
    elif current_line == 0 and util.peek(ins) == ' ':
        # ignore up to one space after line number 0
        ins.read(1)
    # write one extra whitespace character after line number
    output = str(current_line) + bytearray(' ')
    # detokenise tokens until end of line
    while True:
        s = ins.read(1)
        if not textpos and ins.tell() >= bytepos:
            textpos = len(output)
        if s in tk.end_line:
            # \x00 ends lines and comments when listed,
            # if not inside a number constant
            # stream ended or end of line
            break
        elif s == '"':
            # start of literal string, passed verbatim
            # until a closing quote or EOL comes by
            # however number codes are *printed* as the corresponding numbers,
            # even inside comments & literals
            output += s
            litstring = not litstring
        elif s in tk.number:
            ins.seek(-1, 1)
            representation.detokenise_number(ins, output)
        elif s in tk.linenum:
            # 0D: line pointer (unsigned int) - this token should not be here;
            #     interpret as line number and carry on
            # 0E: line number (unsigned int)
            output += representation.uint_to_str(bytearray(ins.read(2)))
        elif comment or litstring or ('\x20' <= s <= '\x7e'):
            # honest ASCII
            output += s
        else:
            ins.seek(-1, 1)
            comment = detokenise_keyword(ins, output)
    return current_line, output, textpos
Пример #18
0
def store_line(linebuf):
    """ Store the given line buffer. """
    if state.basic_state.protected:
        raise error.RunError(error.IFC)
    # get the new line number
    linebuf.seek(1)
    scanline = util.parse_line_number(linebuf)
    # check if linebuf is an empty line after the line number
    empty = (util.skip_white_read(linebuf) in tk.end_line)
    pos, afterpos, deleteable, beyond = find_pos_line_dict(scanline, scanline)
    if empty and not deleteable:
        raise error.RunError(error.UNDEFINED_LINE_NUMBER)
    # read the remainder of the program into a buffer to be pasted back after the write
    state.basic_state.bytecode.seek(afterpos)
    rest = state.basic_state.bytecode.read()
    # insert
    state.basic_state.bytecode.seek(pos)
    # write the line buffer to the program buffer
    length = 0
    if not empty:
        # set offsets
        linebuf.seek(3)  # pass \x00\xC0\xDE
        length = len(linebuf.getvalue())
        state.basic_state.bytecode.write(
            '\0' +
            str(vartypes.value_to_uint(program_memory_start + pos + length)) +
            linebuf.read())
    # write back the remainder of the program
    truncate_program(rest)
    # update all next offsets by shifting them by the length of the added line
    update_line_dict(pos, afterpos, length, deleteable, beyond)
    if not empty:
        state.basic_state.line_numbers[scanline] = pos
    # clear all program stacks
    flow.init_program()
    state.basic_state.last_stored = scanline