Add support for coproc

This commit is contained in:
Vidar Holen 2015-01-26 22:21:04 -08:00
parent 895d83afc5
commit a485482979
3 changed files with 35 additions and 2 deletions

View file

@ -1459,7 +1459,11 @@ readPipe = do
spacing
return $ T_Pipe id ('|':qualifier)
readCommand = readCompoundCommand <|> readSimpleCommand
readCommand = choice [
readCompoundCommand,
readCoProc,
readSimpleCommand
]
readCmdName = do
f <- readNormalWord
@ -1797,6 +1801,26 @@ readFunctionDefinition = called "function" $ do
readFunctionName = many functionChars
prop_readCoProc1 = isOk readCoProc "coproc foo { echo bar; }"
prop_readCoProc2 = isOk readCoProc "coproc { echo bar; }"
prop_readCoProc3 = isOk readCoProc "coproc echo bar"
readCoProc = called "coproc" $ do
id <- getNextId
try $ do
string "coproc"
whitespace
choice [ try $ readCompoundCoProc id, readSimpleCoProc id ]
where
readCompoundCoProc id = do
var <- optionMaybe $
readVariableName `thenSkip` whitespace
body <- readCompoundCommand
return $ T_CoProc id var body
readSimpleCoProc id = do
body <- readSimpleCommand
return $ T_CoProc id Nothing body
readPattern = (readNormalWord `thenSkip` spacing) `sepBy1` (char '|' `thenSkip` spacing)
prop_readCompoundCommand = isOk readCompoundCommand "{ echo foo; }>/dev/null"