|
11 | 11 |
|
12 | 12 | import |
13 | 13 | pathutils |
14 | | - |
| 14 | +import std/strutils |
15 | 15 | when defined(nimPreviewSlimSystem): |
16 | 16 | import std/syncio |
17 | 17 |
|
@@ -86,14 +86,46 @@ const |
86 | 86 | LineContinuationOprs = {'+', '-', '*', '/', '\\', '<', '>', '!', '?', '^', |
87 | 87 | '|', '%', '&', '$', '@', '~', ','} |
88 | 88 | AdditionalLineContinuationOprs = {'#', ':', '='} |
| 89 | + LineContinuationTokens = [ |
| 90 | + "let", "var", "const", "type", # section |
| 91 | + "object", "tuple", |
| 92 | + "and", "or", "xor", |
| 93 | + ] |
| 94 | + |
| 95 | +proc endsWith(s, subs: string, endIdx: var int): bool = |
| 96 | + endIdx.dec subs.len |
| 97 | + result = s.continuesWith(subs, endIdx+1) |
| 98 | + |
| 99 | +proc containsObjectOf(x: string): bool = |
| 100 | + const sep = ' ' |
| 101 | + var idx = x.rfind(sep) |
| 102 | + if idx == -1: return |
| 103 | + |
| 104 | + template eatWord(word) = |
| 105 | + while x[idx] == sep: idx.dec |
| 106 | + result = x.endsWith(word, idx) |
| 107 | + if not result: return |
| 108 | + |
| 109 | + eatWord "of" |
| 110 | + eatWord "object" |
| 111 | + result = true |
| 112 | + |
| 113 | +proc endsWithLineContinuationToken(x: string): bool = |
| 114 | + result = false |
| 115 | + for tok in LineContinuationTokens: |
| 116 | + if x.endsWith(tok): |
| 117 | + return true |
| 118 | + result = x.containsObjectOf |
89 | 119 |
|
90 | 120 | proc endsWithOpr*(x: string): bool = |
91 | 121 | result = x.endsWith(LineContinuationOprs) |
92 | 122 |
|
93 | 123 | proc continueLine(line: string, inTripleString: bool): bool {.inline.} = |
94 | 124 | result = inTripleString or line.len > 0 and ( |
95 | 125 | line[0] == ' ' or |
96 | | - line.endsWith(LineContinuationOprs+AdditionalLineContinuationOprs)) |
| 126 | + line.endsWith(LineContinuationOprs+AdditionalLineContinuationOprs) or |
| 127 | + line.endsWithLineContinuationToken() |
| 128 | + ) |
97 | 129 |
|
98 | 130 | proc countTriples(s: string): int = |
99 | 131 | result = 0 |
|
0 commit comments