summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-01-24 20:08:17 +0100
committerAndreas Rumpf <rumpf_a@web.de>2018-01-24 20:08:17 +0100
commit80caca15bd72e5dbc2712c1f0f6cbfa90262fbb2 (patch)
treeb93808b834a1983a0787ff9de33e6a66daa08b27
parentcd26d0288256c8966edb0762828e599f5fc6cc09 (diff)
downloadNim-80caca15bd72e5dbc2712c1f0f6cbfa90262fbb2.tar.gz
fixes #7089
-rw-r--r--changelog.md3
-rw-r--r--compiler/commands.nim10
-rw-r--r--compiler/lexer.nim10
-rw-r--r--compiler/options.nim1
-rw-r--r--doc/advopt.txt1
-rw-r--r--doc/manual/lexing.txt10
6 files changed, 30 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md
index f7a656937..5c552b486 100644
--- a/changelog.md
+++ b/changelog.md
@@ -223,3 +223,6 @@ styledEcho "Red on Green.", resetStyle
 
 - ``writeStackTrace`` is now proclaimed to have no IO effect (even though it does)
   so that it is more useful for debugging purposes.
+- ``\n`` is now only the single line feed character like in most
+  other programming languages. The new platform specific newline escape sequence is
+  written as ``\p``. This change only affects the Windows platform.
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 18b328fd6..45c0f586c 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -471,6 +471,16 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
     processOnOffSwitch({optMemTracker}, arg, pass, info)
     if optMemTracker in gOptions: defineSymbol("memtracker")
     else: undefSymbol("memtracker")
+  of "oldnewlines":
+    case arg.normalize
+    of "on":
+      options.gOldNewlines = true
+      defineSymbol("nimOldNewlines")
+    of "off":
+      options.gOldNewlines = false
+      undefSymbol("nimOldNewlines")
+    else:
+      localError(info, errOnOrOffExpectedButXFound, arg)
   of "checks", "x": processOnOffSwitch(ChecksOptions, arg, pass, info)
   of "floatchecks":
     processOnOffSwitch({optNaNCheck, optInfCheck}, arg, pass, info)
diff --git a/compiler/lexer.nim b/compiler/lexer.nim
index bca07e500..f703eb3c0 100644
--- a/compiler/lexer.nim
+++ b/compiler/lexer.nim
@@ -625,7 +625,15 @@ proc getEscapedChar(L: var TLexer, tok: var TToken) =
   inc(L.bufpos)               # skip '\'
   case L.buf[L.bufpos]
   of 'n', 'N':
-    if tok.tokType == tkCharLit: lexMessage(L, errNnotAllowedInCharacter)
+    if gOldNewlines:
+      if tok.tokType == tkCharLit: lexMessage(L, errNnotAllowedInCharacter)
+      add(tok.literal, tnl)
+    else:
+      add(tok.literal, '\L')
+    inc(L.bufpos)
+  of 'p', 'P':
+    if tok.tokType == tkCharLit:
+      lexMessage(L, errGenerated, "\\p not allowed in character literal")
     add(tok.literal, tnl)
     inc(L.bufpos)
   of 'r', 'R', 'c', 'C':
diff --git a/compiler/options.nim b/compiler/options.nim
index 8112f26b1..2f136a8f2 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -114,6 +114,7 @@ proc cppDefine*(c: ConfigRef; define: string) =
 
 var
   gIdeCmd*: IdeCmd
+  gOldNewlines*: bool
 
 const
   ChecksOptions* = {optObjCheck, optFieldCheck, optRangeCheck, optNilCheck,
diff --git a/doc/advopt.txt b/doc/advopt.txt
index a1210118e..c8ff0845a 100644
--- a/doc/advopt.txt
+++ b/doc/advopt.txt
@@ -63,6 +63,7 @@ Advanced options:
   --memTracker:on|off       turn memory tracker on|off
   --excessiveStackTrace:on|off
                             stack traces use full file paths
+  --oldNewlines:on|off      turn on|off the old behaviour of "\n"
   --skipCfg                 do not read the general configuration file
   --skipUserCfg             do not read the user's configuration file
   --skipParentCfg           do not read the parent dirs' configuration files
diff --git a/doc/manual/lexing.txt b/doc/manual/lexing.txt
index 92925b7f1..915e87971 100644
--- a/doc/manual/lexing.txt
+++ b/doc/manual/lexing.txt
@@ -163,9 +163,10 @@ contain the following `escape sequences`:idx:\ :
 ==================         ===================================================
   Escape sequence          Meaning
 ==================         ===================================================
-  ``\n``                   `newline`:idx:
+  ``\p``                   platform specific newline: CRLF on Windows,
+                           LF on Unix
   ``\r``, ``\c``           `carriage return`:idx:
-  ``\l``                   `line feed`:idx:
+  ``\n``, ``\l``           `line feed`:idx: (often called `newline`:idx:)
   ``\f``                   `form feed`:idx:
   ``\t``                   `tabulator`:idx:
   ``\v``                   `vertical tabulator`:idx:
@@ -261,7 +262,8 @@ Character literals
 ------------------
 
 Character literals are enclosed in single quotes ``''`` and can contain the
-same escape sequences as strings - with one exception: `newline`:idx: (``\n``)
+same escape sequences as strings - with one exception: the platform
+dependent `newline`:idx: (``\p``)
 is not allowed as it may be wider than one character (often it is the pair
 CR/LF for example).  Here are the valid `escape sequences`:idx: for character
 literals:
@@ -270,7 +272,7 @@ literals:
   Escape sequence          Meaning
 ==================         ===================================================
   ``\r``, ``\c``           `carriage return`:idx:
-  ``\l``                   `line feed`:idx:
+  ``\n``, ``\l``           `line feed`:idx:
   ``\f``                   `form feed`:idx:
   ``\t``                   `tabulator`:idx:
   ``\v``                   `vertical tabulator`:idx: