Skip to content

Commit 8976ec3

Browse files
authored
Merge pull request #4019 from masatake/haskell--handle-newline-just-after-id
Haskell: skip multi-line type signature
2 parents ec69d6f + 7456573 commit 8976ec3

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
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: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "routines.h"
2828

2929

30+
#define HASKELL_STRMAXLEN 1000
3031
/*
3132
* DATA DEFINITIONS
3233
*/
@@ -64,7 +65,7 @@ static int get_line(char *buf)
6465
do {
6566
c = getcFromInputFile();
6667
buf[i++] = c;
67-
} while (c != EOF && c != '\n' && i < 1000);
68+
} while (c != EOF && c != '\n' && i < HASKELL_STRMAXLEN);
6869
buf[i] = '\0';
6970
return i;
7071
}
@@ -114,7 +115,7 @@ static int get_token(char *token, int n)
114115
{
115116
int c = getcFromInputFile();
116117
int i = n;
117-
while (c != EOF && isident(c) && i < 1000) {
118+
while (c != EOF && isident(c) && i < HASKELL_STRMAXLEN) {
118119
token[i] = c;
119120
i++;
120121
c = getcFromInputFile();
@@ -136,7 +137,7 @@ static int inside_datatype(vString *name)
136137
{
137138
enum Find_State st = Find_Eq;
138139
int c;
139-
char token[1001];
140+
char token[HASKELL_STRMAXLEN + 1];
140141

141142
while (1) {
142143
if (st == Find_Eq)
@@ -221,7 +222,7 @@ static int inside_datatype(vString *name)
221222
static void findHaskellTags (int is_literate)
222223
{
223224
vString *name = vStringNew ();
224-
char token[1001], arg[1001];
225+
char token[HASKELL_STRMAXLEN + 1], arg[HASKELL_STRMAXLEN + 1];
225226
int c;
226227
int in_tex_lit_code = 0;
227228
c = get_next_char();
@@ -310,6 +311,32 @@ static void findHaskellTags (int is_literate)
310311
strcmp(token, "import") == 0)
311312
;
312313
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+
313340
if (arg[0] != ':')
314341
add_tag(token, K_FUNCTION, name);
315342
}

0 commit comments

Comments
 (0)