@@ -201,6 +201,8 @@ data Next
201201 = Keyword [Char]
202202 | Operator [Char]
203203 | Close [Char] Char
204+ | Upper Char [Char]
205+ | Lower Char [Char]
204206 | Other (Maybe Char)
205207
206208
@@ -211,25 +213,34 @@ whatIsNext (Source sourceLines) row col =
211213 Other Nothing
212214
213215 Just line ->
214− let
215− chars = drop (fromIntegral col - 1) line
216− keywords = map Name.toChars (Set.toList reservedWords)
217− in
218− case List.find (startsWithKeyword chars) keywords of
219− Just keyword ->
220− Keyword keyword
221−
222− Nothing ->
223− case chars of
224− [] ->
225− Other Nothing
226−
227− c:cs
228− | isSymbol c -> Operator (c : takeWhile isSymbol cs)
229− | c == ')' -> Close "parenthesis" ')'
230− | c == ']' -> Close "square bracket" ']'
231− | c == '}' -> Close "curly brace" '}'
232− | otherwise -> Other (Just c)
216+ case drop (fromIntegral col - 1) line of
217+ [] ->
218+ Other Nothing
219+
220+ c:cs
221+ | Char.isUpper c -> Upper c (takeWhile isInner cs)
222+ | Char.isLower c -> detectKeywords c cs
223+ | isSymbol c -> Operator (c : takeWhile isSymbol cs)
224+ | c == ')' -> Close "parenthesis" ')'
225+ | c == ']' -> Close "square bracket" ']'
226+ | c == '}' -> Close "curly brace" '}'
227+ | otherwise -> Other (Just c)
228+
229+
230+detectKeywords :: Char -> [Char] -> Next
231+detectKeywords c rest =
232+ let
233+ cs = takeWhile isInner rest
234+ name = c : cs
235+ in
236+ if Set.member (Name.fromChars name) reservedWords
237+ then Keyword name
238+ else Lower c name
239+
240+
241+isInner :: Char -> Bool
242+isInner char =
243+ Char.isAlphaNum char || char == '_'
233244
234245
235246isSymbol :: Char -> Bool
@@ -246,7 +257,7 @@ startsWithKeyword restOfLine keyword =
246257 True
247258
248259 c:_ ->
249− not (Char.isAlphaNum c || c == '_')
260+ not (isInner c)
250261
251262
252263nextLineStartsWithKeyword :: [Char] -> Source -> Row -> Maybe (Row, Col)