Skip to content

Commit

Permalink
Merge pull request #4019 from masatake/haskell--handle-newline-just-a…
Browse files Browse the repository at this point in the history
…fter-id

Haskell: skip multi-line type signature
  • Loading branch information
masatake committed Jun 17, 2024
2 parents ec69d6f + 7456573 commit 8976ec3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions Units/parser-haskell.r/multi-line-type-signature.d/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Taken from #4013 submitted by Robin Palotai (@robinp).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Foo input.hs /^module Foo () where$/;" m
thing input.hs /^thing x = pure x$/;" f
9 changes: 9 additions & 0 deletions Units/parser-haskell.r/multi-line-type-signature.d/input.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Foo () where


thing
:: App m
=> Int
-> m Int
thing x = pure x

35 changes: 31 additions & 4 deletions parsers/haskell.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "routines.h"


#define HASKELL_STRMAXLEN 1000
/*
* DATA DEFINITIONS
*/
Expand Down Expand Up @@ -64,7 +65,7 @@ static int get_line(char *buf)
do {
c = getcFromInputFile();
buf[i++] = c;
} while (c != EOF && c != '\n' && i < 1000);
} while (c != EOF && c != '\n' && i < HASKELL_STRMAXLEN);
buf[i] = '\0';
return i;
}
Expand Down Expand Up @@ -114,7 +115,7 @@ static int get_token(char *token, int n)
{
int c = getcFromInputFile();
int i = n;
while (c != EOF && isident(c) && i < 1000) {
while (c != EOF && isident(c) && i < HASKELL_STRMAXLEN) {
token[i] = c;
i++;
c = getcFromInputFile();
Expand All @@ -136,7 +137,7 @@ static int inside_datatype(vString *name)
{
enum Find_State st = Find_Eq;
int c;
char token[1001];
char token[HASKELL_STRMAXLEN + 1];

while (1) {
if (st == Find_Eq)
Expand Down Expand Up @@ -221,7 +222,7 @@ static int inside_datatype(vString *name)
static void findHaskellTags (int is_literate)
{
vString *name = vStringNew ();
char token[1001], arg[1001];
char token[HASKELL_STRMAXLEN + 1], arg[HASKELL_STRMAXLEN + 1];
int c;
int in_tex_lit_code = 0;
c = get_next_char();
Expand Down Expand Up @@ -310,6 +311,32 @@ static void findHaskellTags (int is_literate)
strcmp(token, "import") == 0)
;
else {
/*
* "::" can be after [\n][ \t]+
* ------------------------------
* thing
* :: App m
* => Int
* -> m Int
* ------------------------------
* Skip them to find ':'.
*/
if (arg[0] == '\n' && arg[1] == '\0') {
bool indented = false;
while (1)
{
if ((c = getcFromInputFile()) == EOF)
return;
if (!isspace(c))
break;
indented = true;
}
if (indented)
arg[0] = c;
else
ungetcToInputFile(c);
}

if (arg[0] != ':')
add_tag(token, K_FUNCTION, name);
}
Expand Down

0 comments on commit 8976ec3

Please sign in to comment.