source: CMT/v1r18p20050501/source/cmt_syntax.cxx

Last change on this file was 41, checked in by arnault, 19 years ago

Implement the container statement in project file - See CL269 and #4

  • Property svn:eol-style set to native
File size: 31.1 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// See the complete license in cmt_license.txt "http://www.cecill.info".
5//-----------------------------------------------------------
6
7#include "cmt_syntax.h"
8#include "cmt.h"
9#include "cmt_symbol.h"
10#include "cmt_constituent.h"
11#include "cmt_pattern.h"
12#include "cmt_error.h"
13#include "cmt_branch.h"
14#include "cmt_error.h"
15#include "cmt_script.h"
16#include "cmt_language.h"
17#include "cmt_project.h"
18#include "cmt_cmtpath_pattern.h"
19
20void Kwd::action (const CmtSystem::cmt_string_vector& words,
21                  Project* project,
22                  const cmt_string& file_name,
23                  int line_number)
24{
25}
26
27class KwdAction : public Kwd
28{
29public:
30  void action (const CmtSystem::cmt_string_vector& words,
31               Use* use,
32               const cmt_string& file_name,
33               int line_number)
34  {
35    Symbol::action (words, CommandAction, use);
36  }
37};
38
39class KwdAlias : public Kwd
40{
41public:
42  void action (const CmtSystem::cmt_string_vector& words,
43               Use* use,
44               const cmt_string& file_name,
45               int line_number)
46  {
47    Symbol::action (words, CommandAlias, use);
48  }
49};
50
51class KwdApplication : public Kwd
52{
53public:
54  void action (const CmtSystem::cmt_string_vector& words,
55               Use* use,
56               const cmt_string& file_name,
57               int line_number)
58  {
59    if (use == &(Use::current ()))
60      {
61        Constituent::action (Application, words);
62      }
63  }
64};
65
66class KwdApplyPattern : public Kwd
67{
68public:
69  void action (const CmtSystem::cmt_string_vector& words,
70               Use* use,
71               const cmt_string& file_name,
72               int line_number)
73  {
74    ApplyPattern::action (words, use);
75  }
76};
77
78class KwdApplyTag : public Kwd
79{
80public:
81  void action (const CmtSystem::cmt_string_vector& words,
82               Use* use,
83               const cmt_string& file_name,
84               int line_number)
85  {
86    Tag::action_apply (words, use);
87  }
88};
89
90class KwdAuthor : public Kwd
91{
92public:
93  void action (const CmtSystem::cmt_string_vector& words,
94               Use* use,
95               const cmt_string& file_name,
96               int line_number)
97  {
98    use->author_action (words);
99  }
100};
101
102class KwdBranches : public Kwd
103{
104public:
105  void action (const CmtSystem::cmt_string_vector& words,
106               Use* use,
107               const cmt_string& file_name,
108               int line_number)
109  {
110    if (use == &(Use::current ())) 
111      {
112        Branch::action (words);
113      }
114  }
115};
116
117class KwdBuildStrategy : public Kwd
118{
119public:
120  bool decode (const cmt_string& w, cmt_string& strategy, cmt_string& value)
121  {
122    bool result = true;
123
124    value = w;
125
126    if (w == "prototypes")
127      {
128        strategy = "BuildPrototypes";
129      }
130    else if (w == "no_prototypes")
131      {
132        strategy = "BuildPrototypes";
133      }
134    else if ((w == "with_installarea") || (w == "with_install_area"))
135      {
136        value = "with_installarea";
137        strategy = "InstallArea";
138      }
139    else if ((w == "without_installarea") || (w == "without_install_area"))
140      {
141        value = "without_installarea";
142        strategy = "InstallArea";
143      }
144    else
145      {
146        result = false;
147      }
148
149    return (result);
150  }
151
152  void action (const CmtSystem::cmt_string_vector& words,
153               Use* use,
154               const cmt_string& file_name,
155               int line_number)
156  {
157    cmt_string cmtpath;
158    cmt_string offset;
159
160    use->get_cmtpath_and_offset (cmtpath, offset);
161
162    Project* p = Project::find_by_cmtpath (cmtpath);
163
164    for (int i = 1; i < words.size (); i++)
165      {
166        const cmt_string& w = words[i];
167
168        cmt_string strategy;
169        cmt_string value;
170
171        bool in_error = false;
172
173        if (decode (w, strategy, value))
174          {
175            if (p != 0) p->set_strategy (strategy, value, use->get_package_name ());
176          }
177        else
178          {
179            in_error = true;
180
181            CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
182          }
183      }
184  }
185
186  void action (const CmtSystem::cmt_string_vector& words,
187               Project* project,
188               const cmt_string& file_name,
189               int line_number)
190  {
191    for (int i = 1; i < words.size (); i++)
192      {
193        const cmt_string& w = words[i];
194
195        cmt_string strategy;
196        cmt_string value;
197
198        bool in_error = false;
199
200        if (decode (w, strategy, value))
201          {
202            if (project != 0) project->set_strategy (strategy, value, "");
203          }
204        else
205          {
206            in_error = true;
207
208            CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
209          }
210      }
211  }
212};
213
214class KwdCleanupScript : public Kwd
215{
216public:
217  void action (const CmtSystem::cmt_string_vector& words,
218               Use* use,
219               const cmt_string& file_name,
220               int line_number)
221  {
222    Script::action (words, CleanupScript, use);
223    Symbol::action (words, CommandCleanupScript, use);
224  }
225};
226
227class KwdCmtPathPattern : public Kwd
228{
229public:
230  void action (const CmtSystem::cmt_string_vector& words,
231               Use* use,
232               const cmt_string& /*file_name*/,
233               int /*line_number*/)
234  {
235    CmtPathPattern::action (words, use);
236  }
237};
238
239class KwdContainer : public Kwd
240{
241public:
242  void action (const CmtSystem::cmt_string_vector& words,
243               Use* use,
244               const cmt_string& file_name,
245               int line_number)
246  {
247  }
248
249  void action (const CmtSystem::cmt_string_vector& words,
250               Project* project,
251               const cmt_string& file_name,
252               int line_number)
253  {
254    project->container_action (words[1], words[2]);
255  }
256};
257
258class KwdDocument : public Kwd
259{
260public:
261  void action (const CmtSystem::cmt_string_vector& words,
262               Use* use,
263               const cmt_string& file_name,
264               int line_number)
265  {
266    if (use == &(Use::current ()))
267      {
268        Constituent::action (Document, words);
269      }
270  }
271};
272
273class KwdEndPrivate : public Kwd
274{
275public:
276  void action (const CmtSystem::cmt_string_vector& words,
277               Use* use,
278               const cmt_string& file_name,
279               int line_number)
280  {
281    if (use != &(Use::current ()))
282      {
283        use->pop_scope_section ();
284      }
285  }
286};
287
288class KwdEndPublic : public Kwd
289{
290public:
291  void action (const CmtSystem::cmt_string_vector& words,
292               Use* use,
293               const cmt_string& file_name,
294               int line_number)
295  {
296    if (use != &(Use::current ()))
297      {
298        use->pop_scope_section ();
299      }
300  }
301};
302
303class KwdIgnorePattern : public Kwd
304{
305public:
306  void action (const CmtSystem::cmt_string_vector& words,
307               Use* use,
308               const cmt_string& file_name,
309               int line_number)
310  {
311    IgnorePattern::action (words, use);
312  }
313};
314
315class KwdIncludeDirs : public Kwd
316{
317public:
318  void action (const CmtSystem::cmt_string_vector& words,
319               Use* use,
320               const cmt_string& file_name,
321               int line_number)
322  {
323    Include::action (words, use);
324  }
325};
326
327class KwdIncludePath : public Kwd
328{
329public:
330  void action (const CmtSystem::cmt_string_vector& words,
331               Use* use,
332               const cmt_string& file_name,
333               int line_number)
334  {
335    if (words.size () > 1)
336      {
337        use->set_include_path (words[1]);
338      }
339  }
340};
341
342class KwdLanguage : public Kwd
343{
344public:
345  void action (const CmtSystem::cmt_string_vector& words,
346               Use* use,
347               const cmt_string& file_name,
348               int line_number)
349  {
350    Language::action (words);
351  }
352};
353
354class KwdLibrary : public Kwd
355{
356public:
357  void action (const CmtSystem::cmt_string_vector& words,
358               Use* use,
359               const cmt_string& file_name,
360               int line_number)
361  {
362    if (use == &(Use::current ()))
363      {
364        Constituent::action (Library, words);
365      }
366  }
367};
368
369class KwdMacro : public Kwd
370{
371public:
372  void action (const CmtSystem::cmt_string_vector& words,
373               Use* use,
374               const cmt_string& file_name,
375               int line_number)
376  {
377    Symbol::action (words, CommandMacro, use);
378  }
379};
380
381class KwdMacroPrepend : public Kwd
382{
383public:
384  void action (const CmtSystem::cmt_string_vector& words,
385               Use* use,
386               const cmt_string& file_name,
387               int line_number)
388  {
389    Symbol::action (words, CommandMacroPrepend, use);
390  }
391};
392
393class KwdMacroAppend : public Kwd
394{
395public:
396  void action (const CmtSystem::cmt_string_vector& words,
397               Use* use,
398               const cmt_string& file_name,
399               int line_number)
400  {
401    Symbol::action (words, CommandMacroAppend, use);
402  }
403};
404
405class KwdMacroRemove : public Kwd
406{
407public:
408  void action (const CmtSystem::cmt_string_vector& words,
409               Use* use,
410               const cmt_string& file_name,
411               int line_number)
412  {
413    Symbol::action (words, CommandMacroRemove, use);
414  }
415};
416
417class KwdMacroRemoveRegexp : public Kwd
418{
419public:
420  void action (const CmtSystem::cmt_string_vector& words,
421               Use* use,
422               const cmt_string& file_name,
423               int line_number)
424  {
425    Symbol::action (words, CommandMacroRemoveRegexp, use);
426  }
427};
428
429class KwdMacroRemoveAll : public Kwd
430{
431public:
432  void action (const CmtSystem::cmt_string_vector& words,
433               Use* use,
434               const cmt_string& file_name,
435               int line_number)
436  {
437    Symbol::action (words, CommandMacroRemoveAll, use);
438  }
439};
440
441class KwdMacroRemoveAllRegexp : public Kwd
442{
443public:
444  void action (const CmtSystem::cmt_string_vector& words,
445               Use* use,
446               const cmt_string& file_name,
447               int line_number)
448  {
449    Symbol::action (words, CommandMacroRemoveAllRegexp, use);
450  }
451};
452
453class KwdMakeFragment : public Kwd
454{
455public:
456  void action (const CmtSystem::cmt_string_vector& words,
457               Use* use,
458               const cmt_string& file_name,
459               int line_number)
460  {
461    Fragment::action (words, use);
462  }
463};
464
465class KwdManager : public Kwd
466{
467public:
468  void action (const CmtSystem::cmt_string_vector& words,
469               Use* use,
470               const cmt_string& file_name,
471               int line_number)
472  {
473    use->manager_action (words);
474  }
475};
476
477class KwdPackage : public Kwd
478{
479public:
480  void action (const CmtSystem::cmt_string_vector& words,
481               Use* use,
482               const cmt_string& file_name,
483               int line_number)
484  {
485    /*
486    if (words.size () > 1)
487      {
488        if (use == &(Use::current()))
489          {
490            m_current_package = words[1];
491            build_prefix (m_current_package, m_current_prefix);
492           
493            if ((use->get_package_name () != "") &&
494                (use->get_package_name () != m_current_package))
495              {
496                if (!m_quiet)
497                  {
498                    //  cerr << "#CMT> package name mismatch in requirements of " <<
499                    //  use->get_package_name () << " " <<
500                    //  use->version << " line #" << line_number;
501                    //  cerr << " : " << m_current_package << " versus " <<
502                    //  use->get_package_name () << endl;
503                  }
504              }
505           
506            use->set (m_current_package,
507                      m_current_version,
508                      m_current_path,
509                      "",
510                      "");
511           
512            use->change_path (m_current_path);
513            use->style = m_current_style;
514          }
515      }
516    */
517  }
518};
519
520class KwdPath : public Kwd
521{
522public:
523  void action (const CmtSystem::cmt_string_vector& words,
524               Use* use,
525               const cmt_string& file_name,
526               int line_number)
527  {
528    Symbol::action (words, CommandPath, use);
529  }
530};
531
532class KwdPathAppend : public Kwd
533{
534public:
535  void action (const CmtSystem::cmt_string_vector& words,
536               Use* use,
537               const cmt_string& file_name,
538               int line_number)
539  {
540    Symbol::action (words, CommandPathAppend, use);
541  }
542};
543
544class KwdPathPrepend : public Kwd
545{
546public:
547  void action (const CmtSystem::cmt_string_vector& words,
548               Use* use,
549               const cmt_string& file_name,
550               int line_number)
551  {
552    Symbol::action (words, CommandPathPrepend, use);
553  }
554};
555
556class KwdPathRemove : public Kwd
557{
558public:
559  void action (const CmtSystem::cmt_string_vector& words,
560               Use* use,
561               const cmt_string& file_name,
562               int line_number)
563  {
564    Symbol::action (words, CommandPathRemove, use);
565  }
566};
567
568class KwdPathRemoveRegexp : public Kwd
569{
570public:
571  void action (const CmtSystem::cmt_string_vector& words,
572               Use* use,
573               const cmt_string& file_name,
574               int line_number)
575  {
576    Symbol::action (words, CommandPathRemoveRegexp, use);
577  }
578};
579
580class KwdPattern : public Kwd
581{
582public:
583  void action (const CmtSystem::cmt_string_vector& words,
584               Use* use,
585               const cmt_string& file_name,
586               int line_number)
587  {
588    Pattern::action (words, use);
589  }
590};
591
592class KwdPrivate : public Kwd
593{
594public:
595  void action (const CmtSystem::cmt_string_vector& words,
596               Use* use,
597               const cmt_string& file_name,
598               int line_number)
599  {
600    if (use != &(Use::current ()))
601      {
602        use->push_scope_section (ScopePrivate);
603      }
604  }
605};
606
607class KwdProject : public Kwd
608{
609public:
610  void action (const CmtSystem::cmt_string_vector& words,
611               Use* use,
612               const cmt_string& file_name,
613               int line_number)
614  {
615  }
616
617  void action (const CmtSystem::cmt_string_vector& words,
618               Project* project,
619               const cmt_string& file_name,
620               int line_number)
621  {
622  }
623};
624
625class KwdPublic : public Kwd
626{
627public:
628  void action (const CmtSystem::cmt_string_vector& words,
629               Use* use,
630               const cmt_string& file_name,
631               int line_number)
632  {
633    if (use != &(Use::current ()))
634      {
635        use->push_scope_section (ScopePublic);
636      }
637  }
638};
639
640class KwdSet : public Kwd
641{
642public:
643  void action (const CmtSystem::cmt_string_vector& words,
644               Use* use,
645               const cmt_string& file_name,
646               int line_number)
647  {
648    Symbol::action (words, CommandSet, use);
649  }
650};
651
652class KwdSetAppend : public Kwd
653{
654public:
655  void action (const CmtSystem::cmt_string_vector& words,
656               Use* use,
657               const cmt_string& file_name,
658               int line_number)
659  {
660    Symbol::action (words, CommandSetAppend, use);
661  }
662};
663
664class KwdSetPrepend : public Kwd
665{
666public:
667  void action (const CmtSystem::cmt_string_vector& words,
668               Use* use,
669               const cmt_string& file_name,
670               int line_number)
671  {
672    Symbol::action (words, CommandSetPrepend, use);
673  }
674};
675
676class KwdSetRemove : public Kwd
677{
678public:
679  void action (const CmtSystem::cmt_string_vector& words,
680               Use* use,
681               const cmt_string& file_name,
682               int line_number)
683  {
684    Symbol::action (words, CommandSetRemove, use);
685  }
686};
687
688class KwdSetRemoveRegexp : public Kwd
689{
690public:
691  void action (const CmtSystem::cmt_string_vector& words,
692               Use* use,
693               const cmt_string& file_name,
694               int line_number)
695  {
696    Symbol::action (words, CommandSetRemoveRegexp, use);
697  }
698};
699
700class KwdSetupScript : public Kwd
701{
702public:
703  void action (const CmtSystem::cmt_string_vector& words,
704               Use* use,
705               const cmt_string& file_name,
706               int line_number)
707  {
708    Script::action (words, SetupScript, use);
709    Symbol::action (words, CommandSetupScript, use);
710  }
711};
712
713class KwdSetupStrategy : public Kwd
714{
715public:
716  bool decode (const cmt_string& w, cmt_string& strategy, cmt_string& value)
717  {
718    bool result = true;
719
720    value = w;
721
722    if (w == "config")
723      {
724        strategy = "SetupConfig";
725      }
726    else if (w == "no_config")
727      {
728        strategy = "SetupConfig";
729      }
730    else if (w == "root")
731      {
732        strategy = "SetupRoot";
733      }
734    else if (w == "no_root")
735      {
736        strategy = "SetupRoot";
737      }
738    else if (w == "cleanup")
739      {
740        strategy = "SetupCleanup";
741      }
742    else if (w == "no_cleanup")
743      {
744        strategy = "SetupCleanup";
745      }
746    else
747      {
748        result = false;
749      }
750
751    return (result);
752  }
753
754  void action (const CmtSystem::cmt_string_vector& words,
755               Use* use,
756               const cmt_string& file_name,
757               int line_number)
758  {
759    cmt_string cmtpath;
760    cmt_string offset;
761
762    use->get_cmtpath_and_offset (cmtpath, offset);
763
764    Project* p = Project::find_by_cmtpath (cmtpath);
765
766    for (int i = 1; i < words.size (); i++)
767      {
768        const cmt_string& w = words[i];
769
770        cmt_string strategy;
771        cmt_string value;
772
773        bool in_error = false;
774
775        if (decode (w, strategy, value))
776          {
777            if (p != 0) p->set_strategy (strategy, value, use->get_package_name ());
778          }
779        else
780          {
781            in_error = true;
782
783            CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
784          }
785      }
786  }
787
788  void action (const CmtSystem::cmt_string_vector& words,
789               Project* project,
790               const cmt_string& file_name,
791               int line_number)
792  {
793    for (int i = 1; i < words.size (); i++)
794      {
795        const cmt_string& w = words[i];
796
797        cmt_string strategy;
798        cmt_string value;
799
800        bool in_error = false;
801
802        if (decode (w, strategy, value))
803          {
804            if (project != 0) project->set_strategy (strategy, value, "");
805          }
806        else
807          {
808            in_error = true;
809
810            CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword");
811          }
812      }
813  }
814};
815
816class KwdTag : public Kwd
817{
818public:
819  void action (const CmtSystem::cmt_string_vector& words,
820               Use* use,
821               const cmt_string& file_name,
822               int line_number)
823  {
824    Tag::action (words, use);
825  }
826};
827
828class KwdTagExclude : public Kwd
829{
830public:
831  void action (const CmtSystem::cmt_string_vector& words,
832               Use* use,
833               const cmt_string& file_name,
834               int line_number)
835  {
836    Tag::action_exclude (words, use);
837  }
838};
839
840class KwdUse : public Kwd
841{
842public:
843  void action (const CmtSystem::cmt_string_vector& words,
844               Use* use,
845               const cmt_string& file_name,
846               int line_number)
847  {
848    Use::action (words, use);
849  }
850
851  void action (const CmtSystem::cmt_string_vector& words,
852               Project* project,
853               const cmt_string& file_name,
854               int line_number)
855  {
856    project->use_action (words[1], words[2]);
857  }
858};
859
860class KwdVersionStrategy : public Kwd
861{
862public:
863  void action (const CmtSystem::cmt_string_vector& words,
864               Use* use,
865               const cmt_string& file_name,
866               int line_number)
867  {
868    cerr << "# Package " << use->get_package_name () <<
869      " sets obsolescent version strategy" << endl;
870  }
871};
872
873class KwdVersion : public Kwd
874{
875public:
876  void action (const CmtSystem::cmt_string_vector& words,
877               Use* use,
878               const cmt_string& file_name,
879               int line_number)
880  {
881  }
882};
883
884class KwdDefault : public Kwd
885{
886public:
887  void action (const CmtSystem::cmt_string_vector& words,
888               Use* use,
889               const cmt_string& file_name,
890               int line_number)
891  {
892    /*
893      Unknown keyword : just ignore the line
894    */
895    if (!Cmt::get_quiet ())
896      {
897        cerr << "#CMT> bad syntax in requirements of " << use->get_package_name ()
898             << " " << use->version << " line #" << line_number;
899        cerr << " [" << words[0] << "...]" << endl;
900      }
901   
902    CmtError::set (CmtError::syntax_error, "ParseRequirements> ");
903  }
904};
905
906SyntaxParser& SyntaxParser::instance ()
907{
908  static SyntaxParser p;
909
910  return (p);
911}
912
913/**
914 *  Parse the input file, rejecting comments and
915 * rebuilding complete lines (from sections separated by
916 *  \ characters.
917 *
918 *  Each reformatted line is parsed by filter_line
919 */
920void SyntaxParser::parse_requirements (const cmt_string& file_name, Use* use)
921{
922  SyntaxParser& me = instance ();
923
924  if (use != 0)
925    {
926      cmt_string buffer;
927
928      use->fill_standard_macros (buffer);
929
930      AccessMode saved_current_access = Cmt::get_current_access ();
931      Cmt::set_current_access (UserMode);
932      me.do_parse_text (buffer, "", package_context, use, 0);
933      Cmt::set_current_access (saved_current_access);
934    }
935
936  me.do_parse_requirements (file_name, use);
937
938  if (use != 0)
939    {
940      use->close_scope_sections ();
941    }
942}
943
944/**
945 */
946void SyntaxParser::parse_project_file_text (const cmt_string& text,
947                                            const cmt_string& file_name,
948                                            Project* project)
949{
950  SyntaxParser& me = instance ();
951  me.do_parse_text (text, file_name, project_context, 0, project);
952}
953
954/**
955 *  Parse a text, rejecting comments and
956 * rebuilding complete lines (from sections separated by
957 *  \ characters.
958 *
959 *  Each reformatted line is parsed by filter_line
960 */
961void SyntaxParser::parse_requirements_text (const cmt_string& text,
962                                            const cmt_string& file_name,
963                                            Use* use)
964{
965  SyntaxParser& me = instance ();
966
967    /**
968     *
969     *    We have to preserve m_current_access since it reflects whether
970     *   the current cmt action is run in the context of the current package.
971     *   (the opposite is when the cmt command specifies the current package
972     *    in its arguments -use=... therefore the pwd is NOT the directory
973     *    of the current package)
974     *
975     *   m_current_access is Developer when pwd =  current
976     *                       User      when pwd != current
977     *
978     *    Therefore, as soon as we reach a used package, this must be switched to User
979     *
980     *   On the other hand, Cmt::scope reflects the status of the public/private
981     *  statements. By default, we are in public context when entering a new requirements
982     *  file.
983     *
984     */
985
986  AccessMode saved_current_access;
987
988  saved_current_access = Cmt::get_current_access ();
989
990  if (use == 0) use = &(Use::current ());
991
992  if (use != &(Use::current ()))
993    {
994      if (Cmt::get_debug ())
995        {
996          cout << "parse_requirements_text> set UserMode" << endl;
997        }
998
999      Cmt::set_current_access (UserMode);
1000    }
1001  else
1002    {
1003      if (Cmt::get_debug ())
1004        {
1005          cout << "parse_requirements_text> set DeveloperMode" << endl;
1006        }
1007
1008      Cmt::set_current_access (DeveloperMode);
1009    }
1010
1011  me.do_parse_text (text, file_name, package_context, use, 0);
1012
1013  Cmt::set_current_access (saved_current_access);
1014}
1015
1016/**
1017 *  Apply the basic parser to one single line :
1018 *
1019 *   o Append to global text if previous back_slash
1020 *   o Split into words
1021 *   o Apply the generic Select operator
1022 */
1023void SyntaxParser::parse_requirements_line (const cmt_string& line,
1024                                            Use* use,
1025                                            const cmt_string& file_name,
1026                                            int line_number)
1027{
1028  SyntaxParser& me = instance ();
1029  me.do_parse_line (line, file_name, line_number, package_context, use, 0);
1030}
1031
1032SyntaxParser::SyntaxParser ()
1033{
1034  m_keywords.add ("action", new KwdAction ());
1035  m_keywords.add ("alias", new KwdAlias ());
1036  m_keywords.add ("application", new KwdApplication ());
1037  m_keywords.add ("apply_pattern", new KwdApplyPattern ());
1038  m_keywords.add ("apply_tag", new KwdApplyTag ());
1039  m_keywords.add ("author", new KwdAuthor ());
1040  m_keywords.add ("branches", new KwdBranches ());
1041  m_keywords.add ("build_strategy", new KwdBuildStrategy ());
1042  m_keywords.add ("cleanup_script", new KwdCleanupScript ());
1043  m_keywords.add ("cmtpath_pattern", new KwdCmtPathPattern ());
1044  m_keywords.add ("document", new KwdDocument ());
1045  m_keywords.add ("end_private", new KwdEndPrivate ());
1046  m_keywords.add ("end_public", new KwdEndPublic ());
1047  m_keywords.add ("ignore_pattern", new KwdIgnorePattern ());
1048  m_keywords.add ("include_dirs", new KwdIncludeDirs ());
1049  m_keywords.add ("include_path", new KwdIncludePath ());
1050  m_keywords.add ("language", new KwdLanguage ());
1051  m_keywords.add ("library", new KwdLibrary ());
1052  m_keywords.add ("macro", new KwdMacro ());
1053  m_keywords.add ("macro+", new KwdMacroAppend ());
1054  m_keywords.add ("macro_prepend", new KwdMacroPrepend ());
1055  m_keywords.add ("macro_append", new KwdMacroAppend ());
1056  m_keywords.add ("macro_remove", new KwdMacroRemove ());
1057  m_keywords.add ("macro_remove_regexp", new KwdMacroRemoveRegexp ());
1058  m_keywords.add ("macro_remove_all", new KwdMacroRemoveAll ());
1059  m_keywords.add ("macro_remove_all_regexp", new KwdMacroRemoveAllRegexp ());
1060  m_keywords.add ("make_fragment", new KwdMakeFragment ());
1061  m_keywords.add ("manager", new KwdManager ());
1062  m_keywords.add ("package", new KwdPackage ());
1063  m_keywords.add ("path", new KwdPath ());
1064  m_keywords.add ("path_append", new KwdPathAppend ());
1065  m_keywords.add ("path_prepend", new KwdPathPrepend ());
1066  m_keywords.add ("path_remove", new KwdPathRemove ());
1067  m_keywords.add ("path_remove_regexp", new KwdPathRemoveRegexp ());
1068  m_keywords.add ("pattern", new KwdPattern ());
1069  m_keywords.add ("public", new KwdPublic ());
1070  m_keywords.add ("private", new KwdPrivate ());
1071  m_keywords.add ("project", new KwdProject ());
1072  m_keywords.add ("set", new KwdSet ());
1073  m_keywords.add ("set_append", new KwdSetAppend ());
1074  m_keywords.add ("set_prepend", new KwdSetPrepend ());
1075  m_keywords.add ("set_remove", new KwdSetRemove ());
1076  m_keywords.add ("set_remove_regexp", new KwdSetRemoveRegexp ());
1077  m_keywords.add ("setup_script", new KwdSetupScript ());
1078  m_keywords.add ("setup_strategy", new KwdSetupStrategy ());
1079  m_keywords.add ("tag", new KwdTag ());
1080  m_keywords.add ("tag_exclude", new KwdTagExclude ());
1081  m_keywords.add ("use", new KwdUse ());
1082  m_keywords.add ("version_strategy", new KwdVersionStrategy ());
1083  m_keywords.add ("version", new KwdVersion ());
1084
1085  m_project_keywords.add ("build_strategy", new KwdBuildStrategy ());
1086  m_project_keywords.add ("container", new KwdContainer ());
1087  m_project_keywords.add ("project", new KwdProject ());
1088  m_project_keywords.add ("setup_strategy", new KwdSetupStrategy ());
1089  m_project_keywords.add ("use", new KwdUse ());
1090}
1091
1092void SyntaxParser::do_parse_requirements (const cmt_string& file_name, Use* use)
1093{
1094  cmt_string actual_file_name = file_name;
1095  cmt_string text;
1096
1097  CmtError::clear ();
1098
1099  if (!CmtSystem::test_file (actual_file_name))
1100    {
1101      actual_file_name = "..";
1102      actual_file_name += CmtSystem::file_separator ();
1103      actual_file_name += "cmt";
1104      actual_file_name += CmtSystem::file_separator ();
1105      actual_file_name += file_name;
1106
1107      if (!CmtSystem::test_file (actual_file_name))
1108        {
1109          actual_file_name = "..";
1110          actual_file_name += CmtSystem::file_separator ();
1111          actual_file_name += "mgr";
1112          actual_file_name += CmtSystem::file_separator ();
1113          actual_file_name += file_name;
1114
1115          if (!CmtSystem::test_file (actual_file_name))
1116            {
1117              return;
1118            }
1119        }
1120    }
1121
1122  text.read (actual_file_name);
1123
1124  SyntaxParser::parse_requirements_text (text, actual_file_name, use);
1125}
1126
1127/**
1128 *  Parse a text, rejecting comments and
1129 * rebuilding complete lines (from sections separated by
1130 *  \ characters.
1131 *
1132 *  Each reformatted line is parsed by filter_line
1133 */
1134void SyntaxParser::do_parse_text (const cmt_string& text,
1135                                  const cmt_string& file_name,
1136                                  ContextType context,
1137                                  Use* use,
1138                                  Project* project)
1139{
1140  cmt_string line;
1141  int pos;
1142  int max_pos;
1143  int line_number = 1;
1144
1145  if (context == package_context)
1146    {
1147      if (use == 0) use = &(Use::current ());
1148    }
1149
1150  m_filtered_text.erase (0);
1151
1152  pos = 0;
1153  max_pos = text.size ();
1154
1155  for (pos = 0; pos < max_pos;)
1156    {
1157      int cr = text.find (pos, "\r\n");
1158      int nl = text.find (pos, '\n');
1159      int first = nl;
1160      int length = 1;
1161
1162      if (cr != cmt_string::npos)
1163        {
1164          if (nl == cmt_string::npos)
1165            {
1166              first = cr;
1167              length = 2;
1168            }
1169          else
1170            {
1171              first = (nl < cr) ? nl : cr;
1172              length = (nl < cr) ? 1 : 2;
1173            }
1174        }
1175
1176      if (first == cmt_string::npos)
1177        {
1178          text.substr (pos, line);
1179          pos = max_pos;
1180        }
1181      else if (first > pos)
1182        {
1183          text.substr (pos, first - pos, line);
1184          pos = first + length;
1185        }
1186      else
1187        {
1188          line.erase (0);
1189          pos += length;
1190        }
1191
1192      do_parse_line (line, file_name, line_number, context, use, project);
1193
1194      if ((Cmt::get_action () == action_check_configuration) && CmtError::has_pending_error ())
1195        {
1196          //break;
1197        }
1198
1199      line_number++;
1200    }
1201}
1202
1203void SyntaxParser::do_parse_line (const cmt_string& line,
1204                                  const cmt_string& file_name,
1205                                  int line_number,
1206                                  ContextType context,
1207                                  Use* use,
1208                                  Project* project)
1209{
1210  int length;
1211  int nl;
1212  int back_slash;
1213  cmt_string temp_line = line;
1214
1215  if (temp_line.size () == 0) return;
1216  if (temp_line[0] == '#') return;
1217
1218  nl = temp_line.find_last_of ('\n');
1219  if (nl != cmt_string::npos) temp_line.erase (nl);
1220
1221  length = temp_line.size ();
1222  if (length == 0) return;
1223
1224  //
1225  // We scan the line for handling backslashes.
1226  //
1227  // o Really terminating backslashes (ie those only followed by spaces/tabs
1228  // mean continued line
1229  //
1230  //
1231
1232  bool finished = true;
1233
1234  length = temp_line.size ();
1235
1236  back_slash = temp_line.find_last_of ('\\');
1237
1238  if (back_slash != cmt_string::npos)
1239    {
1240      //
1241      // This is the last backslash
1242      // check if there are only space chars after it
1243      //
1244     
1245      bool at_end = true;
1246
1247      for (int i = (back_slash + 1); i < length; i++)
1248        {
1249          char c = temp_line[i];
1250          if ((c != ' ') && (c != '\t'))
1251            {
1252              at_end = false;
1253              break;
1254            }
1255        }
1256
1257      if (at_end)
1258        {
1259          temp_line.erase (back_slash);
1260          finished = false;
1261        }
1262      else
1263        {
1264          // This was not a trailing backslash.
1265          finished = true;
1266        }
1267    }
1268
1269  m_filtered_text += temp_line;
1270
1271  if (!finished)
1272    {
1273      // We still need to accumulate forthcoming lines
1274      // before parsing the resulting text.
1275      return;
1276    }
1277
1278  /*
1279    Here a full line (possibly accumulating several lines
1280    ended by backslashes) is parsed :
1281   
1282    o Special characters are filtered now :
1283   
1284    <cmt:tab/>  \t
1285    <cmt:cr/>   \r
1286    <cmt:lf/>   \n
1287   
1288    o Split into words (a word is a string not containing
1289    spaces or enclosed in quotes)
1290
1291    o Parse the word array (function Select)
1292
1293  */
1294
1295  m_filtered_text.replace_all ("<cmt:tab/>", "\t");
1296  m_filtered_text.replace_all ("<cmt:cr/>",  "\r");
1297  m_filtered_text.replace_all ("<cmt:lf/>",  "\n");
1298
1299  if (Cmt::get_debug ())
1300    {
1301      cout << "parse_requirements_line [" << m_filtered_text << "]" << endl;
1302    }
1303 
1304  static CmtSystem::cmt_string_vector words;
1305 
1306  CmtSystem::split (m_filtered_text, " \t", words);
1307 
1308  if (words.size () != 0)
1309    {
1310      switch (context)
1311        {
1312        case project_context:
1313          do_parse_words (words, file_name, line_number, project);
1314          break;
1315        case package_context:
1316          do_parse_words (words, file_name, line_number, use);
1317          break;
1318        }
1319    }
1320 
1321  m_filtered_text.erase (0);
1322}
1323
1324void SyntaxParser::do_parse_words (const CmtSystem::cmt_string_vector& words,
1325                                   const cmt_string& file_name,
1326                                   int line_number,
1327                                   Use* use)
1328{
1329  CmtError::clear ();
1330
1331  if (words.size () == 0) return;
1332
1333  const cmt_string& command = words[0];
1334
1335  if (command.size () == 0) return;
1336
1337  //
1338  // First analyze the syntax
1339  //
1340
1341  Kwd* keyword = m_keywords.find (command);
1342  if (keyword == 0)
1343    {
1344      /*
1345
1346        When the first word of the line is not a keyword, it may be an
1347        implicit pattern application.
1348
1349       */
1350
1351      Pattern* p = Pattern::find (command);
1352      if (p == 0)
1353        {
1354          CmtError::set (CmtError::syntax_error, "ParseRequirements> ");
1355        }
1356      else
1357        {
1358          keyword = m_keywords.find ("apply_pattern");
1359        }
1360    }
1361
1362  if (CmtError::has_pending_error ())
1363    {
1364      if (!Cmt::get_quiet ())
1365        {
1366          cerr << "#CMT> bad syntax in requirements of " << use->get_package_name ()
1367               << " " << use->version
1368               << " " << use->specified_path
1369               << " line #" << line_number;
1370          cerr << " [" << command << " ...]" << endl;
1371        }
1372
1373      return;
1374    }
1375
1376  //
1377  // Then interpret the action
1378  //
1379
1380  keyword->action (words, use, file_name, line_number);
1381}
1382
1383void SyntaxParser::do_parse_words (const CmtSystem::cmt_string_vector& words,
1384                                   const cmt_string& file_name,
1385                                   int line_number,
1386                                   Project* project)
1387{
1388  CmtError::clear ();
1389
1390  if (words.size () == 0) return;
1391
1392  const cmt_string& command = words[0];
1393
1394  if (command.size () == 0) return;
1395
1396  //
1397  // First analyze the syntax
1398  //
1399
1400  Kwd* keyword = m_project_keywords.find (command);
1401  if (keyword == 0)
1402    {
1403      CmtError::set (CmtError::syntax_error, "ParseRequirements> ");
1404    }
1405
1406  if (CmtError::has_pending_error ())
1407    {
1408      if (!Cmt::get_quiet ())
1409        {
1410          cerr << "#CMT> bad syntax in project file of " << project->get_name ()
1411               << " line #" << line_number;
1412          cerr << " [" << command << " ...]" << endl;
1413        }
1414
1415      return;
1416    }
1417
1418  //
1419  // Then interpret the action
1420  //
1421
1422  keyword->action (words, project, file_name, line_number);
1423}
1424
1425
1426
1427
Note: See TracBrowser for help on using the repository browser.