diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-09-25 18:52:00 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-09-25 18:52:00 -0300 |
commit | 0af581f0bf5a7d0d67803a1a25959a53d5bb6cda (patch) | |
tree | 308955cc0ef9a22e3447b44fcf0d244d3965a50e /lex.c | |
parent | 2a506ea9d2ed9531352c91a4930bf80549e2e495 (diff) | |
download | lua-0af581f0bf5a7d0d67803a1a25959a53d5bb6cda.tar.gz lua-0af581f0bf5a7d0d67803a1a25959a53d5bb6cda.tar.bz2 lua-0af581f0bf5a7d0d67803a1a25959a53d5bb6cda.zip |
new way to handle pragmas (at the lexical level, instead of parsing).
Diffstat (limited to 'lex.c')
-rw-r--r-- | lex.c | 58 |
1 files changed, 33 insertions, 25 deletions
@@ -1,4 +1,4 @@ | |||
1 | char *rcs_lex = "$Id: lex.c,v 2.34 1996/05/30 14:04:07 roberto Exp roberto $"; | 1 | char *rcs_lex = "$Id: lex.c,v 2.35 1996/09/09 14:11:11 roberto Exp roberto $"; |
2 | 2 | ||
3 | 3 | ||
4 | #include <ctype.h> | 4 | #include <ctype.h> |
@@ -25,7 +25,8 @@ static Input input; /* input function */ | |||
25 | 25 | ||
26 | void lua_setinput (Input fn) | 26 | void lua_setinput (Input fn) |
27 | { | 27 | { |
28 | current = ' '; | 28 | current = '\n'; |
29 | lua_linenumber = 0; | ||
29 | input = fn; | 30 | input = fn; |
30 | } | 31 | } |
31 | 32 | ||
@@ -71,6 +72,26 @@ void luaI_addReserved (void) | |||
71 | } | 72 | } |
72 | } | 73 | } |
73 | 74 | ||
75 | static int inclinenumber (void) | ||
76 | { | ||
77 | if (current == '$') { /* is a pragma? */ | ||
78 | char buff[MINBUFF]; | ||
79 | int i = 0; | ||
80 | next(); /* skip $ */ | ||
81 | while (isalnum(current)) { | ||
82 | if (i >= MINBUFF) lua_error("pragma too long"); | ||
83 | buff[i++] = current; | ||
84 | next(); | ||
85 | } | ||
86 | buff[i] = 0; | ||
87 | if (strcmp(buff, "debug") == 0) | ||
88 | lua_debug = 1; | ||
89 | else if (strcmp(buff, "nodebug") == 0) | ||
90 | lua_debug = 0; | ||
91 | else lua_error("invalid pragma"); | ||
92 | } | ||
93 | return ++lua_linenumber; | ||
94 | } | ||
74 | 95 | ||
75 | static int read_long_string (char *yytext, int buffsize) | 96 | static int read_long_string (char *yytext, int buffsize) |
76 | { | 97 | { |
@@ -103,7 +124,9 @@ static int read_long_string (char *yytext, int buffsize) | |||
103 | } | 124 | } |
104 | continue; | 125 | continue; |
105 | case '\n': | 126 | case '\n': |
106 | lua_linenumber++; /* goes through */ | 127 | save_and_next(); |
128 | inclinenumber(); | ||
129 | continue; | ||
107 | default: | 130 | default: |
108 | save_and_next(); | 131 | save_and_next(); |
109 | } | 132 | } |
@@ -131,29 +154,14 @@ int luaY_lex (void) | |||
131 | int tokensize = 0; | 154 | int tokensize = 0; |
132 | switch (current) | 155 | switch (current) |
133 | { | 156 | { |
134 | case '\n': linelasttoken = ++lua_linenumber; | 157 | case '\n': |
135 | case ' ': | ||
136 | case '\r': /* CR: to avoid problems with DOS/Windows */ | ||
137 | case '\t': | ||
138 | next(); | 158 | next(); |
159 | linelasttoken = inclinenumber(); | ||
139 | continue; | 160 | continue; |
140 | 161 | ||
141 | case '$': | 162 | case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */ |
142 | save_and_next(); | 163 | next(); |
143 | while (isalnum(current) || current == '_') | 164 | continue; |
144 | save_and_next(); | ||
145 | save(0); | ||
146 | if (strcmp(yytext+1, "debug") == 0) | ||
147 | { | ||
148 | luaY_lval.vInt = 1; | ||
149 | return DEBUG; | ||
150 | } | ||
151 | else if (strcmp(yytext+1, "nodebug") == 0) | ||
152 | { | ||
153 | luaY_lval.vInt = 0; | ||
154 | return DEBUG; | ||
155 | } | ||
156 | return WRONGTOKEN; | ||
157 | 165 | ||
158 | case '-': | 166 | case '-': |
159 | save_and_next(); | 167 | save_and_next(); |
@@ -212,8 +220,8 @@ int luaY_lex (void) | |||
212 | case 'n': save('\n'); next(); break; | 220 | case 'n': save('\n'); next(); break; |
213 | case 't': save('\t'); next(); break; | 221 | case 't': save('\t'); next(); break; |
214 | case 'r': save('\r'); next(); break; | 222 | case 'r': save('\r'); next(); break; |
215 | case '\n': lua_linenumber++; /* goes through */ | 223 | case '\n': save_and_next(); inclinenumber(); break; |
216 | default : save(current); next(); break; | 224 | default : save_and_next(); break; |
217 | } | 225 | } |
218 | break; | 226 | break; |
219 | default: | 227 | default: |