Skip to content

Commit

Permalink
Fix lex error on string like "\z"
Browse files Browse the repository at this point in the history
  • Loading branch information
FPtje committed Apr 15, 2023
1 parent 253eb99 commit f8733b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/GLua/Lexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ import Text.ParserCombinators.UU.BasicInstances
-- | String parser that maintains positions.
type LParser a = P (Str Char String LineColPos) a

-- | Whitespace parser.
-- | Whitespace parser that requires at least one whitespace character
parseWhitespace :: LParser String
parseWhitespace = pSome $ pSatisfy (`elem` " \r\n\t") (Insertion "Whitespace" ' ' 5)
--MToken <$> pPos <*> (Whitespace <$> pMunch (`elem` " \r\n\t"))

-- | Whitespace parser that requires 0 or more whitespace characters
parseOptionalWhitespace :: LParser String
parseOptionalWhitespace = pMany $ pSatisfy (`elem` " \r\n\t") (Insertion "Whitespace" ' ' 5)

-- | Blanco parser. Parses anything. Used in parsing comments.
parseAnyChar :: LParser Char
Expand Down Expand Up @@ -148,7 +151,7 @@ parseLineString c = pSym c *> innerString
(:) <$> pNoNewline <*> innerString -- the next character in the string

escapeSequence :: LParser String
escapeSequence = (:) <$> pSym 'z' <*> parseWhitespace <<|> (:[]) <$> parseAnyChar
escapeSequence = (:) <$> pSym 'z' <*> parseOptionalWhitespace <<|> (:[]) <$> parseAnyChar

pNoNewline :: LParser Char
pNoNewline = pSatisfy (/= '\n') (Insertion "Anything but a newline" c 5)
Expand Down
8 changes: 6 additions & 2 deletions src/GLua/PSLexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,20 @@ cBetween c left right = c >= left && c <= right
pUntilEnd :: Parser String
pUntilEnd = manyTill anyChar (lookAhead (endOfLine <|> const '\n' <$> eof))

-- | Whitespace parser.
-- | Whitespace parser that requires at least one whitespace character
parseWhitespace :: Parser String
parseWhitespace = many1 space <?> "whitespace"

-- | Whitespace parser that requires 0 or more whitespace characters
parseOptionalWhitespace :: Parser String
parseOptionalWhitespace = many space <?> "whitespace"

-- | An escaped character of a single line string
-- Takes the delimiter of the string as parameter
escapedStringChar :: Char -> Parser String
escapedStringChar delim = (\escaped -> '\\' : escaped) <$ char '\\' <*> escapedChar <|> (:[]) <$> noneOf ['\n', delim]
where
escapedChar = (:) <$> char 'z' <*> parseWhitespace <|> (:[]) <$> anyChar
escapedChar = (:) <$> char 'z' <*> parseOptionalWhitespace <|> (:[]) <$> anyChar

-- | The start of a nested string
-- Returns the amount of =-signs at the start of the nested string
Expand Down

0 comments on commit f8733b1

Please sign in to comment.