libexpr/nix2: Remove CR line endings

Change-Id: Ib4946c9975804e02ea7584e0c7373c82ed4961f9
This commit is contained in:
piegames 2024-09-28 12:16:15 +02:00
parent dc3c4d9fbf
commit 51d9bdcc68
6 changed files with 23 additions and 6 deletions

View file

@ -15,9 +15,8 @@
// meant to be language versions or have any other semantic meaning. // meant to be language versions or have any other semantic meaning.
// NOTE // NOTE
// nix line endings are \n, \r\n, \r. the grammar does not use eol or // nix line endings are \n, \r\n, *not* \r. Line endings in strings are
// eolf rules in favor of reproducing the old flex lexer as faithfully as // normalized to \n.
// possible, and deferring calculation of positions to downstream users.
namespace nix::parser::grammar::v2 { namespace nix::parser::grammar::v2 {
@ -157,9 +156,17 @@ struct floating : p::seq<
p::must<p::not_at<_extend_as_path>> p::must<p::not_at<_extend_as_path>>
> {}; > {};
// LF or CRLF
struct eol : p::sor<
p8::one<'\n'>,
p::seq<p8::one<'\r'>, p::must<p8::one<'\n'>>>
> {};
// Spacing including comments
struct sep : p::sor< struct sep : p::sor<
p::plus<p8::one<' ', '\t', '\r', '\n'>>, p::plus<p8::one<' ', '\t', '\n'>>,
p::seq<p8::one<'#'>, p::star<p8::not_one<'\r', '\n'>>>, eol,
p::seq<p8::one<'#'>, p::until<eol>>,
p::seq<p8::string<'/', '*'>, p::until<p8::string<'*', '/'>>> p::seq<p8::string<'/', '*'>, p::until<p8::string<'*', '/'>>>
> {}; > {};
@ -180,7 +187,7 @@ struct expr;
struct _string { struct _string {
template<typename... Inner> template<typename... Inner>
struct literal : semantic, p::seq<Inner...> {}; struct literal : semantic, p::seq<Inner...> {};
struct cr_lf : semantic, p::seq<p8::one<'\r'>, p::opt<p8::one<'\n'>>> {}; struct cr_lf : semantic, p::seq<p8::one<'\r'>, p::must<p8::one<'\n'>>> {};
struct interpolation : semantic, p::seq< struct interpolation : semantic, p::seq<
p8::string<'$', '{'>, seps, p8::string<'$', '{'>, seps,
p::must<expr>, seps, p::must<expr>, seps,

View file

@ -23,6 +23,7 @@ inline constexpr const char * error_message = nullptr;
template<> inline constexpr auto error_message<__VA_ARGS__> template<> inline constexpr auto error_message<__VA_ARGS__>
// These are used everywhere the are wrapped in `must<…>` when parsing fails (instead of the usual backtracking) // These are used everywhere the are wrapped in `must<…>` when parsing fails (instead of the usual backtracking)
error_message_for(p8::one<'\n'>) = "line endings must be LF or CRLF, found lone \\r";
error_message_for(p8::one<'{'>) = "expecting '{'"; error_message_for(p8::one<'{'>) = "expecting '{'";
error_message_for(p8::one<'}'>) = "expecting '}'"; error_message_for(p8::one<'}'>) = "expecting '}'";
error_message_for(p8::one<'"'>) = "expecting '\"'"; error_message_for(p8::one<'"'>) = "expecting '\"'";

View file

@ -205,6 +205,7 @@ constexpr std::array<ExperimentalFeatureDetails, numXpFeatures> xpFeatureDetails
- Interpolation in identifiers needs to always be wrapped in $\{}; `"foo ${bar}"` is not a valid identifier anymore. - Interpolation in identifiers needs to always be wrapped in $\{}; `"foo ${bar}"` is not a valid identifier anymore.
- Removed ancient `let {` syntax. See also the `ancient-let` deprecated feature - Removed ancient `let {` syntax. See also the `ancient-let` deprecated feature
- All Nix code must now be fully valid UTF-8 text. - All Nix code must now be fully valid UTF-8 text.
- Line endings must be LF or CLRF, not CR.
)", )",
}, },
{ {

View file

@ -0,0 +1,6 @@
error: syntax error, line endings must be LF or CRLF, found lone \r
at «stdin»:2:1:
1| # foo
2| invalid
| ^
3| # bar

View file

@ -0,0 +1 @@
--extra-experimental-features nix-lang2

View file

@ -0,0 +1 @@
parse-fail-eol-2.nix