]> git.lyx.org Git - lyx.git/blob - src/Lexer.cpp
pimpl not needed here
[lyx.git] / src / Lexer.cpp
1 /**
2  * \file Lexer.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "Lexer.h"
17
18 #include "debug.h"
19
20 #include "support/convert.h"
21 #include "support/filetools.h"
22 #include "support/gzstream.h"
23 #include "support/lstrings.h"
24 #include "support/lyxalgo.h"
25 #include "support/types.h"
26 #include "support/unicode.h"
27
28 #include <boost/noncopyable.hpp>
29
30 #include <functional>
31 #include <istream>
32 #include <stack>
33 #include <sstream>
34 #include <vector>
35
36
37 namespace lyx {
38
39 using support::compare_ascii_no_case;
40 using support::FileName;
41 using support::isStrDbl;
42 using support::isStrInt;
43 using support::ltrim;
44 using support::makeDisplayPath;
45 using support::prefixIs;
46 using support::split;
47 using support::subst;
48 using support::trim;
49
50 using std::endl;
51 using std::getline;
52 using std::lower_bound;
53 using std::sort;
54 using std::string;
55 using std::ios;
56 using std::istream;
57 using std::ostream;
58
59
60 //////////////////////////////////////////////////////////////////////
61 //
62 // Lexer::Pimpl
63 //
64 //////////////////////////////////////////////////////////////////////
65
66
67 ///
68 class Lexer::Pimpl : boost::noncopyable {
69 public:
70         ///
71         Pimpl(keyword_item * tab, int num);
72         ///
73         std::string const getString() const;
74         ///
75         docstring const getDocString() const;
76         ///
77         void printError(std::string const & message) const;
78         ///
79         void printTable(std::ostream & os);
80         ///
81         void pushTable(keyword_item * tab, int num);
82         ///
83         void popTable();
84         ///
85         bool setFile(support::FileName const & filename);
86         ///
87         void setStream(std::istream & i);
88         ///
89         void setCommentChar(char c);
90         ///
91         bool next(bool esc = false);
92         ///
93         int search_kw(char const * const tag) const;
94         ///
95         int lex();
96         ///
97         bool eatLine();
98         ///
99         bool nextToken();
100         /// test if there is a pushed token or the stream is ok
101         bool inputAvailable();
102         ///
103         void pushToken(std::string const &);
104         /// fb_ is only used to open files, the stream is accessed through is.
105         std::filebuf fb_;
106
107         /// gz_ is only used to open files, the stream is accessed through is.
108         gz::gzstreambuf gz_;
109
110         /// the stream that we use.
111         std::istream is;
112         ///
113         std::string name;
114         ///
115         keyword_item * table;
116         ///
117         int no_items;
118         ///
119         std::string buff;
120         ///
121         int status;
122         ///
123         int lineno;
124         ///
125         std::string pushTok;
126         ///
127         char commentChar;
128 private:
129         ///
130         void verifyTable();
131         ///
132         class pushed_table {
133         public:
134                 ///
135                 pushed_table()
136                         : table_elem(0), table_siz(0) {}
137                 ///
138                 pushed_table(keyword_item * ki, int siz)
139                         : table_elem(ki), table_siz(siz) {}
140                 ///
141                 keyword_item * table_elem;
142                 ///
143                 int table_siz;
144         };
145         ///
146         std::stack<pushed_table> pushed;
147 };
148
149
150
151 namespace {
152
153 class compare_tags
154         : public std::binary_function<keyword_item, keyword_item, bool> {
155 public:
156         // used by lower_bound, sort and sorted
157         bool operator()(keyword_item const & a, keyword_item const & b) const
158         {
159                 // we use the ascii version, because in turkish, 'i'
160                 // is not the lowercase version of 'I', and thus
161                 // turkish locale breaks parsing of tags.
162                 return compare_ascii_no_case(a.tag, b.tag) < 0;
163         }
164 };
165
166 } // end of anon namespace
167
168
169 Lexer::Pimpl::Pimpl(keyword_item * tab, int num)
170         : is(&fb_), table(tab), no_items(num),
171           status(0), lineno(0), commentChar('#')
172 {
173         verifyTable();
174 }
175
176
177 string const Lexer::Pimpl::getString() const
178 {
179         return buff;
180 }
181
182
183 docstring const Lexer::Pimpl::getDocString() const
184 {
185         return from_utf8(buff);
186 }
187
188
189 void Lexer::Pimpl::printError(string const & message) const
190 {
191         string const tmpmsg = subst(message, "$$Token", getString());
192         lyxerr << "LyX: " << tmpmsg << " [around line " << lineno
193                 << " of file " << to_utf8(makeDisplayPath(name)) << ']' << endl;
194 }
195
196
197 void Lexer::Pimpl::printTable(ostream & os)
198 {
199         os << "\nNumber of tags: " << no_items << endl;
200         for (int i= 0; i < no_items; ++i)
201                 os << "table[" << i
202                    << "]:  tag: `" << table[i].tag
203                    << "'  code:" << table[i].code << '\n';
204         os.flush();
205 }
206
207
208 void Lexer::Pimpl::verifyTable()
209 {
210         // Check if the table is sorted and if not, sort it.
211         if (table
212             && !lyx::sorted(table, table + no_items, compare_tags())) {
213                 lyxerr << "The table passed to Lexer is not sorted!\n"
214                        << "Tell the developers to fix it!" << endl;
215                 // We sort it anyway to avoid problems.
216                 lyxerr << "\nUnsorted:" << endl;
217                 printTable(lyxerr);
218
219                 sort(table, table + no_items, compare_tags());
220                 lyxerr << "\nSorted:" << endl;
221                 printTable(lyxerr);
222         }
223 }
224
225
226 void Lexer::Pimpl::pushTable(keyword_item * tab, int num)
227 {
228         pushed_table tmppu(table, no_items);
229         pushed.push(tmppu);
230
231         table = tab;
232         no_items = num;
233
234         verifyTable();
235 }
236
237
238 void Lexer::Pimpl::popTable()
239 {
240         if (pushed.empty()) {
241                 lyxerr << "Lexer error: nothing to pop!" << endl;
242                 return;
243         }
244
245         pushed_table tmp = pushed.top();
246         pushed.pop();
247         table = tmp.table_elem;
248         no_items = tmp.table_siz;
249 }
250
251
252 bool Lexer::Pimpl::setFile(FileName const & filename)
253 {
254         // Check the format of the file.
255         string const format = filename.guessFormatFromContents();
256
257         if (format == "gzip" || format == "zip" || format == "compress") {
258                 LYXERR(Debug::LYXLEX) << "lyxlex: compressed" << endl;
259                 // The check only outputs a debug message, because it triggers
260                 // a bug in compaq cxx 6.2, where is_open() returns 'true' for
261                 // a fresh new filebuf.  (JMarc)
262                 if (gz_.is_open() || istream::off_type(is.tellg()) > -1)
263                         lyxerr[Debug::LYXLEX] << "Error in LyXLex::setFile: "
264                                 "file or stream already set." << endl;
265                 gz_.open(filename.toFilesystemEncoding().c_str(), ios::in);
266                 is.rdbuf(&gz_);
267                 name = filename.absFilename();
268                 lineno = 0;
269                 return gz_.is_open() && is.good();
270         } else {
271                 LYXERR(Debug::LYXLEX) << "lyxlex: UNcompressed" << endl;
272
273                 // The check only outputs a debug message, because it triggers
274                 // a bug in compaq cxx 6.2, where is_open() returns 'true' for
275                 // a fresh new filebuf.  (JMarc)
276                 if (fb_.is_open() || istream::off_type(is.tellg()) > 0) {
277                         LYXERR(Debug::LYXLEX) << "Error in Lexer::setFile: "
278                                 "file or stream already set." << endl;
279                 }
280                 fb_.open(filename.toFilesystemEncoding().c_str(), ios::in);
281                 is.rdbuf(&fb_);
282                 name = filename.absFilename();
283                 lineno = 0;
284                 return fb_.is_open() && is.good();
285         }
286 }
287
288
289 void Lexer::Pimpl::setStream(istream & i)
290 {
291         if (fb_.is_open() || istream::off_type(is.tellg()) > 0) {
292                 LYXERR(Debug::LYXLEX)  << "Error in Lexer::setStream: "
293                         "file or stream already set." << endl;
294         }
295         is.rdbuf(i.rdbuf());
296         lineno = 0;
297 }
298
299
300 void Lexer::Pimpl::setCommentChar(char c)
301 {
302         commentChar = c;
303 }
304
305
306 bool Lexer::Pimpl::next(bool esc /* = false */)
307 {
308         if (!pushTok.empty()) {
309                 // There can have been a whole line pushed so
310                 // we extract the first word and leaves the rest
311                 // in pushTok. (Lgb)
312                 if (pushTok[0] == '\\' && pushTok.find(' ') != string::npos) {
313                         buff.clear();
314                         pushTok = split(pushTok, buff, ' ');
315                 } else {
316                         buff = pushTok;
317                         pushTok.clear();
318                 }
319                 status = LEX_TOKEN;
320                 return true;
321         }
322         if (!esc) {
323                 unsigned char c = 0; // getc() returns an int
324                 char cc = 0;
325                 status = 0;
326                 while (is && !status) {
327                         is.get(cc);
328                         c = cc;
329                         if (c == commentChar) {
330                                 // Read rest of line (fast :-)
331 #if 1
332                                 // That is not fast... (Lgb)
333                                 string dummy;
334                                 getline(is, dummy);
335
336                                 LYXERR(Debug::LYXLEX) << "Comment read: `" << c
337                                                       << dummy << '\'' << endl;
338 #else
339                                 // unfortunately ignore is buggy (Lgb)
340                                 is.ignore(100, '\n');
341 #endif
342                                 ++lineno;
343                                 continue;
344                         }
345
346                         if (c == '\"') {
347                                 buff.clear();
348
349                                 do {
350                                         is.get(cc);
351                                         c = cc;
352                                         if (c != '\r')
353                                                 buff.push_back(c);
354                                 } while (c != '\"' && c != '\n' && is);
355
356                                 if (c != '\"') {
357                                         printError("Missing quote");
358                                         if (c == '\n')
359                                                 ++lineno;
360                                 }
361
362                                 buff.resize(buff.size()-1);
363                                 status = LEX_DATA;
364                                 break;
365                         }
366
367                         if (c == ',')
368                                 continue;              /* Skip ','s */
369
370                                 // using relational operators with chars other
371                                 // than == and != is not safe. And if it is done
372                                 // the type _have_ to be unsigned. It usually a
373                                 // lot better to use the functions from cctype
374                         if (c > ' ' && is)  {
375                                 buff.clear();
376
377                                 do {
378                                         buff.push_back(c);
379                                         is.get(cc);
380                                         c = cc;
381                                 } while (c > ' ' && c != ',' && is);
382
383                                 status = LEX_TOKEN;
384                         }
385
386                         if (c == '\r' && is) {
387                                 // The Windows support has lead to the
388                                 // possibility of "\r\n" at the end of
389                                 // a line.  This will stop LyX choking
390                                 // when it expected to find a '\n'
391                                 is.get(cc);
392                                 c = cc;
393                         }
394
395                         if (c == '\n')
396                                 ++lineno;
397
398                 }
399                 if (status)
400                         return true;
401
402                 status = is.eof() ? LEX_FEOF: LEX_UNDEF;
403                 buff.clear();
404                 return false;
405         } else {
406                 unsigned char c = 0; // getc() returns an int
407                 char cc = 0;
408
409                 status = 0;
410                 while (is && !status) {
411                         is.get(cc);
412                         c = cc;
413
414                         // skip ','s
415                         if (c == ',')
416                                 continue;
417
418                         if (c == commentChar) {
419                                 // Read rest of line (fast :-)
420 #if 1
421                                 // That is still not fast... (Lgb)
422                                 string dummy;
423                                 getline(is, dummy);
424
425                                 LYXERR(Debug::LYXLEX) << "Comment read: `" << c
426                                                       << dummy << '\'' << endl;
427 #else
428                                 // but ignore is also still buggy (Lgb)
429                                 // This is fast (Lgb)
430                                 is.ignore(100, '\n');
431 #endif
432                                 ++lineno;
433                                 continue;
434                         }
435
436                         // string
437                         if (c == '\"') {
438                                 buff.clear();
439
440                                 bool escaped = false;
441                                 do {
442                                         escaped = false;
443                                         is.get(cc);
444                                         c = cc;
445                                         if (c == '\r') continue;
446                                         if (c == '\\') {
447                                                 // escape the next char
448                                                 is.get(cc);
449                                                 c = cc;
450                                                 if (c == '\"' || c == '\\')
451                                                         escaped = true;
452                                                 else
453                                                         buff.push_back('\\');
454                                         }
455                                         buff.push_back(c);
456
457                                         if (!escaped && c == '\"')
458                                                 break;
459                                 } while (c != '\n' && is);
460
461                                 if (c != '\"') {
462                                         printError("Missing quote");
463                                         if (c == '\n')
464                                                 ++lineno;
465                                 }
466
467                                 buff.resize(buff.size() -1);
468                                 status = LEX_DATA;
469                                 break;
470                         }
471
472                         if (c > ' ' && is) {
473                                 buff.clear();
474
475                                 do {
476                                         if (c == '\\') {
477                                                 // escape the next char
478                                                 is.get(cc);
479                                                 c = cc;
480                                                 //escaped = true;
481                                         }
482                                         buff.push_back(c);
483                                         is.get(cc);
484                                         c = cc;
485                                 } while (c > ' ' && c != ',' && is);
486
487                                 status = LEX_TOKEN;
488                         }
489                         // new line
490                         if (c == '\n')
491                                 ++lineno;
492                 }
493
494                 if (status)
495                         return true;
496
497                 status = is.eof() ? LEX_FEOF : LEX_UNDEF;
498                 buff.clear();
499                 return false;
500         }
501 }
502
503
504 int Lexer::Pimpl::search_kw(char const * const tag) const
505 {
506         keyword_item search_tag = { tag, 0 };
507         keyword_item * res =
508                 lower_bound(table, table + no_items,
509                             search_tag, compare_tags());
510         // use the compare_ascii_no_case instead of compare_no_case,
511         // because in turkish, 'i' is not the lowercase version of 'I',
512         // and thus turkish locale breaks parsing of tags.
513         if (res != table + no_items
514             && !compare_ascii_no_case(res->tag, tag))
515                 return res->code;
516         return LEX_UNDEF;
517 }
518
519
520 int Lexer::Pimpl::lex()
521 {
522         //NOTE: possible bug.
523         if (next() && status == LEX_TOKEN)
524                 return search_kw(getString().c_str());
525         return status;
526 }
527
528
529 bool Lexer::Pimpl::eatLine()
530 {
531         buff.clear();
532
533         unsigned char c = '\0';
534         char cc = 0;
535         while (is && c != '\n') {
536                 is.get(cc);
537                 c = cc;
538                 //LYXERR(Debug::LYXLEX) << "Lexer::EatLine read char: `"
539                 //                    << c << '\'' << endl;
540                 if (c != '\r')
541                         buff.push_back(c);
542         }
543
544         if (c == '\n') {
545                 ++lineno;
546                 buff.resize(buff.size() - 1);
547                 status = LEX_DATA;
548                 return true;
549         } else if (buff.length() > 0) { // last line
550                 status = LEX_DATA;
551                 return true;
552         } else {
553                 return false;
554         }
555 }
556
557
558 bool Lexer::Pimpl::nextToken()
559 {
560         if (!pushTok.empty()) {
561                 // There can have been a whole line pushed so
562                 // we extract the first word and leaves the rest
563                 // in pushTok. (Lgb)
564                 if (pushTok[0] == '\\' && pushTok.find(' ') != string::npos) {
565                         buff.clear();
566                         pushTok = split(pushTok, buff, ' ');
567                 } else {
568                         buff = pushTok;
569                         pushTok.clear();
570                 }
571                 status = LEX_TOKEN;
572                 return true;
573         }
574
575         status = 0;
576         while (is && !status) {
577                 unsigned char c = 0;
578                 char cc = 0;
579                 is.get(cc);
580                 c = cc;
581                 if (c >= ' ' && is) {
582                         buff.clear();
583
584                         if (c == '\\') { // first char == '\\'
585                                 do {
586                                         buff.push_back(c);
587                                         is.get(cc);
588                                         c = cc;
589                                 } while (c > ' ' && c != '\\' && is);
590                         } else {
591                                 do {
592                                         buff.push_back(c);
593                                         is.get(cc);
594                                         c = cc;
595                                 } while (c >= ' ' && c != '\\' && is);
596                         }
597
598                         if (c == '\\') is.putback(c); // put it back
599                         status = LEX_TOKEN;
600                 }
601
602                 if (c == '\n')
603                         ++lineno;
604
605         }
606         if (status)
607                 return true;
608
609         status = is.eof() ? LEX_FEOF: LEX_UNDEF;
610         buff.clear();
611         return false;
612 }
613
614
615 bool Lexer::Pimpl::inputAvailable()
616 {
617         return is.good();
618 }
619
620
621 void Lexer::Pimpl::pushToken(string const & pt)
622 {
623         pushTok = pt;
624 }
625
626
627
628
629 //////////////////////////////////////////////////////////////////////
630 //
631 // Lexer
632 //
633 //////////////////////////////////////////////////////////////////////
634
635 Lexer::Lexer(keyword_item * tab, int num)
636         : pimpl_(new Pimpl(tab, num))
637 {}
638
639
640 Lexer::~Lexer()
641 {
642         delete pimpl_;
643 }
644
645
646 bool Lexer::isOK() const
647 {
648         return pimpl_->inputAvailable();
649 }
650
651
652 void Lexer::setLineNo(int l)
653 {
654         pimpl_->lineno = l;
655 }
656
657
658 int Lexer::getLineNo() const
659 {
660         return pimpl_->lineno;
661 }
662
663
664 istream & Lexer::getStream()
665 {
666         return pimpl_->is;
667 }
668
669
670 void Lexer::pushTable(keyword_item * tab, int num)
671 {
672         pimpl_->pushTable(tab, num);
673 }
674
675
676 void Lexer::popTable()
677 {
678         pimpl_->popTable();
679 }
680
681
682 void Lexer::printTable(ostream & os)
683 {
684         pimpl_->printTable(os);
685 }
686
687
688 void Lexer::printError(string const & message) const
689 {
690         pimpl_->printError(message);
691 }
692
693
694 bool Lexer::setFile(support::FileName const & filename)
695 {
696         return pimpl_->setFile(filename);
697 }
698
699
700 void Lexer::setStream(istream & i)
701 {
702         pimpl_->setStream(i);
703 }
704
705
706 void Lexer::setCommentChar(char c)
707 {
708         pimpl_->setCommentChar(c);
709 }
710
711 int Lexer::lex()
712 {
713         return pimpl_->lex();
714 }
715
716
717 int Lexer::getInteger() const
718 {
719         lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
720         if (!lastReadOk_) {
721                 pimpl_->printError("integer token missing");
722                 return -1;
723         }
724
725         if (isStrInt(pimpl_->getString()))
726                 return convert<int>(pimpl_->getString());
727
728         lastReadOk_ = false;
729         pimpl_->printError("Bad integer `$$Token'");
730         return -1;
731 }
732
733
734 double Lexer::getFloat() const
735 {
736         // replace comma with dot in case the file was written with
737         // the wrong locale (should be rare, but is easy enough to
738         // avoid).
739         lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
740         if (!lastReadOk_) {
741                 pimpl_->printError("float token missing");
742                 return -1;
743         }
744
745         string const str = subst(pimpl_->getString(), ",", ".");
746         if (isStrDbl(str))
747                 return convert<double>(str);
748
749         lastReadOk_ = false;
750         pimpl_->printError("Bad float `$$Token'");
751         return -1;
752 }
753
754
755 string const Lexer::getString() const
756 {
757         lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
758
759         if (lastReadOk_)
760         return pimpl_->getString();
761
762         return string();
763 }
764
765
766 docstring const Lexer::getDocString() const
767 {
768         lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
769
770         if (lastReadOk_)
771                 return pimpl_->getDocString();
772
773         return docstring();
774 }
775
776
777 // I would prefer to give a tag number instead of an explicit token
778 // here, but it is not possible because Buffer::readDocument uses
779 // explicit tokens (JMarc)
780 string const Lexer::getLongString(string const & endtoken)
781 {
782         string str, prefix;
783         bool firstline = true;
784
785         while (pimpl_->is) { //< eatLine only reads from is, not from pushTok
786                 if (!eatLine())
787                         // blank line in the file being read
788                         continue;
789
790                 string const token = trim(getString(), " \t");
791
792                 LYXERR(Debug::PARSER) << "LongString: `"
793                                       << getString() << '\'' << endl;
794
795                 // We do a case independent comparison, like search_kw does.
796                 if (compare_ascii_no_case(token, endtoken) == 0)
797                         break;
798
799                 string tmpstr = getString();
800                 if (firstline) {
801                         string::size_type i(tmpstr.find_first_not_of(' '));
802                         if (i != string::npos)
803                                 prefix = tmpstr.substr(0, i);
804                         firstline = false;
805                         LYXERR(Debug::PARSER)
806                                 << "Prefix = `" << prefix << "\'" << endl;
807                 }
808
809                 // further lines in long strings may have the same
810                 // whitespace prefix as the first line. Remove it.
811                 if (prefix.length() && prefixIs(tmpstr, prefix)) {
812                         tmpstr.erase(0, prefix.length() - 1);
813                 }
814
815                 str += ltrim(tmpstr, "\t") + '\n';
816         }
817
818         if (!pimpl_->is) {
819                 printError("Long string not ended by `" + endtoken + '\'');
820         }
821
822         return str;
823 }
824
825
826 bool Lexer::getBool() const
827 {
828         if (pimpl_->getString() == "true") {
829                 lastReadOk_ = true;
830                 return true;
831         } else if (pimpl_->getString() != "false") {
832                 pimpl_->printError("Bad boolean `$$Token'. "
833                                    "Use \"false\" or \"true\"");
834                 lastReadOk_ = false;
835         }
836         lastReadOk_ = true;
837         return false;
838 }
839
840
841 bool Lexer::eatLine()
842 {
843         return pimpl_->eatLine();
844 }
845
846
847 bool Lexer::next(bool esc)
848 {
849         return pimpl_->next(esc);
850 }
851
852
853 bool Lexer::nextToken()
854 {
855         return pimpl_->nextToken();
856 }
857
858
859 void Lexer::pushToken(string const & pt)
860 {
861         pimpl_->pushToken(pt);
862 }
863
864
865 Lexer::operator void const *() const
866 {
867         // This behaviour is NOT the same as the std::streams which would
868         // use fail() here. However, our implementation of getString() et al.
869         // can cause the eof() and fail() bits to be set, even though we
870         // haven't tried to read 'em.
871         return lastReadOk_? this : 0;
872 }
873
874
875 bool Lexer::operator!() const
876 {
877         return !lastReadOk_;
878 }
879
880
881 Lexer & Lexer::operator>>(std::string & s)
882 {
883         if (isOK()) {
884                 next();
885                 s = getString();
886         } else {
887                 lastReadOk_ = false;
888         }
889         return *this;
890 }
891
892
893 Lexer & Lexer::operator>>(docstring & s)
894 {
895         if (isOK()) {
896                 next();
897                 s = getDocString();
898         } else {
899                 lastReadOk_ = false;
900         }
901         return *this;
902 }
903
904
905 Lexer & Lexer::operator>>(double & s)
906 {
907         if (isOK()) {
908                 next();
909                 s = getFloat();
910         } else {
911                 lastReadOk_ = false;
912         }
913         return *this;
914 }
915
916
917 Lexer & Lexer::operator>>(int & s)
918 {
919         if (isOK()) {
920                 next();
921                 s = getInteger();
922         } else {
923                 lastReadOk_ = false;
924         }
925         return *this;
926 }
927
928
929 Lexer & Lexer::operator>>(unsigned int & s)
930 {
931         if (isOK()) {
932                 next();
933                 s = getInteger();
934         } else {
935                 lastReadOk_ = false;
936         }
937         return *this;
938 }
939
940
941 Lexer & Lexer::operator>>(bool & s)
942 {
943         if (isOK()) {
944                 next();
945                 s = getBool();
946         } else {
947                 lastReadOk_ = false;
948         }
949         return *this;
950 }
951
952
953 /// quotes a string, e.g. for use in preferences files or as an argument of the "log" dialog
954 string const Lexer::quoteString(string const & arg)
955 {
956         std::ostringstream os;
957         os << '"' << subst(subst(arg, "\\", "\\\\"), "\"", "\\\"") << '"';
958         return os.str();
959 }
960
961
962 } // namespace lyx