|
| 1 | +export = CodePathSegment; |
| 2 | +/** |
| 3 | + * A code path segment. |
| 4 | + * |
| 5 | + * Each segment is arranged in a series of linked lists (implemented by arrays) |
| 6 | + * that keep track of the previous and next segments in a code path. In this way, |
| 7 | + * you can navigate between all segments in any code path so long as you have a |
| 8 | + * reference to any segment in that code path. |
| 9 | + * |
| 10 | + * When first created, the segment is in a detached state, meaning that it knows the |
| 11 | + * segments that came before it but those segments don't know that this new segment |
| 12 | + * follows it. Only when `CodePathSegment#markUsed()` is called on a segment does it |
| 13 | + * officially become part of the code path by updating the previous segments to know |
| 14 | + * that this new segment follows. |
| 15 | + */ |
| 16 | +declare class CodePathSegment { |
| 17 | + /** |
| 18 | + * Creates the root segment. |
| 19 | + * @param {string} id An identifier. |
| 20 | + * @returns {CodePathSegment} The created segment. |
| 21 | + */ |
| 22 | + static newRoot(id: string): CodePathSegment; |
| 23 | + /** |
| 24 | + * Creates a new segment and appends it after the given segments. |
| 25 | + * @param {string} id An identifier. |
| 26 | + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments |
| 27 | + * to append to. |
| 28 | + * @returns {CodePathSegment} The created segment. |
| 29 | + */ |
| 30 | + static newNext(id: string, allPrevSegments: CodePathSegment[]): CodePathSegment; |
| 31 | + /** |
| 32 | + * Creates an unreachable segment and appends it after the given segments. |
| 33 | + * @param {string} id An identifier. |
| 34 | + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments. |
| 35 | + * @returns {CodePathSegment} The created segment. |
| 36 | + */ |
| 37 | + static newUnreachable(id: string, allPrevSegments: CodePathSegment[]): CodePathSegment; |
| 38 | + /** |
| 39 | + * Creates a segment that follows given segments. |
| 40 | + * This factory method does not connect with `allPrevSegments`. |
| 41 | + * But this inherits `reachable` flag. |
| 42 | + * @param {string} id An identifier. |
| 43 | + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments. |
| 44 | + * @returns {CodePathSegment} The created segment. |
| 45 | + */ |
| 46 | + static newDisconnected(id: string, allPrevSegments: CodePathSegment[]): CodePathSegment; |
| 47 | + /** |
| 48 | + * Marks a given segment as used. |
| 49 | + * |
| 50 | + * And this function registers the segment into the previous segments as a next. |
| 51 | + * @param {CodePathSegment} segment A segment to mark. |
| 52 | + * @returns {void} |
| 53 | + */ |
| 54 | + static markUsed(segment: CodePathSegment): void; |
| 55 | + /** |
| 56 | + * Marks a previous segment as looped. |
| 57 | + * @param {CodePathSegment} segment A segment. |
| 58 | + * @param {CodePathSegment} prevSegment A previous segment to mark. |
| 59 | + * @returns {void} |
| 60 | + */ |
| 61 | + static markPrevSegmentAsLooped(segment: CodePathSegment, prevSegment: CodePathSegment): void; |
| 62 | + /** |
| 63 | + * Creates a new array based on an array of segments. If any segment in the |
| 64 | + * array is unused, then it is replaced by all of its previous segments. |
| 65 | + * All used segments are returned as-is without replacement. |
| 66 | + * @param {CodePathSegment[]} segments The array of segments to flatten. |
| 67 | + * @returns {CodePathSegment[]} The flattened array. |
| 68 | + */ |
| 69 | + static flattenUnusedSegments(segments: CodePathSegment[]): CodePathSegment[]; |
| 70 | + /** |
| 71 | + * Creates a new instance. |
| 72 | + * @param {string} id An identifier. |
| 73 | + * @param {CodePathSegment[]} allPrevSegments An array of the previous segments. |
| 74 | + * This array includes unreachable segments. |
| 75 | + * @param {boolean} reachable A flag which shows this is reachable. |
| 76 | + */ |
| 77 | + constructor(id: string, allPrevSegments: CodePathSegment[], reachable: boolean); |
| 78 | + /** |
| 79 | + * The identifier of this code path. |
| 80 | + * Rules use it to store additional information of each rule. |
| 81 | + * @type {string} |
| 82 | + */ |
| 83 | + id: string; |
| 84 | + /** |
| 85 | + * An array of the next reachable segments. |
| 86 | + * @type {CodePathSegment[]} |
| 87 | + */ |
| 88 | + nextSegments: CodePathSegment[]; |
| 89 | + /** |
| 90 | + * An array of the previous reachable segments. |
| 91 | + * @type {CodePathSegment[]} |
| 92 | + */ |
| 93 | + prevSegments: CodePathSegment[]; |
| 94 | + /** |
| 95 | + * An array of all next segments including reachable and unreachable. |
| 96 | + * @type {CodePathSegment[]} |
| 97 | + */ |
| 98 | + allNextSegments: CodePathSegment[]; |
| 99 | + /** |
| 100 | + * An array of all previous segments including reachable and unreachable. |
| 101 | + * @type {CodePathSegment[]} |
| 102 | + */ |
| 103 | + allPrevSegments: CodePathSegment[]; |
| 104 | + /** |
| 105 | + * A flag which shows this is reachable. |
| 106 | + * @type {boolean} |
| 107 | + */ |
| 108 | + reachable: boolean; |
| 109 | + /** |
| 110 | + * Checks a given previous segment is coming from the end of a loop. |
| 111 | + * @param {CodePathSegment} segment A previous segment to check. |
| 112 | + * @returns {boolean} `true` if the segment is coming from the end of a loop. |
| 113 | + */ |
| 114 | + isLoopedPrevSegment(segment: CodePathSegment): boolean; |
| 115 | +} |
0 commit comments