From 4e4856362fb7ce7412236278a58f29e916b0636f Mon Sep 17 00:00:00 2001 From: Falco Peijnenburg Date: Mon, 1 Jul 2024 21:53:05 +0200 Subject: [PATCH] Disallow identifier characters after numbers Fixes #180 --- src/GLua/Lexer.hs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/GLua/Lexer.hs b/src/GLua/Lexer.hs index 40235a8..8ffc859 100644 --- a/src/GLua/Lexer.hs +++ b/src/GLua/Lexer.hs @@ -66,22 +66,17 @@ pIdentifierCharacter :: Parser Char pIdentifierCharacter = satisfy validChar where validChar :: Char -> Bool - validChar c = - cBetween c '0' '9' - || cBetween c 'A' 'Z' - || c == '_' - || cBetween c 'a' 'z' - || ord c >= 128 + validChar c = cBetween c '0' '9' || nonDigitIdentifierCharacter c pNonDigitIdentifierCharacter :: Parser Char -pNonDigitIdentifierCharacter = satisfy validChar - where - validChar :: Char -> Bool - validChar c = - cBetween c 'A' 'Z' - || c == '_' - || cBetween c 'a' 'z' - || ord c >= 128 +pNonDigitIdentifierCharacter = satisfy nonDigitIdentifierCharacter + +nonDigitIdentifierCharacter :: Char -> Bool +nonDigitIdentifierCharacter c = + cBetween c 'A' 'Z' + || c == '_' + || cBetween c 'a' 'z' + || ord c >= 128 cBetween :: Char -> Char -> Char -> Bool cBetween c left right = c >= left && c <= right @@ -166,7 +161,7 @@ parseString = -- | Parse any kind of number. -- Except for numbers that start with a '.'. That's handled by parseDots to solve ambiguity. parseNumber :: Parser Token -parseNumber = TNumber <$> ((++) <$> (pHexadecimal <|> pBinary <|> pNumber) <*> (pLLULL <|> option "" parseNumberSuffix)) "Number" +parseNumber = TNumber <$> ((++) <$> (pHexadecimal <|> pBinary <|> pNumber) <*> (pLLULL <|> option "" parseNumberSuffix)) <* lookAhead (satisfy $ not . nonDigitIdentifierCharacter) "Number" where pNumber :: Parser String pNumber = (++) <$> many1 digit <*> option "" pDecimal