Skip to content

Commit 7456573

Browse files
committed
Haskell: skip multi-line type signature
Close #4013. The original logic extract "thing" in thing :: App m => Int -> m Int as a function because the parser cannot find : after "thing" in the line. The test case is taken from #4013 submitted by @robinp. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 2c717bf commit 7456573

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Taken from #4013 submitted by Robin Palotai (@robinp).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--sort=no
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Foo input.hs /^module Foo () where$/;" m
2+
thing input.hs /^thing x = pure x$/;" f
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Foo () where
2+
3+
4+
thing
5+
:: App m
6+
=> Int
7+
-> m Int
8+
thing x = pure x
9+

parsers/haskell.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,32 @@ static void findHaskellTags (int is_literate)
311311
strcmp(token, "import") == 0)
312312
;
313313
else {
314+
/*
315+
* "::" can be after [\n][ \t]+
316+
* ------------------------------
317+
* thing
318+
* :: App m
319+
* => Int
320+
* -> m Int
321+
* ------------------------------
322+
* Skip them to find ':'.
323+
*/
324+
if (arg[0] == '\n' && arg[1] == '\0') {
325+
bool indented = false;
326+
while (1)
327+
{
328+
if ((c = getcFromInputFile()) == EOF)
329+
return;
330+
if (!isspace(c))
331+
break;
332+
indented = true;
333+
}
334+
if (indented)
335+
arg[0] = c;
336+
else
337+
ungetcToInputFile(c);
338+
}
339+
314340
if (arg[0] != ':')
315341
add_tag(token, K_FUNCTION, name);
316342
}

0 commit comments

Comments
 (0)