aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_lexer.l
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-09 10:57:30 +1000
committerDavid Walter Seikel2012-01-09 10:57:30 +1000
commit1239d06619142c24c835a89862518b024789420c (patch)
tree70c03d552352439b1869fc6f1cbf1c198312ec90 /LuaSL/src/LuaSL_lexer.l
parentMoved yyerror() into the flex source. Added a count function, CHAR, STRING, ... (diff)
downloadSledjHamr-1239d06619142c24c835a89862518b024789420c.zip
SledjHamr-1239d06619142c24c835a89862518b024789420c.tar.gz
SledjHamr-1239d06619142c24c835a89862518b024789420c.tar.bz2
SledjHamr-1239d06619142c24c835a89862518b024789420c.tar.xz
The other half of the comment scanner.
Diffstat (limited to 'LuaSL/src/LuaSL_lexer.l')
-rw-r--r--LuaSL/src/LuaSL_lexer.l19
1 files changed, 16 insertions, 3 deletions
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l
index 291d0c9..3728ab9 100644
--- a/LuaSL/src/LuaSL_lexer.l
+++ b/LuaSL/src/LuaSL_lexer.l
@@ -4,6 +4,7 @@
4#include "LuaSL_LSL_tree.h" 4#include "LuaSL_LSL_tree.h"
5#include <stdio.h> 5#include <stdio.h>
6 6
7void comment(yyscan_t yyscanner);
7void count(char *text); 8void count(char *text);
8 9
9#ifdef LUASL_DEBUG 10#ifdef LUASL_DEBUG
@@ -36,8 +37,8 @@ NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])*
36 37
37 /* White space. */ 38 /* White space. */
38[[:space:]]+ %{ ECHO; /* yylval->spaceValue = strdup(yytext); return LSL_SPACE; */ %} 39[[:space:]]+ %{ ECHO; /* yylval->spaceValue = strdup(yytext); return LSL_SPACE; */ %}
39"/*" %{ /* count(); comment(); */ %} 40"/*" %{ ECHO; comment(yyscanner); %}
40"//"[^\n]* %{ /* consume //-comment */ %} 41"//"[^\n]* %{ ECHO; /* consume //-comment */ %}
41 42
42 /* Operations. */ 43 /* Operations. */
43"&&" { ECHO; return LSL_BOOL_AND; } 44"&&" { ECHO; return LSL_BOOL_AND; }
@@ -116,6 +117,19 @@ NAME [[:alpha:]](_|[[:alpha:]]|[[:digit:]])*
116 117
117%% 118%%
118 119
120void comment(yyscan_t yyscanner)
121{
122 char c, prev = 0;
123
124 while ((c = input(yyscanner)) != 0) /* (EOF maps to 0) */
125 {
126 if (c == '/' && prev == '*')
127 return;
128 prev = c;
129 }
130 yyerror("unterminated comment");
131}
132
119int column = 0; 133int column = 0;
120int line = 0; 134int line = 0;
121 135
@@ -147,7 +161,6 @@ int yywrap(yyscan_t yyscanner)
147 #ifndef LL_WINDOWS 161 #ifndef LL_WINDOWS
148 // Get gcc to stop complaining about lack of use of yyunput and input. 162 // Get gcc to stop complaining about lack of use of yyunput and input.
149 (void) yyunput; 163 (void) yyunput;
150 (void) input;
151 #endif 164 #endif
152#endif 165#endif
153// TODO - If we are getting files from stdin, or multiple -f arguments, we should loop through them and return 0. Return 1 when there are no more files. 166// TODO - If we are getting files from stdin, or multiple -f arguments, we should loop through them and return 0. Return 1 when there are no more files.