lib: Refactor common comment parsers
This commit is contained in:
		
							parent
							
								
									c2199b1125
								
							
						
					
					
						commit
						b06d22a418
					
				| @ -795,25 +795,25 @@ whitespaceChar = charCategory Space | |||||||
| --- ** comments | --- ** comments | ||||||
| 
 | 
 | ||||||
| multilinecommentp :: JournalParser m () | multilinecommentp :: JournalParser m () | ||||||
| multilinecommentp = do | multilinecommentp = startComment *> anyLine `skipManyTill` endComment | ||||||
|   string "comment" >> lift (skipMany spacenonewline) >> newline |  | ||||||
|   go |  | ||||||
|   where |   where | ||||||
|     go = try (eof <|> (string "end comment" >> newline >> return ())) |     emptylinep = lift (skipMany spacenonewline) *> newline *> pure () | ||||||
|          <|> (anyLine >> go) |     startComment = string "comment" >> emptylinep | ||||||
|  |     endComment = eof <|> (string "end comment" >> emptylinep) | ||||||
|     anyLine = anyChar `manyTill` newline |     anyLine = anyChar `manyTill` newline | ||||||
| 
 | 
 | ||||||
| emptyorcommentlinep :: JournalParser m () | emptyorcommentlinep :: JournalParser m () | ||||||
| emptyorcommentlinep = do | emptyorcommentlinep = do | ||||||
|   lift (skipMany spacenonewline) >> (linecommentp <|> (lift (skipMany spacenonewline) >> newline >> return "")) |   lift (skipMany spacenonewline) | ||||||
|   return () |   void linecommentp <|> void newline | ||||||
| 
 | 
 | ||||||
| -- | Parse a possibly multi-line comment following a semicolon. | -- | Parse a possibly multi-line comment following a semicolon. | ||||||
| followingcommentp :: JournalParser m Text | followingcommentp :: JournalParser m Text | ||||||
| followingcommentp = | followingcommentp = do | ||||||
|   -- ptrace "followingcommentp" |   -- ptrace "followingcommentp" | ||||||
|   do samelinecomment <- lift (skipMany spacenonewline) >> (try commentp <|> (newline >> return "")) |   lift (skipMany spacenonewline) | ||||||
|      newlinecomments <- many (try (lift (skipSome spacenonewline) >> commentp)) |   samelinecomment <- try commentp <|> (newline >> return "") | ||||||
|  |   newlinecomments <- many $ try $ lift (skipSome spacenonewline) >> commentp | ||||||
|   return $ T.unlines $ samelinecomment:newlinecomments |   return $ T.unlines $ samelinecomment:newlinecomments | ||||||
| 
 | 
 | ||||||
| -- | Parse a possibly multi-line comment following a semicolon, and | -- | Parse a possibly multi-line comment following a semicolon, and | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user