From 077cfa3e35330ec982c0b4c9047c0956d04d1103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Wed, 14 May 2025 17:57:22 +0200 Subject: Parse shell statement parameters in arbitrary order --- src/Parser/Expr.hs | 2 +- src/Parser/Statement.hs | 55 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Parser/Expr.hs b/src/Parser/Expr.hs index 3700602..079cfba 100644 --- a/src/Parser/Expr.hs +++ b/src/Parser/Expr.hs @@ -394,7 +394,7 @@ checkFunctionArguments (FunctionArguments argTypes) poff kw sexpr@(SomeExpr expr Nothing -> do registerParseError $ FancyError poff $ S.singleton $ ErrorFail $ T.unpack $ case kw of - Just (ArgumentKeyword tkw) -> "unexpected parameter with keyword `" <> tkw <> "'" + Just (ArgumentKeyword tkw) -> "unexpected parameter with keyword ‘" <> tkw <> "’" Nothing -> "unexpected parameter" return sexpr diff --git a/src/Parser/Statement.hs b/src/Parser/Statement.hs index 7c2977d..812c559 100644 --- a/src/Parser/Statement.hs +++ b/src/Parser/Statement.hs @@ -74,17 +74,50 @@ shellStatement :: TestParser (Expr (TestBlock ())) shellStatement = do ref <- L.indentLevel wsymbol "shell" - wsymbol "as" - pname <- newVarName - wsymbol "on" - node <- typedExpr - symbol ":" - void eol - void $ L.indentGuard scn GT ref - script <- shellScript - cont <- testBlock ref - return $ TestBlockStep EmptyTestBlock <$> - (SpawnShell pname <$> node <*> script <*> LambdaAbstraction pname cont) + parseParams ref Nothing Nothing + + where + parseParamKeyword kw prev = do + off <- stateOffset <$> getParserState + wsymbol kw + when (isJust prev) $ do + registerParseError $ FancyError off $ S.singleton $ ErrorFail $ + "unexpected parameter with keyword ‘" <> kw <> "’" + + parseParams ref mbpname mbnode = choice + [ do + parseParamKeyword "as" mbpname + pname <- newVarName + parseParams ref (Just pname) mbnode + + , do + parseParamKeyword "on" mbnode + node <- typedExpr + parseParams ref mbpname (Just node) + + , do + off <- stateOffset <$> getParserState + symbol ":" + pname <- case mbpname of + Just pname -> return pname + Nothing -> do + registerParseError $ FancyError off $ S.singleton $ ErrorFail $ + "missing parameter with keyword ‘as’" + return $ TypedVarName (VarName "") + node <- case mbnode of + Just node -> return node + Nothing -> do + registerParseError $ FancyError off $ S.singleton $ ErrorFail $ + "missing parameter with keyword ‘on’" + return $ Undefined "" + + void eol + void $ L.indentGuard scn GT ref + script <- shellScript + cont <- testBlock ref + return $ TestBlockStep EmptyTestBlock <$> + (SpawnShell pname <$> node <*> script <*> LambdaAbstraction pname cont) + ] exprStatement :: TestParser (Expr (TestBlock ())) exprStatement = do -- cgit v1.2.3