X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fparser%2Fhslexer.flex;h=a5adef34eadcd7e2987821711b6b6013e5d8876d;hb=123f2400f92ba0aaac34340b9276954bd2371743;hp=ab3300e5adbd722272710af480fe0c22e047173e;hpb=ae45ff0e9831a0dc862a5d68d03e355d7e323c62;p=ghc-hetmet.git diff --git a/ghc/compiler/parser/hslexer.flex b/ghc/compiler/parser/hslexer.flex index ab3300e..a5adef3 100644 --- a/ghc/compiler/parser/hslexer.flex +++ b/ghc/compiler/parser/hslexer.flex @@ -7,7 +7,8 @@ * * **********************************************************************/ -#include "../../includes/config.h" +/* The includes/config.h one */ +#include "config.h" #include @@ -254,12 +255,40 @@ NL [\n\r] %% %{ + /* + * Simple comments and whitespace. Normally, we would just ignore these, but + * in case we're processing a string escape, we need to note that we've seen + * a gap. + * + * Note that we cater for a comment line that *doesn't* end in a newline. + * This is incorrect, strictly speaking, but seems like the right thing + * to do. Reported by Rajiv Mirani. (WDP 95/08) + * + * Hackily moved up here so that --<> will match -- SOF 5/97 + */ +%} + +"--"[^\n\r]*{NL}?{WS}* | +{WS}+ { noGap = FALSE; } + +%{ /* * Special GHC pragma rules. Do we need a start state for interface files, * so these won't be matched in source files? --JSM */ + %} +%{ +/* I believe the next rule is not ever matched. + + The '#line ' rule is un-cool, recognising a cpp directive inside hs source. + Driver has now been modified to output `standard' {-# LINE ..-} pragmas + where possible, so the lexer should now never see cpp directives + like '# ' and '#line'. + + -- SOF + ^"# ".*{NL} { char tempf[FILENAME_SIZE]; sscanf(yytext+1, "%d \"%[^\"]", &hslineno, tempf); @@ -273,6 +302,8 @@ NL [\n\r] new_filename(tempf); hsplineno = hslineno; hscolno = 0; hspcolno = 0; } +*/ +%} "{-# LINE ".*"-}"{NL} { /* partain: pragma-style line directive */ @@ -294,21 +325,34 @@ NL [\n\r] PUSH_STATE(UserPragma); RETURN(INLINE_UPRAGMA); } +"{-#"{WS}*"NOINLINE" { + PUSH_STATE(UserPragma); + RETURN(NOINLINE_UPRAGMA); + } "{-#"{WS}*"MAGIC_UNFOLDING" { PUSH_STATE(UserPragma); RETURN(MAGIC_UNFOLDING_UPRAGMA); } -"{-#"{WS}*"DEFOREST" { - PUSH_STATE(UserPragma); - RETURN(DEFOREST_UPRAGMA); - } "{-#"{WS}*"GENERATE_SPECS" { /* these are handled by hscpp */ nested_comments =1; PUSH_STATE(Comment); } +"{-#"{WS}*"OPTIONS" { + /* these are for the driver! */ + nested_comments =1; + PUSH_STATE(Comment); + } +"{-#"{WS}*"SOURCE"{WS}*"#"?"-}" { + /* these are used by `make depend' and the + compiler to indicate that a module should + be imported from source */ + nested_comments =1; + RETURN(SOURCE_UPRAGMA); + } + "{-#"{WS}*[A-Z_]+ { - fprintf(stderr, "\"%s\", line %d: Warning: Unrecognised pragma '", + fprintf(stderr, "%s:%d: Warning: Unrecognised pragma '", input_filename, hsplineno); format_string(stderr, (unsigned char *) yytext, yyleng); fputs("'\n", stderr); @@ -355,6 +399,14 @@ NL [\n\r] "_ccall_GC_" { RETURN(CCALL_GC); } "_casm_" { RETURN(CASM); } "_casm_GC_" { RETURN(CASM_GC); } +"foreign" { RETURN(FOREIGN); } +"export" { RETURN(EXPORT); } +"unsafe" { RETURN(UNSAFE); } +"_stdcall" { RETURN(STDCALL); } +"_ccall" { RETURN(C_CALL); } +"_pascal" { RETURN(PASCAL); } +"_fastcall" { RETURN(FASTCALL); } +"dynamic" { RETURN(DYNAMIC); } %{ /* @@ -381,6 +433,7 @@ NL [\n\r] "<-" { RETURN(LARROW); } "->" { RETURN(RARROW); } "-" { RETURN(MINUS); } +"+" { RETURN(PLUS); } "=>" { RETURN(DARROW); } "@" { RETURN(AT); } @@ -461,8 +514,8 @@ NL [\n\r] %{ /* These SHOULDNAE work in "Code" (sigh) */ %} -{Id}"#" { - if (! nonstandardFlag) { +{Id}"#" { + if (! nonstandardFlag) { char errbuf[ERR_BUF_SIZE]; sprintf(errbuf, "Non-standard identifier (trailing `#'): %s\n", yytext); hsperror(errbuf); @@ -478,6 +531,16 @@ NL [\n\r] hsnewid(yytext, yyleng); RETURN(isconstr(yytext) ? CONSYM : VARSYM); } +{Mod}"."{Id}"#" { + BOOLEAN is_constr; + if (! nonstandardFlag) { + char errbuf[ERR_BUF_SIZE]; + sprintf(errbuf, "Non-standard identifier (trailing `#'): %s\n", yytext); + hsperror(errbuf); + } + is_constr = hsnewqid(yytext, yyleng); + RETURN(is_constr ? QCONID : QVARID); + } {Mod}"."{Id} { BOOLEAN is_constr = hsnewqid(yytext, yyleng); RETURN(is_constr ? QCONID : QVARID); @@ -548,7 +611,7 @@ NL [\n\r] } if (length > 1) { - fprintf(stderr, "\"%s\", line %d, column %d: Unboxed character literal '", + fprintf(stderr, "%s:%d:%d: Unboxed character literal '", input_filename, hsplineno, hspcolno + 1); format_string(stderr, (unsigned char *) text, length); fputs("' too long\n", stderr); @@ -567,7 +630,7 @@ NL [\n\r] text = fetchtext(&length); if (length > 1) { - fprintf(stderr, "\"%s\", line %d, column %d: Character literal '", + fprintf(stderr, "%s:%d:%d: Character literal '", input_filename, hsplineno, hspcolno + 1); format_string(stderr, (unsigned char *) text, length); fputs("' too long\n", stderr); @@ -746,20 +809,6 @@ NL [\n\r] POP_STATE; } -%{ - /* - * Simple comments and whitespace. Normally, we would just ignore these, but - * in case we're processing a string escape, we need to note that we've seen - * a gap. - * - * Note that we cater for a comment line that *doesn't* end in a newline. - * This is incorrect, strictly speaking, but seems like the right thing - * to do. Reported by Rajiv Mirani. (WDP 95/08) - */ -%} - -"--".*{NL}?{WS}* | -{WS}+ { noGap = FALSE; } %{ /* @@ -789,21 +838,21 @@ NL [\n\r] %} (.|\n) { - fprintf(stderr, "\"%s\", line %d, column %d: Illegal character: `", + fprintf(stderr, "%s:%d:%d: Illegal character: `", input_filename, hsplineno, hspcolno + 1); format_string(stderr, (unsigned char *) yytext, 1); fputs("'\n", stderr); hsperror(""); } (.|\n) { - fprintf(stderr, "\"%s\", line %d, column %d: Illegal character: `", + fprintf(stderr, "%s:%d:%d: Illegal character: `", input_filename, hsplineno, hspcolno + 1); format_string(stderr, (unsigned char *) yytext, 1); fputs("' in a character literal\n", stderr); hsperror(""); } (.|\n) { - fprintf(stderr, "\"%s\", line %d, column %d: Illegal character escape: `\\", + fprintf(stderr, "%s:%d:%d: Illegal character escape: `\\", input_filename, hsplineno, hspcolno + 1); format_string(stderr, (unsigned char *) yytext, 1); fputs("'\n", stderr); @@ -812,7 +861,7 @@ NL [\n\r] (.|\n) { if (nonstandardFlag) { addtext(yytext, yyleng); } else { - fprintf(stderr, "\"%s\", line %d, column %d: Illegal character: `", + fprintf(stderr, "%s:%d:%d: Illegal character: `", input_filename, hsplineno, hspcolno + 1); format_string(stderr, (unsigned char *) yytext, 1); fputs("' in a string literal\n", stderr); @@ -821,13 +870,13 @@ NL [\n\r] } (.|\n) { if (noGap) { - fprintf(stderr, "\"%s\", line %d, column %d: Illegal string escape: `\\", + fprintf(stderr, "%s:%d:%d: Illegal string escape: `\\", input_filename, hsplineno, hspcolno + 1); format_string(stderr, (unsigned char *) yytext, 1); fputs("'\n", stderr); hsperror(""); } else { - fprintf(stderr, "\"%s\", line %d, column %d: Illegal character: `", + fprintf(stderr, "%s:%d:%d: Illegal character: `", input_filename, hsplineno, hspcolno + 1); format_string(stderr, (unsigned char *) yytext, 1); fputs("' in a string gap\n", stderr);