This detail of the specification makes triple-quoted strings more
readable and usable in code.
Before, programmer was required to starts content just after the """
thus writing unaligned piece of text
~~~
var x = """Roses are red,
Violets are blue,
Triple-quoted strings,
Are easier to write.
"""
~~~
This patch ignore the end of line iff it just follows the """,
thus programmer can write
~~~
var x = """
Roses are red,
Violets are blue,
Triple-quoted strings,
Are easier to write.
"""
~~~
This commit will improve the usability of the new/future template library.
Signed-off-by: Jean Privat <jean@pryen.org>
redef fun accept_literal(v)
do
var txt = self.n_string.text
- var skip = 1
- if txt.chars[0] == txt.chars[1] and txt.length >= 6 then skip = 3
- self.value = txt.substring(skip, txt.length-(2*skip)).unescape_nit
+ var behead = 1
+ var betail = 1
+ if txt.chars[0] == txt.chars[1] and txt.length >= 6 then
+ behead = 3
+ betail = 3
+ if txt.chars[0] == '"' and txt.chars[3] == '\n' then behead = 4 # ignore first \n in """
+ end
+ self.value = txt.substring(behead, txt.length - behead - betail).unescape_nit
end
end
1111b{b}bc{{{ {{{ {{{ 1
-
-
*1**2***3***$4$
--- /dev/null
+hello
+word
+hello
+world
+hello
+word
+
+hello
+world
+
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+print """hello
+word"""
+
+print """
+hello
+world"""
+
+print """hello
+word
+"""
+
+print """
+hello
+world
+"""