haskell-nix / hnix

A Haskell re-implementation of the Nix expression language
https://hackage.haskell.org/package/hnix
BSD 3-Clause "New" or "Revised" License
765 stars 115 forks source link

parse failed on recent nixpkgs all-packages.nix #1067

Closed yu-re-ka closed 2 years ago

yu-re-ka commented 2 years ago

[nix-shell:~/proj/hnix]$ cabal v2-run hnix -- --eval ~/proj/nixpkgs/pkgs/top-level/all-packages.nix 
Up to date
hnix: Parse failed: /home/yuka/proj/nixpkgs/pkgs/top-level/all-packages.nix:15958:21:
      |
15958 |   patchelf = if with stdenv.buildPlatform; isAarch64 && isMusl then
      |                     ^
unexpected space
expecting '!', '-', ':', or path
soulomoon commented 2 years ago

seems like associate priority problem in the parser. hnix parser does not expect nested keywords expresion

nixExpr :: Parser NExprLoc
nixExpr = keywords <|> nixLambda <|> nixExprAlgebra
 where
  keywords = nixLet <|> nixIf <|> nixAssert <|> nixWith

nixIf :: Parser NExprLoc
nixIf =
  annotateNamedLocation "if" $
    liftA3 NIf
      (reserved "if"   *> nixExprAlgebra)
      (exprAfterReservedWord "then")
      (exprAfterReservedWord "else")

nixExprAlgebra :: Parser NExprLoc
nixExprAlgebra =
  makeExprParser
    nixTerm
    nixOperators

while nix parser

expr: expr_function;

expr_function
  : ID ':' expr_function
    { $$ = new ExprLambda(CUR_POS, data->symbols.create($1), 0, $3); }
  | '{' formals '}' ':' expr_function
    { $$ = new ExprLambda(CUR_POS, toFormals(*data, $2), $5); }
  | '{' formals '}' '@' ID ':' expr_function
    {
      auto arg = data->symbols.create($5);
      $$ = new ExprLambda(CUR_POS, arg, toFormals(*data, $2, CUR_POS, arg), $7);
    }
  | ID '@' '{' formals '}' ':' expr_function
    {
      auto arg = data->symbols.create($1);
      $$ = new ExprLambda(CUR_POS, arg, toFormals(*data, $4, CUR_POS, arg), $7);
    }
  | ASSERT expr ';' expr_function
    { $$ = new ExprAssert(CUR_POS, $2, $4); }
  | WITH expr ';' expr_function
    { $$ = new ExprWith(CUR_POS, $2, $4); }
  | LET binds IN expr_function
    { if (!$2->dynamicAttrs.empty())
        throw ParseError({
            .msg = hintfmt("dynamic attributes not allowed in let"),
            .errPos = data->state.positions[CUR_POS]
        });
      $$ = new ExprLet($2, $4);
    }
  | expr_if
  ;

expr_if
  : IF expr THEN expr ELSE expr { $$ = new ExprIf(CUR_POS, $2, $4, $6); }
  | expr_op
  ;

following nix should be an expression rather than arith expr

soulomoon commented 2 years ago

I am fixing it


it shoudl be fixed by now @yu-re-ka

soulomoon commented 2 years ago

The bug should be fixed but there is problem in your command since you are not providing enough arg to the function(alll-pckages.nix). @yu-re-ka

> cabal v2-run hnix -- --eval ~/proj/nixpkgs/pkgs/top-level/all-packages.nix 
hnix: Missing value for parameter: ''VarName "lib"