X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FyaccParser%2Fhslexer.flex;h=3c2ab369a44a751b55d8448e87d6ee649d31cf9a;hb=b52838bcf54a3d5d07cf29f17f3af6f584fc0f4e;hp=7d0ce0fc608fe8dcb167c1060104a295c3d4a088;hpb=e7d21ee4f8ac907665a7e170c71d59e13a01da09;p=ghc-hetmet.git diff --git a/ghc/compiler/yaccParser/hslexer.flex b/ghc/compiler/yaccParser/hslexer.flex index 7d0ce0f..3c2ab36 100644 --- a/ghc/compiler/yaccParser/hslexer.flex +++ b/ghc/compiler/yaccParser/hslexer.flex @@ -64,7 +64,7 @@ #define _isconstr(s) (CharTable[*s]&(_C)) BOOLEAN isconstr PROTO((char *)); /* fwd decl */ -unsigned char CharTable[NCHARS] = { +static unsigned char CharTable[NCHARS] = { /* nul */ 0, 0, 0, 0, 0, 0, 0, 0, /* bs */ 0, _S, _S, _S, _S, 0, 0, 0, /* dle */ 0, 0, 0, 0, 0, 0, 0, 0, @@ -115,12 +115,12 @@ char *input_filename = NULL; /* Always points to a dynamically allocated string * have been renamed as hsXXXXX rather than yyXXXXX. --JSM */ -int hslineno = 0; /* Line number at end of token */ +static int hslineno = 0; /* Line number at end of token */ int hsplineno = 0; /* Line number at end of previous token */ -int hscolno = 0; /* Column number at end of token */ +static int hscolno = 0; /* Column number at end of token */ int hspcolno = 0; /* Column number at end of previous token */ -int hsmlcolno = 0; /* Column number for multiple-rule lexemes */ +static int hsmlcolno = 0; /* Column number for multiple-rule lexemes */ int startlineno = 0; /* The line number where something starts */ int endlineno = 0; /* The line number where something ends */ @@ -142,12 +142,15 @@ static int nested_comments; /* For counting comment nesting depth */ /* Essential forward declarations */ -static VOID hsnewid PROTO((char *, int)); -static VOID layout_input PROTO((char *, int)); -static VOID cleartext (NO_ARGS); -static VOID addtext PROTO((char *, unsigned)); -static VOID addchar PROTO((char)); +static void hsnewid PROTO((char *, int)); +static void layout_input PROTO((char *, int)); +static void cleartext (NO_ARGS); +static void addtext PROTO((char *, unsigned)); +static void addchar PROTO((char)); static char *fetchtext PROTO((unsigned *)); +static void new_filename PROTO((char *)); +static int Return PROTO((int)); +static void hsentercontext PROTO((int)); /* Special file handling for IMPORTS */ /* Note: imports only ever go *one deep* (hence no need for a stack) WDP 94/09 */ @@ -384,6 +387,14 @@ NL [\n\r] PUSH_STATE(UserPragma); RETURN(ABSTRACT_UPRAGMA); } +"{-#"{WS}*[A-Z_]+ { + fprintf(stderr, "Warning: \"%s\", line %d: Unrecognised pragma '", + input_filename, hsplineno); + format_string(stderr, (unsigned char *) yytext, yyleng); + fputs("'\n", stderr); + nested_comments = 1; + PUSH_STATE(Comment); + } "#-}" { POP_STATE; RETURN(END_UPRAGMA); } %{ @@ -527,13 +538,18 @@ NL [\n\r] "_TUP_"{D}+ { hsnewid(yytext, yyleng); RETURN(CONID); } [a-z]{i}*"$"[a-z]{i}* { hsnewid(yytext, yyleng); RETURN(TYVAR_TEMPLATE_ID); } -{Id}"#" { +%{ +/* These SHOULDNAE work in "Code" (sigh) */ +%} +{Id}"#" { + if (! (nonstandardFlag || in_interface)) { + char errbuf[ERR_BUF_SIZE]; + sprintf(errbuf, "Non-standard identifier (trailing `#'): %s\n", yytext); + hsperror(errbuf); + } hsnewid(yytext, yyleng); RETURN(_isconstr(yytext) ? CONID : VARID); } -%{ -/* This SHOULDNAE work in "Code" (sigh) */ -%} _+{Id} { if (! (nonstandardFlag || in_interface)) { char errbuf[ERR_BUF_SIZE]; @@ -817,10 +833,14 @@ 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) */ %} -"--".*{NL}{WS}* | +"--".*{NL}?{WS}* | {WS}+ { noGap = FALSE; } %{ @@ -947,11 +967,11 @@ NL [\n\r] This allows unnamed sources to be piped into the parser. */ +extern BOOLEAN acceptPrim; + void -yyinit() +yyinit(void) { - extern BOOLEAN acceptPrim; - input_filename = xstrdup(""); /* We must initialize the input buffer _now_, because we call @@ -964,9 +984,8 @@ yyinit() PUSH_STATE(Code); } -void -new_filename(f) /* This looks pretty dodgy to me (WDP) */ - char *f; +static void +new_filename(char *f) /* This looks pretty dodgy to me (WDP) */ { if (input_filename != NULL) free(input_filename); @@ -986,8 +1005,8 @@ new_filename(f) /* This looks pretty dodgy to me (WDP) */ forcing insertion of ; or } as appropriate */ -BOOLEAN -hsshouldindent() +static BOOLEAN +hsshouldindent(void) { return (!forgetindent && INDENTON); } @@ -995,7 +1014,7 @@ hsshouldindent() /* Enter new context and set new indentation level */ void -hssetindent() +hssetindent(void) { #ifdef HSP_DEBUG fprintf(stderr, "hssetindent:hscolno=%d,hspcolno=%d,INDENTPT[%d]=%d\n", hscolno, hspcolno, icontexts, INDENTPT); @@ -1024,7 +1043,7 @@ hssetindent() /* Enter a new context without changing the indentation level */ void -hsincindent() +hsincindent(void) { #ifdef HSP_DEBUG fprintf(stderr, "hsincindent:hscolno=%d,hspcolno=%d,INDENTPT[%d]=%d\n", hscolno, hspcolno, icontexts, INDENTPT); @@ -1035,16 +1054,15 @@ hsincindent() /* Turn off indentation processing, usually because an explicit "{" has been seen */ void -hsindentoff() +hsindentoff(void) { forgetindent = TRUE; } /* Enter a new layout context. */ -void -hsentercontext(indent) - int indent; +static void +hsentercontext(int indent) { /* Enter new context and set indentation as specified */ if (++icontexts >= MAX_CONTEXTS) { @@ -1063,7 +1081,7 @@ hsentercontext(indent) /* Exit a layout context */ void -hsendindent() +hsendindent(void) { --icontexts; #ifdef HSP_DEBUG @@ -1075,9 +1093,8 @@ hsendindent() * Return checks the indentation level and returns ;, } or the specified token. */ -int -Return(tok) - int tok; +static int +Return(int tok) { #ifdef HSP_DEBUG extern int yyleng; @@ -1174,12 +1191,11 @@ yylex() **********************************************************************/ /* setyyin(file) open file as new lex input buffer */ +extern FILE *yyin; + void -setyyin(file) - char *file; +setyyin(char *file) { - extern FILE *yyin; - hsbuf_save = YY_CURRENT_BUFFER; if ((yyin = fopen(file, "r")) == NULL) { char errbuf[ERR_BUF_SIZE]; @@ -1210,10 +1226,8 @@ setyyin(file) #endif } -static VOID -layout_input(text, len) -char *text; -int len; +static void +layout_input(char *text, int len) { #ifdef HSP_DEBUG fprintf(stderr, "Scanning \"%s\"\n", text); @@ -1243,7 +1257,7 @@ int len; } void -setstartlineno() +setstartlineno(void) { startlineno = hsplineno; #if 1/*etags*/ @@ -1269,8 +1283,8 @@ static struct { char *text; } textcache = { 0, 0, NULL }; -static VOID -cleartext() +static void +cleartext(void) { /* fprintf(stderr, "cleartext\n"); */ textcache.next = 0; @@ -1280,10 +1294,8 @@ cleartext() } } -static VOID -addtext(text, length) -char *text; -unsigned length; +static void +addtext(char *text, unsigned length) { /* fprintf(stderr, "addtext: %d %s\n", length, text); */ @@ -1298,13 +1310,8 @@ unsigned length; textcache.next += length; } -static VOID -#ifdef __STDC__ +static void addchar(char c) -#else -addchar(c) - char c; -#endif { /* fprintf(stderr, "addchar: %c\n", c); */ @@ -1316,8 +1323,7 @@ addchar(c) } static char * -fetchtext(length) -unsigned *length; +fetchtext(unsigned *length) { /* fprintf(stderr, "fetchtext: %d\n", textcache.next); */ @@ -1338,10 +1344,8 @@ unsigned *length; hsnewid Enters an id of length n into the symbol table. */ -static VOID -hsnewid(name, length) -char *name; -int length; +static void +hsnewid(char *name, int length) { char save = name[length]; @@ -1351,8 +1355,7 @@ int length; } BOOLEAN -isconstr(s) /* walks past leading underscores before using the macro */ - char *s; +isconstr(char *s) /* walks past leading underscores before using the macro */ { char *temp = s;