]> SALOME platform Git repositories - modules/yacs.git/blob - src/yacsloader/codeParsers.hxx
Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / yacsloader / codeParsers.hxx
1
2 #ifndef _CODEPARSERS_HXX_
3 #define _CODEPARSERS_HXX_
4
5 #include "parserBase.hxx"
6 #include "dataParsers.hxx"
7
8 #include "factory.hxx"
9
10 namespace YACS
11 {
12
13 /*! \brief Class for code parser in inline nodes.
14  *
15  */
16 struct codetypeParser: parser
17 {
18   static codetypeParser codeParser;
19   virtual void onStart(const XML_Char* el, const XML_Char** attr)
20     {
21       std::string element(el);
22       parser* pp=&parser::main_parser;
23       if(element == "code")pp=&stringtypeParser::stringParser;
24       this->SetUserDataAndPush(pp);
25       pp->init();
26       pp->pre();
27       pp->buildAttr(attr);
28     }
29   virtual void onEnd(const char *el,parser* child)
30     {
31       std::string element(el);
32       if(element == "code")code(((stringtypeParser*)child)->post());
33     }
34   virtual void pre (){_code="";}
35   virtual void code (const std::string& s)
36     {
37       if(_code == "")
38         _code=s;
39       else 
40         _code=_code + '\n' + s;
41     }
42   virtual myfunc post ()
43     {
44       _func._name="script";
45       _func._code=_code;
46       return _func;
47     }
48     std::string _code;
49     myfunc _func;
50 };
51
52 /*! \brief Class for function parser in inline nodes.
53  *
54  */
55 struct functypeParser: codetypeParser
56 {
57   static functypeParser funcParser;
58   virtual void buildAttr(const XML_Char** attr)
59     {
60       required("name",attr);
61       for (int i = 0; attr[i]; i += 2) 
62       {
63         if(std::string(attr[i]) == "name")name(attr[i+1]);
64       }
65     }
66   virtual void name (const std::string& name)
67     {
68       _func._name=name;
69     }
70   virtual myfunc post ()
71     {
72       _func._code=_code;
73       return _func;
74     }
75 };
76
77 }
78
79 #endif