Skip to content

Commit d604cf6

Browse files
committed
Now not escaping forward slash and fixed lexing strings
1 parent 89c9119 commit d604cf6

File tree

4 files changed

+324
-213
lines changed

4 files changed

+324
-213
lines changed

src/kdl/lexer.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ proc tokenStringBody(lexer: var Lexer, raw = false) =
360360
continue
361361
362362
let next = lexer.peek(1)
363-
if next notin escapeTable or next != 'u':
363+
if next != 'u' and next notin escapeTable:
364364
lexer.error &"Invalid escape '{next}'"
365365
366366
lexer.inc 2

src/kdl/utils.nim

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,20 @@ template check*(cond: untyped, msg = "") =
3636
fail astToStr(cond) & " failed" & (if txt.len > 0: ": " & txt else: "")
3737

3838
proc quoted*(x: string): string =
39+
result.add '"'
3940
var i = 0
4041
while i < x.len:
42+
var isEscape = false
4143
for k, v in escapeTable:
42-
if x.continuesWith(v, i):
44+
# Don't escape forward slash
45+
if k != '/' and x.continuesWith(v, i):
4346
result.add &"\\{k}"
4447
i.inc v.len
45-
else:
46-
result.add x[i]
47-
i.inc
48+
isEscape = true
49+
if not isEscape:
50+
result.add x[i]
51+
i.inc
52+
result.add '"'
4853

4954
proc cmpIgnoreStyle(a, b: openarray[char], ignoreChars = {'_', '-'}): int =
5055
let aLen = a.len

0 commit comments

Comments
 (0)