diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index c9ad3040771..7d78fb84137 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -3,7 +3,7 @@ %define api.namespace { ::nix::parser } %define api.parser.class { BisonParser } %locations -%define parse.error verbose +%define parse.error detailed %defines /* %no-lines */ %parse-param { void * scanner } @@ -140,18 +140,41 @@ static Expr * makeCall(Exprs & exprs, PosIdx pos, Expr * fn, Expr * arg) { %type path_start %type string_parts string_attr %type attr -%token ID -%token STR IND_STR -%token INT_LIT -%token FLOAT_LIT -%token PATH HPATH SPATH PATH_END -%token URI -%token IF THEN ELSE ASSERT WITH LET IN_KW REC INHERIT EQ NEQ AND OR IMPL OR_KW -%token PIPE_FROM PIPE_INTO /* <| and |> */ -%token DOLLAR_CURLY /* == ${ */ -%token IND_STRING_OPEN IND_STRING_CLOSE -%token ELLIPSIS - +%token ID "identifier" +%token STR "string" +%token IND_STR "indented string" +%token INT_LIT "integer" +%token FLOAT_LIT "floating-point literal" +%token PATH "path" +%token HPATH "'~/…' path" +%token SPATH "'<…>' path" +%token PATH_END "end of path" +%token URI "URI" +%token IF "'if'" +%token THEN "'then'" +%token ELSE "'else'" +%token ASSERT "'assert'" +%token WITH "'with'" +%token LET "'let'" +%token IN_KW "'in'" +%token REC "'rec'" +%token INHERIT "'inherit'" +%token EQ "'=='" +%token NEQ "'!='" +%token LEQ "'<='" +%token GEQ "'>='" +%token UPDATE "'//'" +%token CONCAT "'++'" +%token AND "'&&'" +%token OR "'||'" +%token IMPL "'->'" +%token OR_KW "'or'" +%token PIPE_FROM "'<|'" +%token PIPE_INTO "'|>'" +%token DOLLAR_CURLY "'${'" +%token IND_STRING_OPEN "start of an indented string" +%token IND_STRING_CLOSE "end of an indented string" +%token ELLIPSIS "'...'" %right IMPL %left OR diff --git a/tests/functional/lang/parse-fail-unexpected-and.err.exp b/tests/functional/lang/parse-fail-unexpected-and.err.exp new file mode 100644 index 00000000000..8c3b11241d0 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-and.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '&&' + at «stdin»:1:1: + 1| && true + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-and.nix b/tests/functional/lang/parse-fail-unexpected-and.nix new file mode 100644 index 00000000000..92b7ef1c7dd --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-and.nix @@ -0,0 +1 @@ +&& true diff --git a/tests/functional/lang/parse-fail-unexpected-assert.err.exp b/tests/functional/lang/parse-fail-unexpected-assert.err.exp new file mode 100644 index 00000000000..7f00dcd5863 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-assert.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected 'assert', expecting identifier or 'or' or '${' or '"' + at «stdin»:1:3: + 1| a.assert + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-assert.nix b/tests/functional/lang/parse-fail-unexpected-assert.nix new file mode 100644 index 00000000000..989a981111b --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-assert.nix @@ -0,0 +1 @@ +a.assert diff --git a/tests/functional/lang/parse-fail-unexpected-concat.err.exp b/tests/functional/lang/parse-fail-unexpected-concat.err.exp new file mode 100644 index 00000000000..e1845bde8de --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-concat.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '++' + at «stdin»:1:1: + 1| ++ [] + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-concat.nix b/tests/functional/lang/parse-fail-unexpected-concat.nix new file mode 100644 index 00000000000..0e84d329561 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-concat.nix @@ -0,0 +1 @@ +++ [] diff --git a/tests/functional/lang/parse-fail-unexpected-ellipsis.err.exp b/tests/functional/lang/parse-fail-unexpected-ellipsis.err.exp new file mode 100644 index 00000000000..8a2019298f2 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-ellipsis.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '...', expecting '.' or '=' + at «stdin»:1:5: + 1| { a ... } + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-ellipsis.nix b/tests/functional/lang/parse-fail-unexpected-ellipsis.nix new file mode 100644 index 00000000000..ba04161cf3c --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-ellipsis.nix @@ -0,0 +1 @@ +{ a ... } diff --git a/tests/functional/lang/parse-fail-unexpected-else.err.exp b/tests/functional/lang/parse-fail-unexpected-else.err.exp new file mode 100644 index 00000000000..5a8f0b2a5e5 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-else.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected 'else', expecting 'then' + at «stdin»:1:6: + 1| if 1 else + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-else.nix b/tests/functional/lang/parse-fail-unexpected-else.nix new file mode 100644 index 00000000000..b9a805eb736 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-else.nix @@ -0,0 +1 @@ +if 1 else diff --git a/tests/functional/lang/parse-fail-unexpected-eq.err.exp b/tests/functional/lang/parse-fail-unexpected-eq.err.exp new file mode 100644 index 00000000000..6fb9db002c6 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-eq.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '==' + at «stdin»:1:1: + 1| == 1 + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-eq.nix b/tests/functional/lang/parse-fail-unexpected-eq.nix new file mode 100644 index 00000000000..2badb0f30db --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-eq.nix @@ -0,0 +1 @@ +== 1 diff --git a/tests/functional/lang/parse-fail-unexpected-float.err.exp b/tests/functional/lang/parse-fail-unexpected-float.err.exp new file mode 100644 index 00000000000..6db7be9ab68 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-float.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected floating-point literal, expecting 'inherit' + at «stdin»:1:3: + 1| { 1.5 = x; } + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-float.nix b/tests/functional/lang/parse-fail-unexpected-float.nix new file mode 100644 index 00000000000..8b018950144 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-float.nix @@ -0,0 +1 @@ +{ 1.5 = x; } diff --git a/tests/functional/lang/parse-fail-unexpected-geq.err.exp b/tests/functional/lang/parse-fail-unexpected-geq.err.exp new file mode 100644 index 00000000000..666f1e336d8 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-geq.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '>=' + at «stdin»:1:1: + 1| >= 1 + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-geq.nix b/tests/functional/lang/parse-fail-unexpected-geq.nix new file mode 100644 index 00000000000..4eee0cc8826 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-geq.nix @@ -0,0 +1 @@ +>= 1 diff --git a/tests/functional/lang/parse-fail-unexpected-hpath.err.exp b/tests/functional/lang/parse-fail-unexpected-hpath.err.exp new file mode 100644 index 00000000000..15193927be0 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-hpath.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '~/…' path, expecting identifier or 'or' or '${' or '"' + at «stdin»:1:3: + 1| a.~/foo + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-hpath.nix b/tests/functional/lang/parse-fail-unexpected-hpath.nix new file mode 100644 index 00000000000..b0422ef35d9 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-hpath.nix @@ -0,0 +1 @@ +a.~/foo diff --git a/tests/functional/lang/parse-fail-unexpected-if.err.exp b/tests/functional/lang/parse-fail-unexpected-if.err.exp new file mode 100644 index 00000000000..9941adbd286 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-if.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected 'if', expecting identifier or 'or' or '${' or '"' + at «stdin»:1:3: + 1| a.if + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-if.nix b/tests/functional/lang/parse-fail-unexpected-if.nix new file mode 100644 index 00000000000..7dd8b96b859 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-if.nix @@ -0,0 +1 @@ +a.if diff --git a/tests/functional/lang/parse-fail-unexpected-impl.err.exp b/tests/functional/lang/parse-fail-unexpected-impl.err.exp new file mode 100644 index 00000000000..36421578de1 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-impl.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '->' + at «stdin»:1:1: + 1| -> x + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-impl.nix b/tests/functional/lang/parse-fail-unexpected-impl.nix new file mode 100644 index 00000000000..05217c76357 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-impl.nix @@ -0,0 +1 @@ +-> x diff --git a/tests/functional/lang/parse-fail-unexpected-in.err.exp b/tests/functional/lang/parse-fail-unexpected-in.err.exp new file mode 100644 index 00000000000..7557552d2fc --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-in.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected 'in', expecting identifier or 'or' or '${' or '"' + at «stdin»:1:3: + 1| a.in + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-in.nix b/tests/functional/lang/parse-fail-unexpected-in.nix new file mode 100644 index 00000000000..20e5c8ea346 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-in.nix @@ -0,0 +1 @@ +a.in diff --git a/tests/functional/lang/parse-fail-unexpected-ind-string.err.exp b/tests/functional/lang/parse-fail-unexpected-ind-string.err.exp new file mode 100644 index 00000000000..2e348ae0d9c --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-ind-string.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected start of an indented string, expecting identifier or 'or' or '${' or '"' + at «stdin»:1:3: + 1| a.'' + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-ind-string.nix b/tests/functional/lang/parse-fail-unexpected-ind-string.nix new file mode 100644 index 00000000000..667303fb2e7 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-ind-string.nix @@ -0,0 +1 @@ +a.'' diff --git a/tests/functional/lang/parse-fail-unexpected-inherit.err.exp b/tests/functional/lang/parse-fail-unexpected-inherit.err.exp new file mode 100644 index 00000000000..56389139a8a --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-inherit.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected 'inherit', expecting identifier or 'or' or '${' or '"' + at «stdin»:1:3: + 1| a.inherit + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-inherit.nix b/tests/functional/lang/parse-fail-unexpected-inherit.nix new file mode 100644 index 00000000000..324e683c302 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-inherit.nix @@ -0,0 +1 @@ +a.inherit diff --git a/tests/functional/lang/parse-fail-unexpected-int.err.exp b/tests/functional/lang/parse-fail-unexpected-int.err.exp new file mode 100644 index 00000000000..d20d9cd8bb3 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-int.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected integer, expecting 'inherit' + at «stdin»:1:3: + 1| { 1 = x; } + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-int.nix b/tests/functional/lang/parse-fail-unexpected-int.nix new file mode 100644 index 00000000000..bf3622703ba --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-int.nix @@ -0,0 +1 @@ +{ 1 = x; } diff --git a/tests/functional/lang/parse-fail-unexpected-leq.err.exp b/tests/functional/lang/parse-fail-unexpected-leq.err.exp new file mode 100644 index 00000000000..a521e195385 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-leq.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '<=' + at «stdin»:1:1: + 1| <= 1 + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-leq.nix b/tests/functional/lang/parse-fail-unexpected-leq.nix new file mode 100644 index 00000000000..e642af42966 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-leq.nix @@ -0,0 +1 @@ +<= 1 diff --git a/tests/functional/lang/parse-fail-unexpected-let.err.exp b/tests/functional/lang/parse-fail-unexpected-let.err.exp new file mode 100644 index 00000000000..4468547cb19 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-let.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected 'let', expecting identifier or 'or' or '${' or '"' + at «stdin»:1:3: + 1| a.let + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-let.nix b/tests/functional/lang/parse-fail-unexpected-let.nix new file mode 100644 index 00000000000..632c7b3a066 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-let.nix @@ -0,0 +1 @@ +a.let diff --git a/tests/functional/lang/parse-fail-unexpected-neq.err.exp b/tests/functional/lang/parse-fail-unexpected-neq.err.exp new file mode 100644 index 00000000000..7a75ac9a778 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-neq.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '!=' + at «stdin»:1:6: + 1| 1 != != 2 + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-neq.nix b/tests/functional/lang/parse-fail-unexpected-neq.nix new file mode 100644 index 00000000000..ca366caa3a7 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-neq.nix @@ -0,0 +1 @@ +1 != != 2 diff --git a/tests/functional/lang/parse-fail-unexpected-or.err.exp b/tests/functional/lang/parse-fail-unexpected-or.err.exp new file mode 100644 index 00000000000..ed1a1a675f5 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-or.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '||' + at «stdin»:1:1: + 1| || true + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-or.nix b/tests/functional/lang/parse-fail-unexpected-or.nix new file mode 100644 index 00000000000..2922d991965 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-or.nix @@ -0,0 +1 @@ +|| true diff --git a/tests/functional/lang/parse-fail-unexpected-path.err.exp b/tests/functional/lang/parse-fail-unexpected-path.err.exp new file mode 100644 index 00000000000..aff95ab81dc --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-path.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected path, expecting identifier or 'or' or '${' or '"' + at «stdin»:1:7: + 1| { } ? ./foo + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-path.nix b/tests/functional/lang/parse-fail-unexpected-path.nix new file mode 100644 index 00000000000..8f261419fb3 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-path.nix @@ -0,0 +1 @@ +{ } ? ./foo diff --git a/tests/functional/lang/parse-fail-unexpected-rec.err.exp b/tests/functional/lang/parse-fail-unexpected-rec.err.exp new file mode 100644 index 00000000000..f1db1b4ec33 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-rec.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected 'rec', expecting identifier or 'or' or '${' or '"' + at «stdin»:1:3: + 1| a.rec + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-rec.nix b/tests/functional/lang/parse-fail-unexpected-rec.nix new file mode 100644 index 00000000000..01f4facc42d --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-rec.nix @@ -0,0 +1 @@ +a.rec diff --git a/tests/functional/lang/parse-fail-unexpected-spath.err.exp b/tests/functional/lang/parse-fail-unexpected-spath.err.exp new file mode 100644 index 00000000000..30b8ac83c2c --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-spath.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '<…>' path, expecting identifier or 'or' or '${' or '"' + at «stdin»:1:3: + 1| a. + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-spath.nix b/tests/functional/lang/parse-fail-unexpected-spath.nix new file mode 100644 index 00000000000..42c8a0cac22 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-spath.nix @@ -0,0 +1 @@ +a. diff --git a/tests/functional/lang/parse-fail-unexpected-then.err.exp b/tests/functional/lang/parse-fail-unexpected-then.err.exp new file mode 100644 index 00000000000..8fbfdd9462d --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-then.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected 'then' + at «stdin»:1:4: + 1| if then + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-then.nix b/tests/functional/lang/parse-fail-unexpected-then.nix new file mode 100644 index 00000000000..f767077b93f --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-then.nix @@ -0,0 +1 @@ +if then diff --git a/tests/functional/lang/parse-fail-unexpected-update.err.exp b/tests/functional/lang/parse-fail-unexpected-update.err.exp new file mode 100644 index 00000000000..e2a31b98bab --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-update.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected '//' + at «stdin»:1:1: + 1| // 1 + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-update.nix b/tests/functional/lang/parse-fail-unexpected-update.nix new file mode 100644 index 00000000000..9d63dce53f5 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-update.nix @@ -0,0 +1 @@ +// 1 diff --git a/tests/functional/lang/parse-fail-unexpected-uri.err.exp b/tests/functional/lang/parse-fail-unexpected-uri.err.exp new file mode 100644 index 00000000000..148085d5675 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-uri.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected URI + at «stdin»:1:11: + 1| { inherit http://x; } + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-uri.nix b/tests/functional/lang/parse-fail-unexpected-uri.nix new file mode 100644 index 00000000000..c57dec0e0f7 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-uri.nix @@ -0,0 +1 @@ +{ inherit http://x; } diff --git a/tests/functional/lang/parse-fail-unexpected-with.err.exp b/tests/functional/lang/parse-fail-unexpected-with.err.exp new file mode 100644 index 00000000000..a79581d919f --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-with.err.exp @@ -0,0 +1,5 @@ +error: syntax error, unexpected 'with', expecting identifier or 'or' or '${' or '"' + at «stdin»:1:3: + 1| a.with + | ^ + 2| diff --git a/tests/functional/lang/parse-fail-unexpected-with.nix b/tests/functional/lang/parse-fail-unexpected-with.nix new file mode 100644 index 00000000000..1c1ec0c6195 --- /dev/null +++ b/tests/functional/lang/parse-fail-unexpected-with.nix @@ -0,0 +1 @@ +a.with