support two double quotes in quoted identifier plus unicode quoted identifier syntax
This commit is contained in:
parent
4e1a1da820
commit
f64632bbac
|
@ -143,6 +143,7 @@ which parses as a typed literal
|
|||
|
||||
> name :: Parser Name
|
||||
> name = choice [QName <$> quotedIdentifier
|
||||
> ,UQName <$> uquotedIdentifier
|
||||
> ,Name <$> identifierBlacklist blacklist]
|
||||
|
||||
> names :: Parser [Name]
|
||||
|
@ -1119,10 +1120,23 @@ make this choice.
|
|||
> nonFirstChar = digit <|> firstChar <?> ""
|
||||
|
||||
> quotedIdentifier :: Parser String
|
||||
> quotedIdentifier = char '"' *> manyTill anyChar doubleQuote
|
||||
> <?> "identifier"
|
||||
> quotedIdentifier = quotedIdenHelper
|
||||
|
||||
TODO: add "" inside quoted identifiers
|
||||
> quotedIdenHelper :: Parser String
|
||||
> quotedIdenHelper =
|
||||
> lexeme (dq *> manyTill anyChar dq >>= optionSuffix moreIden)
|
||||
> <?> "identifier"
|
||||
> where
|
||||
> moreIden s0 = do
|
||||
> void dq
|
||||
> s <- manyTill anyChar dq
|
||||
> optionSuffix moreIden (s0 ++ "\"" ++ s)
|
||||
> dq = char '"' <?> "double quote"
|
||||
|
||||
> uquotedIdentifier :: Parser String
|
||||
> uquotedIdentifier =
|
||||
> try (string "u&" <|> string "U&") *> quotedIdenHelper
|
||||
> <?> "identifier"
|
||||
|
||||
parses an identifier with a : prefix. The : isn't included in the
|
||||
return value
|
||||
|
@ -1163,9 +1177,6 @@ todo: work out the symbol parsing better
|
|||
> semi :: Parser Char
|
||||
> semi = lexeme (char ';') <?> "semicolon"
|
||||
|
||||
> doubleQuote :: Parser Char
|
||||
> doubleQuote = lexeme (char '"') <?> "double quotes"
|
||||
|
||||
> quote :: Parser Char
|
||||
> quote = lexeme (char '\'') <?> "single quote"
|
||||
|
||||
|
|
|
@ -213,9 +213,16 @@ which have been changed to try to improve the layout of the output.
|
|||
> doubleUpQuotes ('\'':cs) = '\'':'\'':doubleUpQuotes cs
|
||||
> doubleUpQuotes (c:cs) = c:doubleUpQuotes cs
|
||||
|
||||
> doubleUpDoubleQuotes :: String -> String
|
||||
> doubleUpDoubleQuotes [] = []
|
||||
> doubleUpDoubleQuotes ('"':cs) = '"':'"':doubleUpDoubleQuotes cs
|
||||
> doubleUpDoubleQuotes (c:cs) = c:doubleUpDoubleQuotes cs
|
||||
|
||||
|
||||
|
||||
> unname :: Name -> String
|
||||
> unname (QName n) = "\"" ++ n ++ "\""
|
||||
> unname (QName n) = "\"" ++ doubleUpDoubleQuotes n ++ "\""
|
||||
> unname (UQName n) = "U&\"" ++ doubleUpDoubleQuotes n ++ "\""
|
||||
> unname (Name n) = n
|
||||
|
||||
> unnames :: [Name] -> String
|
||||
|
@ -223,7 +230,9 @@ which have been changed to try to improve the layout of the output.
|
|||
|
||||
|
||||
> name :: Name -> Doc
|
||||
> name (QName n) = doubleQuotes $ text n
|
||||
> name (QName n) = doubleQuotes $ text $ doubleUpDoubleQuotes n
|
||||
> name (UQName n) =
|
||||
> text "U&" <> doubleQuotes (text $ doubleUpDoubleQuotes n)
|
||||
> name (Name n) = text n
|
||||
|
||||
> names :: [Name] -> Doc
|
||||
|
|
|
@ -155,6 +155,7 @@
|
|||
> -- | Represents an identifier name, which can be quoted or unquoted.
|
||||
> data Name = Name String
|
||||
> | QName String
|
||||
> | UQName String
|
||||
> deriving (Eq,Show,Read,Data,Typeable)
|
||||
|
||||
TODO: add ref and scope, any others?
|
||||
|
|
|
@ -805,9 +805,10 @@ TODO: language identifiers have different rules to generic identifiers
|
|||
> ,("t1",Iden [Name "t1"])
|
||||
> ,("a.b",Iden [Name "a", Name "b"])
|
||||
> ,("a.b.c",Iden [Name "a", Name "b", Name "c"])
|
||||
> -- TODO: quoted idens
|
||||
> -- double double quotes in quoted idens
|
||||
> -- unicode idens syntax (needs escape?)
|
||||
> ,("\"quoted iden\"", Iden [QName "quoted iden"])
|
||||
> ,("\"quoted \"\" iden\"", Iden [QName "quoted \" iden"])
|
||||
> ,("U&\"quoted iden\"", Iden [UQName "quoted iden"])
|
||||
> ,("U&\"quoted \"\" iden\"", Iden [UQName "quoted \" iden"])
|
||||
> ]
|
||||
|
||||
TODO: module stuff
|
||||
|
|
Loading…
Reference in a new issue