lua-users home
lua-l archive

Re: patch: C-style string lexing

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I've attached a very small patch that let's you do something very
similar to this but syntactically different from C. It allows you to
do the following:
a = "a piece of a string
 "another piece
 "the end";
print(a) --> a piece of a string another piece the end
Basically, once it reaches a new line (instead of erroring like
default lua), it instead looks for a string delimiter ignoring white
space, and then continues lexing the string. It's completely backwards
compatible with core Lua now as far as I can tell.
-- 
-Patrick Donnelly
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."
-Will Durant
--- llex.c	2008年01月31日 15:58:44.000000000 -0700
+++ llex.new.c	2008年01月31日 13:38:31.000000000 -0700
@@ -282,7 +282,19 @@
 continue; /* to avoid warnings */
 case '\n':
 case '\r':
- luaX_lexerror(ls, "unfinished string", TK_STRING);
+ next(ls);
+ while (ls->current != del) {
+ switch (ls->current) {
+ case '\t': /* only allow whitespace */
+ case ' ':
+ break;
+ default: 
+ luaX_lexerror(ls, "unfinished string", TK_STRING);
+ continue; /* to avoid warnings */
+ }
+ next(ls);
+ }
+ next(ls);
 continue; /* to avoid warnings */
 case '\\': {
 int c;

AltStyle によって変換されたページ (->オリジナル) /