Remove support for using \ for line continuation.

This commit is contained in:
Qi Xiao 2020-08-16 16:16:24 +01:00
parent bb24b63356
commit 0c2d05f260
3 changed files with 7 additions and 58 deletions

View File

@ -163,15 +163,15 @@ func TestUse(t *testing.T) {
}
// Regression test for #1072
func TestUse_WarnsAboutDeprecatedSyntax(t *testing.T) {
func TestUse_WarnsAboutDeprecatedFeatures(t *testing.T) {
restore := prog.SetShowDeprecations(true)
defer restore()
libdir, cleanup := util.InTestDir()
defer cleanup()
mustWriteFile("dep.elv", []byte("a = \\\n1"), 0600)
mustWriteFile("dep.elv", []byte("x = (ord 1)"), 0600)
TestWithSetup(t, func(ev *Evaler) { ev.SetLibDir(libdir) },
// Importing module triggers check for deprecated syntax features
// Importing module triggers check for deprecated features
That("use dep").PrintsStderrWith("is deprecated"),
)
}

View File

@ -18,7 +18,6 @@ import (
"unicode"
"github.com/elves/elvish/pkg/diag"
"github.com/elves/elvish/pkg/prog"
)
// Tree represents a parsed tree.
@ -958,8 +957,7 @@ spaces:
}
ps.next()
}
case r == '\\' || r == '^':
p := ps.pos
case r == '^':
// Line continuation is like inline whitespace.
ps.next()
switch ps.peek() {
@ -968,14 +966,8 @@ spaces:
if ps.peek() == '\n' {
ps.next()
}
if r == '\\' {
backslashLineCont(ps, p)
}
case '\n':
ps.next()
if r == '\\' {
backslashLineCont(ps, p)
}
case eof:
ps.error(errShouldBeNewline)
default:
@ -989,20 +981,6 @@ spaces:
addSep(n, ps)
}
func backslashLineCont(ps *parser, p int) {
if !prog.ShowDeprecations || ps.warn == nil {
return
}
err := diag.Error{
Type: "deprecation",
Message: "using \\ for line continuation is deprecated; use ^ instead",
Context: diag.Context{
Name: ps.srcName, Source: ps.src,
Ranging: diag.Ranging{From: p, To: p + 1}},
}
fmt.Fprintln(ps.warn, err.Show(""))
}
// IsInlineWhitespace reports whether r is an inline whitespace character.
// Currently this includes space (Unicode 0x20) and tab (Unicode 0x9).
func IsInlineWhitespace(r rune) bool {

View File

@ -1,14 +1,9 @@
package parse
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"testing"
"github.com/elves/elvish/pkg/prog"
)
func a(c ...interface{}) ast {
@ -255,9 +250,6 @@ var goodCases = []struct {
// Line continuation: "^\n" is considered whitespace
{"a b^\nc", ast{
"Chunk/Pipeline/Form", fs{"Head": "a", "Args": []string{"b", "c"}}}},
// Same test using deprecated "\\\n".
{"a b\\\nc", ast{
"Chunk/Pipeline/Form", fs{"Head": "a", "Args": []string{"b", "c"}}}},
// Carriage returns are normally treated the same as newlines:
// Separating pipelines in a chunk
@ -275,10 +267,10 @@ var goodCases = []struct {
"Elements": []string{"a", "b"}}})},
// However, in line continuations, \r\n is treated as a single newline
{"a b\\\r\nc", ast{
{"a b^\r\nc", ast{
"Chunk/Pipeline/Form", fs{"Head": "a", "Args": []string{"b", "c"}}}},
// But a lone \r also works
{"a b\\\rc", ast{
{"a b^\rc", ast{
"Chunk/Pipeline/Form", fs{"Head": "a", "Args": []string{"b", "c"}}}},
// Comments in chunks.
@ -321,27 +313,6 @@ func TestParse(t *testing.T) {
}
}
func TestParseDeprecations(t *testing.T) {
restore := prog.SetShowDeprecations(true)
defer restore()
r, w := io.Pipe()
msgChan := make(chan []byte)
go func() {
msg, _ := ioutil.ReadAll(r)
msgChan <- msg
r.Close()
}()
ParseWithDeprecation(Source{Name: "[test]", Code: "a\\\nb"}, w)
w.Close()
msg := <-msgChan
wantMsg := []byte("using \\ for line continuation is deprecated")
if !bytes.Contains(msg, wantMsg) {
t.Errorf("got message %q, want message to contain %q", msg, wantMsg)
}
}
var parseErrorTests = []struct {
src string
errPart string
@ -391,7 +362,7 @@ var parseErrorTests = []struct {
// Unmatched {.
{src: "{ a", errAtEnd: true, errMsg: "should be '}'"},
// Unfinished line continuation.
{src: `a \`, errAtEnd: true, errMsg: "should be newline"},
{src: `a ^`, errAtEnd: true, errMsg: "should be newline"},
// Backslash is otherwise not allowed.
{src: `a \a`, errPart: `\`, errMsg: `unexpected rune '\\'`},
}