Skip to content

Commit 80caca1

Browse files
committed
fixes #7089
1 parent cd26d02 commit 80caca1

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,6 @@ styledEcho "Red on Green.", resetStyle
223223

224224
- ``writeStackTrace`` is now proclaimed to have no IO effect (even though it does)
225225
so that it is more useful for debugging purposes.
226+
- ``\n`` is now only the single line feed character like in most
227+
other programming languages. The new platform specific newline escape sequence is
228+
written as ``\p``. This change only affects the Windows platform.

compiler/commands.nim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,16 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
471471
processOnOffSwitch({optMemTracker}, arg, pass, info)
472472
if optMemTracker in gOptions: defineSymbol("memtracker")
473473
else: undefSymbol("memtracker")
474+
of "oldnewlines":
475+
case arg.normalize
476+
of "on":
477+
options.gOldNewlines = true
478+
defineSymbol("nimOldNewlines")
479+
of "off":
480+
options.gOldNewlines = false
481+
undefSymbol("nimOldNewlines")
482+
else:
483+
localError(info, errOnOrOffExpectedButXFound, arg)
474484
of "checks", "x": processOnOffSwitch(ChecksOptions, arg, pass, info)
475485
of "floatchecks":
476486
processOnOffSwitch({optNaNCheck, optInfCheck}, arg, pass, info)

compiler/lexer.nim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,15 @@ proc getEscapedChar(L: var TLexer, tok: var TToken) =
625625
inc(L.bufpos) # skip '\'
626626
case L.buf[L.bufpos]
627627
of 'n', 'N':
628-
if tok.tokType == tkCharLit: lexMessage(L, errNnotAllowedInCharacter)
628+
if gOldNewlines:
629+
if tok.tokType == tkCharLit: lexMessage(L, errNnotAllowedInCharacter)
630+
add(tok.literal, tnl)
631+
else:
632+
add(tok.literal, '\L')
633+
inc(L.bufpos)
634+
of 'p', 'P':
635+
if tok.tokType == tkCharLit:
636+
lexMessage(L, errGenerated, "\\p not allowed in character literal")
629637
add(tok.literal, tnl)
630638
inc(L.bufpos)
631639
of 'r', 'R', 'c', 'C':

compiler/options.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ proc cppDefine*(c: ConfigRef; define: string) =
114114

115115
var
116116
gIdeCmd*: IdeCmd
117+
gOldNewlines*: bool
117118

118119
const
119120
ChecksOptions* = {optObjCheck, optFieldCheck, optRangeCheck, optNilCheck,

doc/advopt.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Advanced options:
6363
--memTracker:on|off turn memory tracker on|off
6464
--excessiveStackTrace:on|off
6565
stack traces use full file paths
66+
--oldNewlines:on|off turn on|off the old behaviour of "\n"
6667
--skipCfg do not read the general configuration file
6768
--skipUserCfg do not read the user's configuration file
6869
--skipParentCfg do not read the parent dirs' configuration files

doc/manual/lexing.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ contain the following `escape sequences`:idx:\ :
163163
================== ===================================================
164164
Escape sequence Meaning
165165
================== ===================================================
166-
``\n`` `newline`:idx:
166+
``\p`` platform specific newline: CRLF on Windows,
167+
LF on Unix
167168
``\r``, ``\c`` `carriage return`:idx:
168-
``\l`` `line feed`:idx:
169+
``\n``, ``\l`` `line feed`:idx: (often called `newline`:idx:)
169170
``\f`` `form feed`:idx:
170171
``\t`` `tabulator`:idx:
171172
``\v`` `vertical tabulator`:idx:
@@ -261,7 +262,8 @@ Character literals
261262
------------------
262263

263264
Character literals are enclosed in single quotes ``''`` and can contain the
264-
same escape sequences as strings - with one exception: `newline`:idx: (``\n``)
265+
same escape sequences as strings - with one exception: the platform
266+
dependent `newline`:idx: (``\p``)
265267
is not allowed as it may be wider than one character (often it is the pair
266268
CR/LF for example). Here are the valid `escape sequences`:idx: for character
267269
literals:
@@ -270,7 +272,7 @@ literals:
270272
Escape sequence Meaning
271273
================== ===================================================
272274
``\r``, ``\c`` `carriage return`:idx:
273-
``\l`` `line feed`:idx:
275+
``\n``, ``\l`` `line feed`:idx:
274276
``\f`` `form feed`:idx:
275277
``\t`` `tabulator`:idx:
276278
``\v`` `vertical tabulator`:idx:

0 commit comments

Comments
 (0)