diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-09-09 16:20:41 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-09-09 16:20:41 +0200 |
commit | 1e61471d480575d069f96b858e4b46f43ba0530f (patch) | |
tree | 9a73101d555a2212fa68a36626fb850496da8e03 | |
parent | ea66709a853255c7957a8a7907fd21fa7f6cfd3f (diff) |
For newline escaping, ignore whole thing instead of making it newline
To capture literal newline, use quoting.
-rw-r--r-- | build/lexer.cxx | 9 | ||||
-rw-r--r-- | tests/escaping/buildfile | 13 | ||||
-rw-r--r-- | tests/escaping/test.out | 4 | ||||
-rwxr-xr-x | tests/escaping/test.sh | 3 | ||||
-rw-r--r-- | tests/quote/buildfile | 15 | ||||
-rw-r--r-- | tests/quote/test.out | 5 |
6 files changed, 44 insertions, 5 deletions
diff --git a/build/lexer.cxx b/build/lexer.cxx index e083b4a..b680234 100644 --- a/build/lexer.cxx +++ b/build/lexer.cxx @@ -225,7 +225,9 @@ namespace build case '\\': { get (); - lexeme += escape (); + c = escape (); + if (c != '\n') // Ignore. + lexeme += c; continue; } case '\'': @@ -362,10 +364,7 @@ namespace build get (); if (peek () == '\n') - { - r = true; - break; - } + break; // Ignore. unget (c); // Fall through. diff --git a/tests/escaping/buildfile b/tests/escaping/buildfile new file mode 100644 index 0000000..4259087 --- /dev/null +++ b/tests/escaping/buildfile @@ -0,0 +1,13 @@ +print \'single\' +print \"double\" + +# Newline is special. +# +\ +print foo\ +bar + +print foo \ +bar + +./: diff --git a/tests/escaping/test.out b/tests/escaping/test.out new file mode 100644 index 0000000..9894dde --- /dev/null +++ b/tests/escaping/test.out @@ -0,0 +1,4 @@ +'single' +"double" +foobar +foo bar diff --git a/tests/escaping/test.sh b/tests/escaping/test.sh new file mode 100755 index 0000000..b898b3c --- /dev/null +++ b/tests/escaping/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +valgrind -q b -q | diff -u test.out - diff --git a/tests/quote/buildfile b/tests/quote/buildfile index 19c2bfc..a2ebbe9 100644 --- a/tests/quote/buildfile +++ b/tests/quote/buildfile @@ -29,4 +29,19 @@ print "("foo bar")" print "("$foo bar")" print "("$foo ($bar)")" +# Quoting and escaping/multiline. +# +print \ +"foo"\ +"bar" + +print \ +"foo\ +bar" + +print \ +"foo (fox \ +) +bar" + ./: diff --git a/tests/quote/test.out b/tests/quote/test.out index f5d7a71..af5b724 100644 --- a/tests/quote/test.out +++ b/tests/quote/test.out @@ -18,3 +18,8 @@ foo bar foo bar fo o bar fo o bar +foobar +foo\ +bar +foo fox +bar |