Skip to content

Commit 652daef

Browse files
wetorncw
authored andcommitted
parser: fix CRLF(\r\n) file parsing error, SyntaxError: 'invalid syntax'
1 parent 337df2a commit 652daef

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

parser/lexer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ func (x *yyLex) dequeue() int {
110110
func (x *yyLex) refill() {
111111
var err error
112112
x.line, err = x.reader.ReadString('\n')
113+
if strings.HasSuffix(x.line, "\r\n") {
114+
x.line = x.line[:len(x.line)-2] + "\n"
115+
}
113116
if yyDebug >= 2 {
114117
fmt.Printf("line = %q, err = %v\n", x.line, err)
115118
}

parser/lexer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func TestLex(t *testing.T) {
262262
{"01", "illegal decimal with leading zero 1:0", "exec", LexTokens{
263263
{FILE_INPUT, nil, ast.Pos{0, 0}},
264264
}},
265-
{"1\n 2\n 3\n4\n", "", "exec", LexTokens{
265+
{"1\n 2\r\n 3\r\n4\n", "", "exec", LexTokens{
266266
{FILE_INPUT, nil, ast.Pos{0, 0}},
267267
{NUMBER, py.Int(1), ast.Pos{1, 0}},
268268
{NEWLINE, nil, ast.Pos{1, 1}},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy