[pure-lang-svn] SF.net SVN: pure-lang:[709] pure/trunk
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-09-05 02:01:32
|
Revision: 709
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=709&view=rev
Author: agraef
Date: 2008-09-05 02:01:42 +0000 (Fri, 05 Sep 2008)
Log Message:
-----------
Warn about used identifiers which are also interactive commands.
Modified Paths:
--------------
pure/trunk/ChangeLog
pure/trunk/lexer.ll
Modified: pure/trunk/ChangeLog
===================================================================
--- pure/trunk/ChangeLog 2008-09-05 01:12:59 UTC (rev 708)
+++ pure/trunk/ChangeLog 2008-09-05 02:01:42 UTC (rev 709)
@@ -1,5 +1,8 @@
2008-09-05 Albert Graef <Dr....@t-...>
+ * lexer.ll: Warn about used identifiers which are also interactive
+ commands.
+
* printer.cc: Changed <<...>> syntax for "external" objects such
as closures, thunks and pointers to #<...> syntax pilfered from
Scheme. This is less likely to be mistaken for a valid Pure
Modified: pure/trunk/lexer.ll
===================================================================
--- pure/trunk/lexer.ll 2008-09-05 01:12:59 UTC (rev 708)
+++ pure/trunk/lexer.ll 2008-09-05 02:01:42 UTC (rev 709)
@@ -215,6 +215,27 @@
free(matches);
}
}
+
+static void check(const yy::location& l, const char* s)
+{
+ static set<string> done;
+ const char *name;
+ size_t i = 0;
+ while ((name = commands[i++]))
+ /* We warn about each identifier at most once. FIXME: We should also check
+ whether the interpreter is running in (global) interactive mode, but at
+ present this information isn't available before we actually enter the
+ interactive loop, when all source files from the command line have
+ already been processed. */
+ if (strcmp(name, s) == 0 && done.find(s) == done.end()) {
+ assert(interpreter::g_interp);
+ interpreter& interp = *interpreter::g_interp;
+ interp.warning(l, "warning: identifier '"+string(s)+
+ "' is also an interpreter command");
+ done.insert(s);
+ return;
+ }
+}
%}
%option noyywrap nounput debug
@@ -257,7 +278,7 @@
<comment>[\n]+ yylloc->lines(yyleng); yylloc->step();
<comment>"*"+"/" yylloc->step(); BEGIN(INITIAL);
-<xdecl>{id} yylval->sval = new string(yytext); return token::ID;
+<xdecl>{id} check(*yylloc, yytext); yylval->sval = new string(yytext); return token::ID;
<xdecl>[()*,=] return yy::parser::token_type(yytext[0]);
<xdecl>"//".* yylloc->step();
<xdecl>"/*" BEGIN(xdecl_comment);
@@ -275,7 +296,7 @@
<xdecl_comment>[\n]+ yylloc->lines(yyleng); yylloc->step();
<xdecl_comment>"*"+"/" yylloc->step(); BEGIN(xdecl);
-<xusing>{id} yylval->sval = new string(yytext); return token::ID;
+<xusing>{id} check(*yylloc, yytext); yylval->sval = new string(yytext); return token::ID;
<xusing>, return yy::parser::token_type(yytext[0]);
<xusing>"//".* yylloc->step();
<xusing>"/*" BEGIN(xusing_comment);
@@ -930,6 +951,7 @@
with return token::WITH;
using BEGIN(xusing); return token::USING;
{id} {
+ check(*yylloc, yytext);
if (interp.declare_op) {
yylval->sval = new string(yytext);
return token::ID;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|