-- // This is the indentation production. It corresponds to the
-- // equivalent number of spaces between the start of a line and the
-- // beginning of the first scalar node. For any two consecutive scalars
-- // preceded by indentation, the second is child of the first one if it
-- // is more indented. Intermixing of spaces and tabs is NOT allowed:
-- // either tabs or spaces should be used for indentation within a
-- // document.

-- //     [10] single_quoted ::= "'" (char_word | char_space | break)* "'"

-- // A quote character that has to be included in the string should be
-- // preceded by '\\'. If the string contains line breaks, leading
-- // spaces on each new line are stripped off. The initial indentation
-- // is defined by the first line after a break. The indentation is
-- // decreased if word characters appear at a lower indentation, but it
-- // is never increased. Lines ending with '\\' are concatenaded. Escape
-- // sequences that are recognized are \\", \\' and \\\\. The character
-- // '\\' should be considered literal in other cases.

-- //     [11] double_quoted ::= '"' (char_word | char_space | break)* '"'

-- // Same rule applies as for [10].

-- FIXME: I still need to handle the described indentation rule


quotedBy q = between qp (qp <?> "end of string") quotedText

  where qp = char q
        quotedText = many ( try escape <|> try stringCharacter )
        stringCharacter = satisfy (\c -> (c/=q) && ( isAllowedChar c || isSpaceChar c) )
        escape = do char '\\'
                    oneOf "\"'\\" <|> (lineBreak >> return ' ')
quotedBy q = between qp (qp <?> "end of string") quotedText

  where qp = char q
        quotedText = many ( try escape <|> try stringCharacter )
        stringCharacter = satisfy (\c -> (c/=q) && ( isAllowedChar c || isSpaceChar c) )
        escape = do char '\\'
                    oneOf "\"'\\" <|> (lineBreak >> return ' ')
quotedBy q = between qp (qp <?> "end of string") quotedText

  where qp = char q
        quotedText = many ( try escape <|> try stringCharacter )
        stringCharacter = satisfy (\c -> (c/=q) && ( isAllowedChar c || isSpaceChar c) )
        escape = do char '\\'
                    oneOf "\"'\\" <|> (lineBreak >> return ' ')