@@ -2795,17 +2795,29 @@ readFunctionDefinition = called "function" $ do
2795
2795
prop_readCoProc1 = isOk readCoProc " coproc foo { echo bar; }"
2796
2796
prop_readCoProc2 = isOk readCoProc " coproc { echo bar; }"
2797
2797
prop_readCoProc3 = isOk readCoProc " coproc echo bar"
2798
+ prop_readCoProc4 = isOk readCoProc " coproc a=b echo bar"
2799
+ prop_readCoProc5 = isOk readCoProc " coproc 'foo' { echo bar; }"
2800
+ prop_readCoProc6 = isOk readCoProc " coproc \" foo$$\" { echo bar; }"
2801
+ prop_readCoProc7 = isOk readCoProc " coproc 'foo' ( echo bar )"
2802
+ prop_readCoProc8 = isOk readCoProc " coproc \" foo$$\" while true; do true; done"
2798
2803
readCoProc = called " coproc" $ do
2799
2804
start <- startSpan
2800
2805
try $ do
2801
2806
string " coproc"
2802
- whitespace
2807
+ spacing1
2803
2808
choice [ try $ readCompoundCoProc start, readSimpleCoProc start ]
2804
2809
where
2805
2810
readCompoundCoProc start = do
2806
- var <- optionMaybe $
2807
- readVariableName `thenSkip` whitespace
2808
- body <- readBody readCompoundCommand
2811
+ notFollowedBy2 readAssignmentWord
2812
+ (var, body) <- choice [
2813
+ try $ do
2814
+ body <- readBody readCompoundCommand
2815
+ return (Nothing , body),
2816
+ try $ do
2817
+ var <- readNormalWord `thenSkip` spacing
2818
+ body <- readBody readCompoundCommand
2819
+ return (Just var, body)
2820
+ ]
2809
2821
id <- endSpan start
2810
2822
return $ T_CoProc id var body
2811
2823
readSimpleCoProc start = do
@@ -3436,13 +3448,22 @@ isOk p s = parsesCleanly p s == Just True -- The string parses with no wa
3436
3448
isWarning p s = parsesCleanly p s == Just False -- The string parses with warnings
3437
3449
isNotOk p s = parsesCleanly p s == Nothing -- The string does not parse
3438
3450
3439
- parsesCleanly parser string = runIdentity $ do
3451
+ -- If the parser matches the string, return Right [ParseNotes+ParseProblems]
3452
+ -- If it does not match the string, return Left [ParseProblems]
3453
+ getParseOutput parser string = runIdentity $ do
3440
3454
(res, sys) <- runParser testEnvironment
3441
3455
(parser >> eof >> getState) " -" string
3442
3456
case (res, sys) of
3443
3457
(Right userState, systemState) ->
3444
- return $ Just . null $ parseNotes userState ++ parseProblems systemState
3445
- (Left _, _) -> return Nothing
3458
+ return $ Right $ parseNotes userState ++ parseProblems systemState
3459
+ (Left _, systemState) -> return $ Left $ parseProblems systemState
3460
+
3461
+ -- If the parser matches the string, return Just whether it was clean (without emitting suggestions)
3462
+ -- Otherwise, Nothing
3463
+ parsesCleanly parser string =
3464
+ case getParseOutput parser string of
3465
+ Right list -> Just $ null list
3466
+ Left _ -> Nothing
3446
3467
3447
3468
parseWithNotes parser = do
3448
3469
item <- parser
0 commit comments