Skip to content

Commit

Permalink
Disallow identifier characters after numbers
Browse files Browse the repository at this point in the history
Fixes #180
  • Loading branch information
FPtje committed Jul 1, 2024
1 parent 85dc32a commit 4e48563
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/GLua/Lexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4e48563

Please sign in to comment.