]> git.lyx.org Git - lyx.git/blob - src/factory.cpp
Fix C++20 compilation on systems where char_type is wchar_t
[lyx.git] / src / factory.cpp
1 /**
2  * \file factory.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "factory.h"
14
15 #include "FuncRequest.h"
16 #include "Lexer.h"
17 #include "LyX.h"
18
19 #include "insets/InsetBibitem.h"
20 #include "insets/InsetBibtex.h"
21 #include "insets/InsetBox.h"
22 #include "insets/InsetBranch.h"
23 #include "insets/InsetCaption.h"
24 #include "insets/InsetCitation.h"
25 #include "insets/InsetCounter.h"
26 #include "insets/InsetFlex.h"
27 #include "insets/InsetERT.h"
28 #include "insets/InsetListings.h"
29 #include "insets/InsetExternal.h"
30 #include "insets/InsetFloat.h"
31 #include "insets/InsetFloatList.h"
32 #include "insets/InsetFoot.h"
33 #include "insets/InsetGraphics.h"
34 #include "insets/InsetHyperlink.h"
35 #include "insets/InsetInclude.h"
36 #include "insets/InsetIndex.h"
37 #include "insets/InsetInfo.h"
38 #include "insets/InsetIPA.h"
39 #include "insets/InsetIPAMacro.h"
40 #include "insets/InsetLabel.h"
41 #include "insets/InsetLine.h"
42 #include "insets/InsetMarginal.h"
43 #include "insets/InsetNewline.h"
44 #include "insets/InsetNewpage.h"
45 #include "insets/InsetNomencl.h"
46 #include "insets/InsetNote.h"
47 #include "insets/InsetArgument.h"
48 #include "insets/InsetPhantom.h"
49 #include "insets/InsetPreview.h"
50 #include "insets/InsetQuotes.h"
51 #include "insets/InsetRef.h"
52 #include "insets/InsetScript.h"
53 #include "insets/InsetSeparator.h"
54 #include "insets/InsetSpace.h"
55 #include "insets/InsetTabular.h"
56 #include "insets/InsetTOC.h"
57 #include "insets/InsetVSpace.h"
58 #include "insets/InsetWrap.h"
59
60 #include "mathed/InsetMathMacroTemplate.h"
61 #include "mathed/InsetMathHull.h"
62
63 #include "frontends/alert.h"
64
65 #include "support/debug.h"
66 #include "support/ExceptionMessage.h"
67 #include "support/lstrings.h"
68 #include "support/unique_ptr.h"
69
70 #include <sstream>
71
72
73 using namespace std;
74 using namespace lyx::support;
75
76 namespace lyx {
77
78 namespace Alert = frontend::Alert;
79
80
81 Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
82 {
83         try {
84
85                 switch (cmd.action()) {
86
87                 case LFUN_NEWPAGE_INSERT: {
88                         string const name = cmd.getArg(0);
89                         InsetNewpageParams inp;
90                         if (name.empty() || name == "newpage")
91                                 inp.kind = InsetNewpageParams::NEWPAGE;
92                         else if (name == "pagebreak")
93                                 inp.kind = InsetNewpageParams::PAGEBREAK;
94                         else if (name == "clearpage")
95                                 inp.kind = InsetNewpageParams::CLEARPAGE;
96                         else if (name == "cleardoublepage")
97                                 inp.kind = InsetNewpageParams::CLEARDOUBLEPAGE;
98                         else if (name == "nopagebreak")
99                                 inp.kind = InsetNewpageParams::NOPAGEBREAK;
100                         return new InsetNewpage(inp);
101                 }
102
103                 case LFUN_SEPARATOR_INSERT: {
104                         string const name = cmd.getArg(0);
105                         InsetSeparatorParams inp;
106                         if (name.empty() || name == "plain")
107                                 inp.kind = InsetSeparatorParams::PLAIN;
108                         else if (name == "parbreak")
109                                 inp.kind = InsetSeparatorParams::PARBREAK;
110                         else if (name == "latexpar")
111                                 inp.kind = InsetSeparatorParams::LATEXPAR;
112                         else {
113                                 lyxerr << "Wrong argument for LyX function 'separator-insert'." << endl;
114                                 break;
115                         }
116                         return new InsetSeparator(inp);
117                 }
118
119                 case LFUN_FLEX_INSERT: {
120                         string s = cmd.getArg(0);
121                         return new InsetFlex(buf, s);
122                 }
123
124                 case LFUN_NOTE_INSERT: {
125                         string arg = cmd.getArg(0);
126                         if (arg.empty())
127                                 arg = "Note";
128                         return new InsetNote(buf, arg);
129                 }
130
131                 case LFUN_BOX_INSERT: {
132                         string arg = cmd.getArg(0);
133                         if (arg.empty())
134                                 arg = "Boxed";
135                         return new InsetBox(buf, arg);
136                 }
137
138                 case LFUN_BRANCH_INSERT: {
139                         docstring arg = cmd.argument();
140                         if (arg.empty())
141                                 arg = from_ascii("none");
142                         return new InsetBranch(buf, InsetBranchParams(arg));
143                 }
144
145                 case LFUN_PHANTOM_INSERT: {
146                         string arg = cmd.getArg(0);
147                         if (arg.empty())
148                                 arg = "Phantom";
149                         return new InsetPhantom(buf, arg);
150                 }
151
152                 case LFUN_IPAMACRO_INSERT: {
153                         string const arg1 = cmd.getArg(0);
154                         string const arg2 = cmd.getArg(1);
155                         if (arg1 != "deco") {
156                                 LYXERR0("LFUN_IPAMACRO_INSERT: wrong argument");
157                                 return nullptr;
158                         }
159                         return new InsetIPADeco(buf, arg2);
160                 }
161
162                 case LFUN_ERT_INSERT:
163                         return new InsetERT(buf);
164
165                 case LFUN_LISTING_INSERT:
166                         return new InsetListings(buf);
167
168                 case LFUN_FOOTNOTE_INSERT:
169                         return new InsetFoot(buf);
170
171                 case LFUN_MARGINALNOTE_INSERT:
172                         return new InsetMarginal(buf);
173
174                 case LFUN_ARGUMENT_INSERT: {
175                         string arg = cmd.getArg(0);
176                         if (arg.empty()) {
177                                 LYXERR0("argument-insert needs an argument!");
178                                 return nullptr;
179                         }
180                         return new InsetArgument(buf, arg);
181                 }
182
183                 case LFUN_FLOAT_INSERT: {
184                         string argument = to_utf8(cmd.argument());
185                         if (!argument.empty()) {
186                                 if (!contains(argument, "sideways")) {
187                                         if (!contains(argument, "wide"))
188                                                 argument += "\nwide false";
189                                         argument += "\nsideways false";
190                                 }
191                         }
192                         return new InsetFloat(buf, argument);
193                 }
194
195                 case LFUN_FLOAT_WIDE_INSERT: {
196                         string argument = to_utf8(cmd.argument());
197                         if (!argument.empty()) {
198                                 if (!contains(argument, "sideways")) {
199                                         if (!contains(argument, "wide"))
200                                                 argument += "\nwide true";
201                                         argument += "\nsideways false";
202                                 }
203                         }
204                         InsetFloat * fl = new InsetFloat(buf, argument);
205                         fl->setWide(true);
206                         return fl;
207                 }
208
209                 case LFUN_WRAP_INSERT: {
210                         string const argument = to_utf8(cmd.argument());
211                         if (argument == "figure" || argument == "table")
212                                 return new InsetWrap(buf, argument);
213                         lyxerr << "Non-existent wrapfig type: " << argument << endl;
214                         return nullptr;
215                 }
216
217                 case LFUN_INDEX_INSERT: {
218                         docstring const & arg = cmd.argument();
219                         return new InsetIndex(buf, InsetIndexParams(arg));
220                 }
221
222                 case LFUN_IPA_INSERT:
223                         return new InsetIPA(buf);
224
225                 case LFUN_NOMENCL_INSERT: {
226                         InsetCommandParams icp(NOMENCL_CODE);
227                         icp["symbol"] = cmd.argument();
228                         return new InsetNomencl(buf, icp);
229                 }
230
231                 case LFUN_TABULAR_INSERT: {
232                         if (cmd.argument().empty())
233                                 return nullptr;
234                         istringstream ss(to_utf8(cmd.argument()));
235                         int r = 0, c = 0;
236                         ss >> r >> c;
237                         if (r <= 0)
238                                 r = 2;
239                         if (c <= 0)
240                                 c = 2;
241                         return new InsetTabular(buf, r, c);
242                 }
243
244                 case LFUN_CAPTION_INSERT: {
245                         string arg = cmd.getArg(0);
246                         if (arg.empty())
247                                 arg = "Standard";
248                         return new InsetCaption(buf, arg);
249                 }
250
251                 case LFUN_INDEX_PRINT:  {
252                         InsetCommandParams icp(INDEX_PRINT_CODE);
253                         icp["type"] = cmd.argument();
254                         return new InsetPrintIndex(buf, icp);
255                 }
256
257                 case LFUN_NOMENCL_PRINT: {
258                         InsetCommandParams icp(NOMENCL_PRINT_CODE);
259                         icp["set_width"] = from_ascii("auto");
260                         return new InsetPrintNomencl(buf, icp);
261                 }
262
263                 case LFUN_INFO_INSERT: {
264                         InsetInfo * inset = new InsetInfo(buf, to_utf8(cmd.argument()));
265                         return inset;
266                 }
267
268                 case LFUN_PREVIEW_INSERT:
269                         return new InsetPreview(buf);
270
271                 case LFUN_SCRIPT_INSERT: {
272                         InsetScriptParams isp;
273                         InsetScript::string2params("script script " + to_utf8(cmd.argument()), isp);
274                         return new InsetScript(buf, isp);
275                 }
276
277                 case LFUN_INSET_INSERT: {
278                         string const name = cmd.getArg(0);
279                         InsetCode code = insetCode(name);
280                         switch (code) {
281                         case NO_CODE:
282                                 lyxerr << "No such inset '" << name << "'.";
283                                 return nullptr;
284
285                         case BIBITEM_CODE: {
286                                 InsetCommandParams icp(code);
287                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
288                                 return new InsetBibitem(buf, icp);
289                         }
290
291                         case BIBTEX_CODE: {
292                                 InsetCommandParams icp(code);
293                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
294                                 return new InsetBibtex(buf, icp);
295                         }
296
297                         case CITE_CODE: {
298                                 InsetCommandParams icp(code);
299                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
300                                 return new InsetCitation(buf, icp);
301                         }
302
303                         case COUNTER_CODE: {
304                                 InsetCommandParams icp(code);
305                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
306                                 return new InsetCounter(buf, icp);
307                         }
308
309                         case ERT_CODE: {
310                                 return new InsetERT(buf,
311                                         InsetERT::string2params(to_utf8(cmd.argument())));
312                         }
313
314                         case EXTERNAL_CODE: {
315                                 InsetExternalParams iep;
316                                 InsetExternal::string2params(to_utf8(cmd.argument()), *buf, iep);
317                                 auto inset = make_unique<InsetExternal>(buf);
318                                 inset->setBuffer(*buf);
319                                 inset->setParams(iep);
320                                 return inset.release();
321                         }
322
323                         case GRAPHICS_CODE: {
324                                 InsetGraphicsParams igp;
325                                 InsetGraphics::string2params(to_utf8(cmd.argument()), *buf, igp);
326                                 auto inset = make_unique<InsetGraphics>(buf);
327                                 inset->setParams(igp);
328                                 return inset.release();
329                         }
330
331                         case HYPERLINK_CODE: {
332                                 InsetCommandParams icp(code);
333                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
334                                 return new InsetHyperlink(buf, icp);
335                         }
336
337                         case INCLUDE_CODE: {
338                                 InsetCommandParams icp(code);
339                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
340                                 return new InsetInclude(buf, icp);
341                         }
342
343                         case INDEX_CODE: {
344                                 docstring const & arg = cmd.argument();
345                                 return new InsetIndex(buf, InsetIndexParams(arg));
346                         }
347
348                         case INDEX_PRINT_CODE:  {
349                                 InsetCommandParams icp(code);
350                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
351                                 return new InsetPrintIndex(buf, icp);
352                         }
353
354                         case LABEL_CODE: {
355                                 InsetCommandParams icp(code);
356                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
357                                 return new InsetLabel(buf, icp);
358                         }
359
360                         case LINE_CODE: {
361                                 InsetCommandParams icp(code);
362                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
363                                 return new InsetLine(buf, icp);
364                         }
365
366                         case LISTINGS_CODE: {
367                                 InsetListingsParams par;
368                                 InsetListings::string2params(to_utf8(cmd.argument()), par);
369                                 return new InsetListings(buf, par);
370                         }
371
372                         case NOMENCL_CODE: {
373                                 InsetCommandParams icp(code);
374                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
375                                 return new InsetNomencl(buf, icp);
376                         }
377
378                         case REF_CODE: {
379                                 InsetCommandParams icp(code);
380                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
381                                 return new InsetRef(buf, icp);
382                         }
383
384                         case SCRIPT_CODE: {
385                                 InsetScriptParams isp;
386                                 InsetScript::string2params(to_utf8(cmd.argument()), isp);
387                                 return new InsetScript(buf, isp);
388                         }
389
390                         case SPACE_CODE: {
391                                 InsetSpaceParams isp;
392                                 InsetSpace::string2params(to_utf8(cmd.argument()), isp);
393                                 return new InsetSpace(isp);
394                         }
395
396                         case TOC_CODE: {
397                                 InsetCommandParams icp(code);
398                                 InsetCommand::string2params(to_utf8(cmd.argument()), icp);
399                                 return new InsetTOC(buf, icp);
400                         }
401
402                         case VSPACE_CODE: {
403                                 VSpace vspace;
404                                 InsetVSpace::string2params(to_utf8(cmd.argument()), vspace);
405                                 return new InsetVSpace(vspace);
406                         }
407
408                         case PREVIEW_CODE:
409                                 return new InsetPreview(buf);
410
411                         default:
412                                 lyxerr << "Inset '" << name << "' not permitted with LFUN_INSET_INSERT."
413                                                 << endl;
414                                 return nullptr;
415
416                         }
417                 } //end LFUN_INSET_INSERT
418
419                 case LFUN_SPACE_INSERT: {
420                         string const name = cmd.getArg(0);
421                         string const len = cmd.getArg(1);
422                         if (name.empty()) {
423                                 lyxerr << "LyX function 'space-insert' needs an argument." << endl;
424                                 break;
425                         }
426                         InsetSpaceParams isp;
427                         // The tests for isp.math might be disabled after a file format change
428                         if (name == "normal")
429                                 isp.kind = InsetSpaceParams::NORMAL;
430                         else if (name == "protected")
431                                 isp.kind = InsetSpaceParams::PROTECTED;
432                         else if (name == "visible")
433                                 isp.kind = InsetSpaceParams::VISIBLE;
434                         else if (name == "thin")
435                                 isp.kind = InsetSpaceParams::THIN;
436                         else if (isp.math && name == "med")
437                                 isp.kind = InsetSpaceParams::MEDIUM;
438                         else if (isp.math && name == "thick")
439                                 isp.kind = InsetSpaceParams::THICK;
440                         else if (name == "quad")
441                                 isp.kind = InsetSpaceParams::QUAD;
442                         else if (name == "qquad")
443                                 isp.kind = InsetSpaceParams::QQUAD;
444                         else if (name == "enspace")
445                                 isp.kind = InsetSpaceParams::ENSPACE;
446                         else if (name == "enskip")
447                                 isp.kind = InsetSpaceParams::ENSKIP;
448                         else if (name == "negthinspace")
449                                 isp.kind = InsetSpaceParams::NEGTHIN;
450                         else if (name == "negmedspace")
451                                 isp.kind = InsetSpaceParams::NEGMEDIUM;
452                         else if (name == "negthickspace")
453                                 isp.kind = InsetSpaceParams::NEGTHICK;
454                         else if (name == "hfill")
455                                 isp.kind = InsetSpaceParams::HFILL;
456                         else if (name == "hfill*")
457                                 isp.kind = InsetSpaceParams::HFILL_PROTECTED;
458                         else if (name == "dotfill")
459                                 isp.kind = InsetSpaceParams::DOTFILL;
460                         else if (name == "hrulefill")
461                                 isp.kind = InsetSpaceParams::HRULEFILL;
462                         else if (name == "hspace") {
463                                 if (len.empty() || !isValidGlueLength(len)) {
464                                         lyxerr << "LyX function 'space-insert hspace' "
465                                                << "needs a valid length argument." << endl;
466                                         break;
467                                 }
468                                 isp.kind = InsetSpaceParams::CUSTOM;
469                                 isp.length = GlueLength(len);
470                         }
471                         else if (name == "hspace*") {
472                                 if (len.empty() || !isValidGlueLength(len)) {
473                                         lyxerr << "LyX function 'space-insert hspace*' "
474                                                << "needs a valid length argument." << endl;
475                                         break;
476                                 }
477                                 isp.kind = InsetSpaceParams::CUSTOM_PROTECTED;
478                                 isp.length = GlueLength(len);
479                         }
480                         else {
481                                 lyxerr << "Wrong argument for LyX function 'space-insert'." << endl;
482                                 break;
483                         }
484                         return new InsetSpace(isp);
485                 }
486
487                 default:
488                         break;
489                 }
490
491         } catch (ExceptionMessage const & message) {
492                 if (message.type_ == ErrorException) {
493                         // This should never happen!
494                         Alert::error(message.title_, message.details_);
495                         lyx_exit(1);
496                 } else if (message.type_ == WarningException) {
497                         Alert::warning(message.title_, message.details_);
498                         return nullptr;
499                 }
500         }
501
502         return nullptr;
503 }
504
505
506 Inset * createInset(Buffer * buf, FuncRequest const & cmd)
507 {
508         Inset * inset = createInsetHelper(buf, cmd);
509         if (inset)
510                 inset->setBuffer(*buf);
511         return inset;
512 }
513
514
515 Inset * readInset(Lexer & lex, Buffer * buf)
516 {
517         // consistency check
518         if (lex.getString() != "\\begin_inset")
519                 LYXERR0("Buffer::readInset: Consistency check failed.");
520
521         unique_ptr<Inset> inset;
522
523         string tmptok;
524         lex >> tmptok;
525
526         // test the different insets
527
528         // FIXME It would be better if we did not have this branch and could
529         // just do one massive switch for all insets. But at present, it's
530         // easier to do it this way, and we can't do the massive switch until
531         // the conversion mentioned below.  Note that if we do want to do a
532         // single switch, we need to remove this "CommandInset" line---or
533         // replace it with a single "InsetType" line that would be used in all
534         // insets.
535         if (tmptok == "CommandInset") {
536                 lex.next();
537                 string const insetType = lex.getString();
538                 lex.pushToken(insetType);
539
540                 InsetCode const code = insetCode(insetType);
541
542                 //FIXME If we do the one massive switch, we cannot do this here, since
543                 //we do not know in advance that we're dealing with a command inset.
544                 //Worst case, we could put it in each case below. Better, we could
545                 //pass the lexer to the constructor and let the params be built there.
546                 InsetCommandParams inscmd(code);
547                 inscmd.Read(lex, buf);
548
549                 switch (code) {
550                         case BIBITEM_CODE:
551                                 inset.reset(new InsetBibitem(buf, inscmd));
552                                 break;
553                         case BIBTEX_CODE:
554                                 inset.reset(new InsetBibtex(buf, inscmd));
555                                 break;
556                         case CITE_CODE:
557                                 inset.reset(new InsetCitation(buf, inscmd));
558                                 break;
559                         case COUNTER_CODE:
560                                 inset.reset(new InsetCounter(buf, inscmd));
561                                 break;
562                         case HYPERLINK_CODE:
563                                 inset.reset(new InsetHyperlink(buf, inscmd));
564                                 break;
565                         case INCLUDE_CODE:
566                                 inset.reset(new InsetInclude(buf, inscmd));
567                                 break;
568                         case INDEX_PRINT_CODE:
569                                 inset.reset(new InsetPrintIndex(buf, inscmd));
570                                 break;
571                         case LABEL_CODE:
572                                 inset.reset(new InsetLabel(buf, inscmd));
573                                 break;
574                         case LINE_CODE:
575                                 inset.reset(new InsetLine(buf, inscmd));
576                                 break;
577                         case NOMENCL_CODE:
578                                 inset.reset(new InsetNomencl(buf, inscmd));
579                                 break;
580                         case NOMENCL_PRINT_CODE:
581                                 inset.reset(new InsetPrintNomencl(buf, inscmd));
582                                 break;
583                         case REF_CODE:
584                                 if (inscmd["name"].empty() && inscmd["reference"].empty())
585                                         return nullptr;
586                                 inset.reset(new InsetRef(buf, inscmd));
587                                 break;
588                         case TOC_CODE:
589                                 inset.reset(new InsetTOC(buf, inscmd));
590                                 break;
591                         case NO_CODE:
592                         default:
593                                 lyxerr << "unknown CommandInset '" << insetType
594                                                         << "'" << endl;
595                                 while (lex.isOK() && lex.getString() != "\\end_inset")
596                                         lex.next();
597                                 return nullptr;
598                 }
599                 inset->setBuffer(*buf);
600         } else {
601                 // FIXME This branch should be made to use inset codes
602                 // as the preceding branch does. Unfortunately, that
603                 // will take some doing. It requires converting the
604                 // representation of the insets in LyX files so that
605                 // they use the inset names listed in Inset.cpp. Then,
606                 // as above, the inset names can be translated to
607                 // inset codes using insetCode(). And the insets'
608                 // write() routines should use insetName() rather than
609                 // hardcoding it.
610                 if (tmptok == "Quotes") {
611                         inset.reset(new InsetQuotes(buf));
612                 } else if (tmptok == "External") {
613                         inset.reset(new InsetExternal(buf));
614                 } else if (tmptok == "FormulaMacro") {
615                         inset.reset(new InsetMathMacroTemplate(buf));
616                 } else if (tmptok == "Formula") {
617                         inset.reset(new InsetMathHull(buf));
618                 } else if (tmptok == "Graphics") {
619                         inset.reset(new InsetGraphics(buf));
620                 } else if (tmptok == "Note") {
621                         inset.reset(new InsetNote(buf, tmptok));
622                 } else if (tmptok == "Box") {
623                         inset.reset(new InsetBox(buf, tmptok));
624                 } else if (tmptok == "Flex") {
625                         lex.eatLine();
626                         string s = lex.getString();
627                         inset.reset(new InsetFlex(buf, s));
628                 } else if (tmptok == "Branch") {
629                         inset.reset(new InsetBranch(buf, InsetBranchParams()));
630                 } else if (tmptok == "Phantom") {
631                         inset.reset(new InsetPhantom(buf, tmptok));
632                 } else if (tmptok == "ERT") {
633                         inset.reset(new InsetERT(buf));
634                 } else if (tmptok == "listings") {
635                         inset.reset(new InsetListings(buf));
636                 } else if (tmptok == "script") {
637                         inset.reset(new InsetScript(buf));
638                 } else if (tmptok == "space") {
639                         inset.reset(new InsetSpace);
640                 } else if (tmptok == "Tabular") {
641                         inset.reset(new InsetTabular(buf));
642                 } else if (tmptok == "Text") {
643                         inset.reset(new InsetText(buf));
644                 } else if (tmptok == "VSpace") {
645                         inset.reset(new InsetVSpace);
646                 } else if (tmptok == "Foot") {
647                         inset.reset(new InsetFoot(buf));
648                 } else if (tmptok == "Marginal") {
649                         inset.reset(new InsetMarginal(buf));
650                 } else if (tmptok == "Newpage") {
651                         inset.reset(new InsetNewpage);
652                 } else if (tmptok == "Newline") {
653                         inset.reset(new InsetNewline);
654                 } else if (tmptok == "Separator") {
655                         inset.reset(new InsetSeparator);
656                 } else if (tmptok == "Argument") {
657                         inset.reset(new InsetArgument(buf, tmptok));
658                 } else if (tmptok == "Float") {
659                         inset.reset(new InsetFloat(buf, string()));
660                 } else if (tmptok == "Wrap") {
661                         lex.next();
662                         string tmptok2 = lex.getString();
663                         inset.reset(new InsetWrap(buf, tmptok2));
664                 } else if (tmptok == "Caption") {
665                         lex.eatLine();
666                         string s = lex.getString();
667                         inset.reset(new InsetCaption(buf, s));
668                 } else if (tmptok == "Index") {
669                         inset.reset(new InsetIndex(buf, InsetIndexParams()));
670                 } else if (tmptok == "FloatList") {
671                         inset.reset(new InsetFloatList(buf));
672                 } else if (tmptok == "Info") {
673                         inset.reset(new InsetInfo(buf));
674                 } else if (tmptok == "IPA") {
675                         inset.reset(new InsetIPA(buf));
676                 } else if (tmptok == "IPADeco") {
677                         inset.reset(new InsetIPADeco(buf, tmptok));
678                 } else if (tmptok == "Preview") {
679                         inset.reset(new InsetPreview(buf));
680                 } else {
681                         lyxerr << "unknown Inset type '" << tmptok
682                                << "'" << endl;
683                         while (lex.isOK() && lex.getString() != "\\end_inset")
684                                 lex.next();
685                         return nullptr;
686                 }
687
688                 // Set the buffer reference for proper parsing of some insets
689                 // (InsetCollapsible for example)
690                 inset->setBuffer(*buf);
691                 inset->read(lex);
692                 // Set again the buffer for insets that are created inside this inset
693                 // (InsetMathHull for example).
694                 inset->setBuffer(*buf);
695         }
696         return inset.release();
697 }
698
699
700 } // namespace lyx