diff options
-rw-r--r-- | compiler/lexer.nim | 24 | ||||
-rw-r--r-- | compiler/rodimpl.nim | 2 | ||||
-rw-r--r-- | nimpretty/tests/exhaustive.nim | 2 | ||||
-rw-r--r-- | nimpretty/tests/expected/exhaustive.nim | 2 |
4 files changed, 19 insertions, 11 deletions
diff --git a/compiler/lexer.nim b/compiler/lexer.nim index 4cb800017..d9051bd7f 100644 --- a/compiler/lexer.nim +++ b/compiler/lexer.nim @@ -740,11 +740,17 @@ proc handleCRLF(L: var TLexer, pos: int): int = result = nimlexbase.handleLF(L, pos) else: result = pos -proc getString(L: var TLexer, tok: var TToken, rawMode: bool) = +type + StringMode = enum + normal, + raw, + generalized + +proc getString(L: var TLexer, tok: var TToken, mode: StringMode) = var pos = L.bufpos var buf = L.buf # put `buf` in a register var line = L.lineNumber # save linenumber for better error message - tokenBegin(tok, pos) + tokenBegin(tok, pos - ord(mode == raw)) inc pos # skip " if buf[pos] == '\"' and buf[pos+1] == '\"': tok.tokType = tkTripleStrLit # long string literal: @@ -784,12 +790,12 @@ proc getString(L: var TLexer, tok: var TToken, rawMode: bool) = inc(pos) else: # ordinary string literal - if rawMode: tok.tokType = tkRStrLit + if mode != normal: tok.tokType = tkRStrLit else: tok.tokType = tkStrLit while true: var c = buf[pos] if c == '\"': - if rawMode and buf[pos+1] == '\"': + if mode != normal and buf[pos+1] == '\"': inc(pos, 2) add(tok.literal, '"') else: @@ -800,7 +806,7 @@ proc getString(L: var TLexer, tok: var TToken, rawMode: bool) = tokenEndIgnore(tok, pos) lexMessage(L, errGenerated, "closing \" expected") break - elif (c == '\\') and not rawMode: + elif (c == '\\') and mode == normal: L.bufpos = pos getEscapedChar(L, tok) pos = L.bufpos @@ -1168,7 +1174,7 @@ proc rawGetTok*(L: var TLexer, tok: var TToken) = of 'r', 'R': if L.buf[L.bufpos + 1] == '\"': inc(L.bufpos) - getString(L, tok, true) + getString(L, tok, raw) else: getSymbol(L, tok) of '(': @@ -1246,9 +1252,9 @@ proc rawGetTok*(L: var TLexer, tok: var TToken) = lexMessage(L, errGenerated, "invalid token: " & c & " (\\" & $(ord(c)) & ')') of '\"': # check for generalized raw string literal: - var rawMode = L.bufpos > 0 and L.buf[L.bufpos-1] in SymChars - getString(L, tok, rawMode) - if rawMode: + let mode = if L.bufpos > 0 and L.buf[L.bufpos-1] in SymChars: generalized else: normal + getString(L, tok, mode) + if mode == generalized: # tkRStrLit -> tkGStrLit # tkTripleStrLit -> tkGTripleStrLit inc(tok.tokType, 2) diff --git a/compiler/rodimpl.nim b/compiler/rodimpl.nim index 1a42ca137..420c5bf7f 100644 --- a/compiler/rodimpl.nim +++ b/compiler/rodimpl.nim @@ -853,12 +853,10 @@ proc loadNode*(g: ModuleGraph; module: PSym): PNode = result = newNodeI(nkStmtList, module.info) for row in db.rows(sql"select data from toplevelstmts where module = ? order by position asc", abs module.id): - var b = BlobReader(pos: 0) # ensure we can read without index checks: b.s = row[0] & '\0' result.add decodeNode(g, b, module.info) - db.exec(sql"insert into controlblock(idgen) values (?)", gFrontEndId) replay(g, module, result) diff --git a/nimpretty/tests/exhaustive.nim b/nimpretty/tests/exhaustive.nim index a2501a193..1b8007844 100644 --- a/nimpretty/tests/exhaustive.nim +++ b/nimpretty/tests/exhaustive.nim @@ -314,3 +314,5 @@ proc f() = if c == '\\': # escape char str &= c + +const test = r"C:\Users\-\Desktop\test.txt" diff --git a/nimpretty/tests/expected/exhaustive.nim b/nimpretty/tests/expected/exhaustive.nim index 95071fce3..bace61945 100644 --- a/nimpretty/tests/expected/exhaustive.nim +++ b/nimpretty/tests/expected/exhaustive.nim @@ -323,3 +323,5 @@ proc f() = if c == '\\': # escape char str &= c + +const test = r"C:\Users\-\Desktop\test.txt" |