on master help sign in
Support extraction of doc comments
931c665Evan Czaplicki
compiler/src/Parse/Space.hs+18−9
@@ -10,6 +10,7 @@ module Parse.Space
10 , checkAligned
10 , checkAligned
11 , checkFreshLine
11 , checkFreshLine
12 --
12 --
13+ , DocComment(..)
13 , docComment
14 , docComment
14 )
15 )
15 where
16 where
@@ -87,7 +88,7 @@ checkFreshLine toError =
87
88
88
89
89chompAndCheckIndent :: (E.Space -> Row -> Col -> x) -> (Row -> Col -> x) -> P.Parser x ()
90chompAndCheckIndent :: (E.Space -> Row -> Col -> x) -> (Row -> Col -> x) -> P.Parser x ()
90−chompAndCheckIndent toWhitespaceError toIndentError =
91+chompAndCheckIndent toSpaceError toIndentError =
91 P.Parser $ \(P.State pos end indent row col) cok _ cerr _ ->
92 P.Parser $ \(P.State pos end indent row col) cok _ cerr _ ->
92 let
93 let
93 (# status, newPos, newRow, newCol #) = eatSpaces pos end row col
94 (# status, newPos, newRow, newCol #) = eatSpaces pos end row col
@@ -105,9 +106,9 @@ chompAndCheckIndent toWhitespaceError toIndentError =
105 else
106 else
106 cerr row col toIndentError
107 cerr row col toIndentError
107
108
108− HasTab -> cerr newRow newCol (toWhitespaceError E.HasTab)
109+ HasTab -> cerr newRow newCol (toSpaceError E.HasTab)
109− EndlessMultiComment -> cerr newRow newCol (toWhitespaceError E.EndlessMultiComment)
110+ EndlessMultiComment -> cerr newRow newCol (toSpaceError E.EndlessMultiComment)
110− UnexpectedDocComment -> cerr newRow newCol (toWhitespaceError E.UnexpectedDocComment)
111+ UnexpectedDocComment -> cerr newRow newCol (toSpaceError E.UnexpectedDocComment)
111
112
112
113
113
114
@@ -240,8 +241,15 @@ eatMultiCommentHelp pos end row col openComments =
240-- DOCUMENTATION COMMENT
241-- DOCUMENTATION COMMENT
241
242
242
243
244+data DocComment =
245+ DocComment
246+ { _start :: Ptr Word8
247+ , _end :: Ptr Word8
248+ }
249+
250+
243−docComment :: (Row -> Col -> x) -> (Row -> Col -> x) -> (Row -> Col -> x) -> P.Parser x ()
251+docComment :: (Row -> Col -> x) -> (E.Space -> Row -> Col -> x) -> P.Parser x DocComment
244−docComment toExpectation toTabError toEndlessError =
252+docComment toExpectation toSpaceError =
245 P.Parser $ \(P.State pos end indent row col) cok _ cerr eerr ->
253 P.Parser $ \(P.State pos end indent row col) cok _ cerr eerr ->
246 let
254 let
247 !pos3 = plusPtr pos 3
255 !pos3 = plusPtr pos 3
@@ -258,11 +266,12 @@ docComment toExpectation toTabError toEndlessError =
258 case status of
266 case status of
259 MultiGood ->
267 MultiGood ->
260 let
268 let
269+ !comment = DocComment pos3 (plusPtr newPos (-2))
261 !newState = P.State newPos end indent newRow newCol
270 !newState = P.State newPos end indent newRow newCol
262 in
271 in
263− cok () newState
272+ cok comment newState
264
273
265− MultiTab -> cerr newRow newCol toTabError
274+ MultiTab -> cerr newRow newCol (toSpaceError E.HasTab)
266− MultiEndless -> cerr row col toEndlessError
275+ MultiEndless -> cerr row col (toSpaceError E.EndlessMultiComment)
267 else
276 else
268 eerr row col toExpectation
277 eerr row col toExpectation