To initialize, analyze the surroundings of the given index.
(self, editwin, index)
| 24 | |
| 25 | class HyperParser: |
| 26 | def __init__(self, editwin, index): |
| 27 | "To initialize, analyze the surroundings of the given index." |
| 28 | |
| 29 | self.editwin = editwin |
| 30 | self.text = text = editwin.text |
| 31 | |
| 32 | parser = pyparse.Parser(editwin.indentwidth, editwin.tabwidth) |
| 33 | |
| 34 | def index2line(index): |
| 35 | return int(float(index)) |
| 36 | lno = index2line(text.index(index)) |
| 37 | |
| 38 | if not editwin.prompt_last_line: |
| 39 | for context in editwin.num_context_lines: |
| 40 | startat = max(lno - context, 1) |
| 41 | startatindex = repr(startat) + ".0" |
| 42 | stopatindex = "%d.end" % lno |
| 43 | # We add the newline because PyParse requires a newline |
| 44 | # at end. We add a space so that index won't be at end |
| 45 | # of line, so that its status will be the same as the |
| 46 | # char before it, if should. |
| 47 | parser.set_code(text.get(startatindex, stopatindex)+' \n') |
| 48 | bod = parser.find_good_parse_start( |
| 49 | editwin._build_char_in_string_func(startatindex)) |
| 50 | if bod is not None or startat == 1: |
| 51 | break |
| 52 | parser.set_lo(bod or 0) |
| 53 | else: |
| 54 | r = text.tag_prevrange("console", index) |
| 55 | if r: |
| 56 | startatindex = r[1] |
| 57 | else: |
| 58 | startatindex = "1.0" |
| 59 | stopatindex = "%d.end" % lno |
| 60 | # We add the newline because PyParse requires it. We add a |
| 61 | # space so that index won't be at end of line, so that its |
| 62 | # status will be the same as the char before it, if should. |
| 63 | parser.set_code(text.get(startatindex, stopatindex)+' \n') |
| 64 | parser.set_lo(0) |
| 65 | |
| 66 | # We want what the parser has, minus the last newline and space. |
| 67 | self.rawtext = parser.code[:-2] |
| 68 | # Parser.code apparently preserves the statement we are in, so |
| 69 | # that stopatindex can be used to synchronize the string with |
| 70 | # the text box indices. |
| 71 | self.stopatindex = stopatindex |
| 72 | self.bracketing = parser.get_last_stmt_bracketing() |
| 73 | # find which pairs of bracketing are openers. These always |
| 74 | # correspond to a character of rawtext. |
| 75 | self.isopener = [i>0 and self.bracketing[i][1] > |
| 76 | self.bracketing[i-1][1] |
| 77 | for i in range(len(self.bracketing))] |
| 78 | |
| 79 | self.set_index(index) |
| 80 | |
| 81 | def set_index(self, index): |
| 82 | """Set the index to which the functions relate. |
nothing calls this directly
no test coverage detected