@@ -594,24 +594,46 @@ apostrophe = do
594594quoted = do
595595 doubleQuoted <|> singleQuoted
596596
597−singleQuoted = try (do
598− result <- enclosed singleQuoteStart singleQuoteEnd
599− (do{notFollowedBy' singleQuoted; inline} <|> apostrophe)
600− return $ Quoted SingleQuote $ normalizeSpaces result)
601−
602−doubleQuoted = try (do
603− result <- enclosed doubleQuoteStart doubleQuoteEnd inline
604− return $ Quoted DoubleQuote $ normalizeSpaces result)
597+withQuoteContext context parser = do
598+ oldState <- getState
599+ let oldQuoteContext = stateQuoteContext oldState
600+ setState oldState { stateQuoteContext = context }
601+ result <- parser
602+ newState <- getState
603+ setState newState { stateQuoteContext = oldQuoteContext }
604+ return result
605+
606+singleQuoted = try $ do
607+ singleQuoteStart
608+ withQuoteContext InSingleQuote $ do
609+ notFollowedBy space
610+ result <- many1Till inline singleQuoteEnd
611+ return $ Quoted SingleQuote $ normalizeSpaces result
612+
613+doubleQuoted = try $ do
614+ doubleQuoteStart
615+ withQuoteContext InDoubleQuote $ do
616+ notFollowedBy space
617+ result <- many1Till inline doubleQuoteEnd
618+ return $ Quoted DoubleQuote $ normalizeSpaces result
619+
620+failIfInQuoteContext context = do
621+ st <- getState
622+ if (stateQuoteContext st == context)
623+ then fail "already inside quotes"
624+ else return ()
605625
606−singleQuoteStart = try (do
626+singleQuoteStart = do
627+ failIfInQuoteContext InSingleQuote
607628 char '\'' <|> char '\8216'
608− notFollowedBy' whitespace)
609629
610630singleQuoteEnd = try (do
611− oneOfStrings ["'", "\8217"]
631+ char '\'' <|> char '\8217'
612632 notFollowedBy alphaNum)
613633
614−doubleQuoteStart = char '"' <|> char '\8220'
634+doubleQuoteStart = do
635+ failIfInQuoteContext InDoubleQuote
636+ char '"' <|> char '\8220'
615637
616638doubleQuoteEnd = char '"' <|> char '\8221'
617639
@@ -623,7 +645,7 @@ dash = enDash <|> emDash
623645
624646enDash = try (do
625647 char '-'
626− followedBy' (many1 digit)
648+ notFollowedBy (noneOf "0123456789")
627649 return EnDash)
628650
629651emDash = try (do