parser
A simple class to provide access to full extent of statements with starting and ending lines.
closest_after(tree, lineno)
Return the closest item strictly before lineno.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree |
IntervalTree
|
The intervals obtained from get_stmt_ranges function. |
required |
lineno |
int
|
The lineno to use in the file. |
required |
Returns:
Type | Description |
---|---|
Optional[Interval]
|
Optional[Interval]: An interval representing closest statement after the line if there is a statement after. |
Source code in mkreports/parser.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
closest_before(tree, lineno)
Return the closest item strictly before lineno.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree |
IntervalTree
|
The intervals obtained from get_stmt_ranges function. |
required |
lineno |
int
|
The lineno to use in the file. |
required |
Returns:
Type | Description |
---|---|
Optional[Interval]
|
Optional[Interval]: An interval representing closest statement before the line if there is a statement before. |
Source code in mkreports/parser.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
envelope(tree, pos)
Interval that covers the given interval (i.e. is larger).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree |
IntervalTree
|
The intervals obtained from get_stmt_ranges function. |
required |
pos |
Interval
|
Interval to cover. |
required |
Returns:
Type | Description |
---|---|
Optional[Interval]
|
Optional[Interval]: The next largest interval covering the current one, if there is one, otherwise None. |
Source code in mkreports/parser.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
get_neighbors(tree, lineno)
For a given lineno, get the current statement (if there is one), as well as the previous and next statements in the tree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree |
IntervalTree
|
required | |
lineno |
int
|
required |
Returns:
Type | Description |
---|---|
Optional[Interval], Optional[Interval], Optional[Interval]
|
Interval of statement before the line, covering the current line and the next statement. |
Source code in mkreports/parser.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
get_stmt_ranges(pyfile)
Parse the python file and return the ranges of all statements.
Here, we only return the range of the statements at the lowest level. This is to make it easier to find the 'previous' statement. The line numbers in the interval tree will be 1-based.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pyfile |
Path
|
Path to the python file to analyze. |
required |
Returns:
Name | Type | Description |
---|---|---|
IntervallTree |
IntervalTree
|
An object representing the hierarchical intervals of the statements in the file. |
Source code in mkreports/parser.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
smallest_overlap(tree, lineno)
Find the closest match that overlaps and is shortests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree |
IntervalTree
|
The intervals obtained from get_stmt_ranges function. |
required |
lineno |
int
|
The lineno to use in the file. |
required |
Returns:
Type | Description |
---|---|
Optional[Interval]
|
Optional[Interval]: An interval if there is a statement at the line. |
Source code in mkreports/parser.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|