From: Pablo Neira Ayuso Date: Mon, 6 Jan 2025 23:00:50 +0000 (+0100) Subject: scanner: better error reporting for CRLF line terminators X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=d68dde0ec4cebd6e4bef87bd939a1a5d98f241b5;p=thirdparty%2Fnftables.git scanner: better error reporting for CRLF line terminators commit 8c35615297983227cac1437edbe0cdedf4c2227b upstream. Provide a hint to users that file is coming with CRLF line terminators, maybe from a non-Linux OS. Extend scanner.l to provide hint on CRLF in files: # file test.nft test.nft: ASCII text, with CRLF, LF line terminators # nft -f test.nft test.nft:1:13-14: Error: syntax error, unexpected CRLF line terminators table ip x { ^^ Signed-off-by: Pablo Neira Ayuso --- diff --git a/src/parser_bison.y b/src/parser_bison.y index 7c008f68..3258c7e6 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -233,6 +233,7 @@ int nft_lex(void *, void *, void *); %token TOKEN_EOF 0 "end of file" %token JUNK "junk" +%token CRLF "CRLF line terminators" %token NEWLINE "newline" %token COLON "colon" diff --git a/src/scanner.l b/src/scanner.l index e88a2643..00816c93 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -114,6 +114,7 @@ extern void yyset_column(int, yyscan_t); space [ ] tab \t +newline_crlf \r\n newline \n digit [0-9] hexdigit [0-9a-fA-F] @@ -862,6 +863,8 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) return STRING; } +{newline_crlf} { return CRLF; } + \\{newline} { reset_pos(yyget_extra(yyscanner), yylloc); }