# HG changeset patch # User jwe # Date 1129897517 0 # Node ID d0a24bfe4487df313613289d2bae166965261cc3 # Parent 08448daec2935651fd15d6b029ca51fe61ec8139 [project @ 2005-10-21 12:25:16 by jwe] diff -r 08448daec293 -r d0a24bfe4487 src/ChangeLog --- a/src/ChangeLog Thu Oct 20 20:56:59 2005 +0000 +++ b/src/ChangeLog Fri Oct 21 12:25:17 2005 +0000 @@ -1,3 +1,9 @@ +2005-10-21 John W. Eaton + + * DLD-FUNCTIONS/gplot.l (read_until): Special case STRING. + (handle_string): Restore function. + ("'", "\""): Call handle string when matching these tokens.. + 2005-10-20 John W. Eaton * pt-mat.cc (tm_row_const::all_real): New data member. diff -r 08448daec293 -r d0a24bfe4487 src/DLD-FUNCTIONS/gplot.l --- a/src/DLD-FUNCTIONS/gplot.l Thu Oct 20 20:56:59 2005 +0000 +++ b/src/DLD-FUNCTIONS/gplot.l Fri Oct 21 12:25:17 2005 +0000 @@ -121,6 +121,9 @@ static int is_plot_keyword (const std::string& s); +static int handle_string (char delim); +static std::string strbuf; + %} D [0-9] @@ -197,11 +200,14 @@ { gpt_quote_is_transpose = true; gpt_allow_plotkw = true; - warning ("unknown token = \"%s\" in plot command", yytext); - return OTHER; + return handle_string ('\''); } } +"\"" { + return handle_string ('"'); + } + {IDENT} { int itok = 0; if (can_be_plotkw () && (itok = is_plot_keyword (yytext))) @@ -308,6 +314,69 @@ return 0; } +// This is used to handle character strings. Kludge alert. + +static int +handle_string (char delim) +{ + int c; + bool escape_pending = false; + + strbuf = std::string (1, delim); + + while ((c = yyinput ()) != EOF) + { + if (c == '\\') + { + if (escape_pending) + { + strbuf += static_cast (c); + escape_pending = false; + } + else + { + strbuf += static_cast (c); + escape_pending = true; + } + continue; + } + else if (c == '\n') + { + error ("unterminated string constant"); + break; + } + else if (c == delim) + { + if (escape_pending) + strbuf += static_cast (c); + else + { + c = yyinput (); + + if (c == delim) + { + strbuf += static_cast (c); + strbuf += static_cast (c); + } + else + { + yyunput (c, yytext); + strbuf += static_cast (delim); + return STRING; + } + } + } + else + strbuf += static_cast (c); + + escape_pending = false; + } + + throw gpt_parse_error ("unterminated string"); + + return 0; +} + // (Probably not necessesary, but current Matlab style plot functions // break without this (they emit too short gnuplot commands)) @@ -446,7 +515,7 @@ break; } - s += std::string (yytext) + " "; + s += (tok == STRING ? strbuf : std::string (yytext)) + " "; tok = gptlex (); }