blob: 4bcc0c8ac8b9dd8bf525edb4299e69206b96eda2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
module Haddock.Backends.Hyperlinker.Parser (parse) where
data Token = Token
{ tkType :: TokenType
, tkValue :: String
, tkSpan :: Span
}
data Position = Position
{ posRow :: !Int
, posCol :: !Int
}
data Span = Span
{ spStart :: Position
, spEnd :: Position
}
data TokenType
= Identifier
| Comment
| Whitespace
| Operator
| Symbol
parse :: String -> [Token]
parse = tokenize . tag . chunk
chunk :: String -> [String]
chunk = undefined
tag :: [String] -> [(Span, String)]
tag =
reverse . snd . foldl aux (Position 1 1, [])
where
aux (pos, cs) c =
let pos' = if c == "\n"
then pos { posRow = posRow pos + 1, posCol = 1 }
else pos { posCol = posCol pos + length c }
in (pos', (Span pos pos', c):cs)
tokenize :: [(Span, String)] -> [Token]
tokenize = undefined
|