summaryrefslogtreecommitdiffabout
path: root/include/sitecing/sitecing_parser.h
Side-by-side diff
Diffstat (limited to 'include/sitecing/sitecing_parser.h') (more/less context) (ignore whitespace changes)
-rw-r--r--include/sitecing/sitecing_parser.h326
1 files changed, 326 insertions, 0 deletions
diff --git a/include/sitecing/sitecing_parser.h b/include/sitecing/sitecing_parser.h
new file mode 100644
index 0000000..22d716f
--- a/dev/null
+++ b/include/sitecing/sitecing_parser.h
@@ -0,0 +1,326 @@
+#ifndef __SITECING_SITECING_PARSER_H
+#define __SITECING_SITECING_PARSER_H
+
+#include <string>
+#include <list>
+#include <map>
+#include <stdexcept>
+using namespace std;
+
+#include "sitecing/component_factory.h"
+using namespace sitecing;
+
+/**
+ * @file
+ * @brief The component source parser.
+ */
+
+#ifndef sitecing_parser_flexlexer_once
+#define sitecing_parser_flexlexer_once
+#undef yyFlexLexer
+#define yyFlexLexer sitecing_parserFlexLexer
+#include <FlexLexer.h>
+#undef yyFlexLexerOnce
+#endif
+
+/**
+ * The component source parser.
+ */
+class sitecing_parser : public sitecing_parserFlexLexer {
+ public:
+ /**
+ * The ancestor class definition.
+ */
+ class ancestor_class {
+ public:
+ /**
+ * The class name.
+ */
+ string name;
+ /**
+ * The source component path.
+ */
+ string path;
+
+ /**
+ * @param n the class name.
+ * @param p the component path.
+ */
+ ancestor_class(const string& n,const string& p)
+ : name(n), path(p) { }
+ };
+ /**
+ * The list of ancestor classes.
+ */
+ typedef list<ancestor_class> ancestor_classes_t;
+ /**
+ * The ancestor classes.
+ */
+ ancestor_classes_t ancestor_classes;
+ /**
+ * The member variable definition.
+ */
+ class member_variable {
+ public:
+ /**
+ * The member variable type.
+ */
+ string type;
+ /**
+ * The member variable name.
+ */
+ string name;
+ /**
+ * The member variable is a component.
+ */
+ bool bComponent;
+ /**
+ * The variable initializer.
+ */
+ string initializer;
+ /**
+ * @todo TODO: wish I could remember -- document me.
+ */
+ bool bTypeOnly;
+
+ /**
+ * @param t type.
+ * @param n name.
+ * @param i initializer.
+ * @param bc whether it is a component.
+ * @param bto @todo TODO: @see bTypeOnly.
+ */
+ member_variable(const string& t,const string& n,const string& i,bool bc = false,bool bto = false)
+ : type(t), name(n), initializer(i), bComponent(bc), bTypeOnly(bto) { }
+ };
+ /**
+ * The list of member variables.
+ */
+ typedef list<member_variable> member_variables_t;
+ /**
+ * Member variables.
+ */
+ member_variables_t member_variables;
+ /**
+ * @todo TODO: wish I could remember the details -- document me.
+ */
+ bool have_initializers;
+ /**
+ * Whether the component has a constructor defined.
+ */
+ bool have_constructor;
+ /**
+ * Member function definition.
+ */
+ class member_function {
+ public:
+ /**
+ * Return type.
+ */
+ string type;
+ /**
+ * Function name.
+ */
+ string name;
+ /**
+ * Arguments declaration.
+ */
+ string args;
+ /**
+ * Function body.
+ */
+ string body;
+
+ /**
+ * @param t type.
+ * @param n name.
+ * @param a arguments.
+ * @param b body.
+ */
+ member_function(const string& t,const string& n,const string& a,const string& b)
+ : type(t), name(n), args(a), body(b) { }
+ };
+ /**
+ * The list of member functions.
+ */
+ typedef list<member_function> member_functions_t;
+ /**
+ * Member functions.
+ */
+ member_functions_t member_functions;
+ /**
+ * Current mode of operation.
+ */
+ class modus_operandi {
+ public:
+ /**
+ * The state enumeration.
+ */
+ enum modus_t {
+ /**
+ * Building the code.
+ */
+ modus_code = 0,
+ /**
+ * Ready to do the '<<' thing.
+ */
+ modus_preop,
+ /**
+ * Just made a '<<'.
+ */
+ modus_postop,
+ /**
+ * Outputting raw output data.
+ */
+ modus_text,
+ /**
+ * The number of modes.
+ */
+ modi
+ };
+ /**
+ * Processing flags enumeration.
+ */
+ enum {
+ /**
+ * Eat the comments.
+ */
+ flag_devour_comments = 0x0001,
+ /**
+ * Eat whitespace.
+ */
+ flag_devour_whitespace = 0x0002
+ };
+ /**
+ * The processing mode.
+ */
+ modus_t modus;
+ /**
+ * The processing flags.
+ */
+ int flags;
+ /**
+ * Output being built.
+ */
+ string output;
+ /**
+ * The type for compound modes.
+ */
+ string _type;
+ /**
+ * The last id encountered.
+ */
+ string _lastid;
+ /**
+ * The name for compound modes.
+ */
+ string _name;
+ /**
+ * The argument declaration. Obviously for member functions.
+ */
+ string _args;
+
+ /**
+ * @param flags.
+ * @see flags
+ */
+ modus_operandi(int f = 0)
+ : modus(modus_code), flags(f) { }
+
+ /**
+ * Change the processing mode.
+ */
+ void modify(modus_t m);
+
+ /**
+ * See if we're eating up whitespaces.
+ */
+ bool devour_whitespace() { return flags&flag_devour_whitespace; }
+ /**
+ * See if we're eating up the comments.
+ */
+ bool devour_comments() { return flags&flag_devour_comments; }
+ };
+ /**
+ * The modes stack type.
+ */
+ typedef list<modus_operandi> modi_operandi;
+ /**
+ * The modes stack.
+ */
+ modi_operandi modi;
+ /**
+ * Input file name.
+ */
+ string input_file;
+ /**
+ * Base class name.
+ */
+ string base_class;
+ /**
+ * Base class header.
+ */
+ string base_header;
+ /**
+ * Component's basename.
+ * @todo TODO: wish I could remember the details -- document me.
+ */
+ string component_basename;
+ /**
+ * The skeleton file name.
+ */
+ string skeleton;
+ /**
+ * The component class name.
+ */
+ string class_name;
+ /**
+ * Output basename.
+ * @todo TODO: wish I could remember the details -- document me.
+ */
+ string output_basename;
+ /**
+ * Verbatim declaration part.
+ */
+ string decl;
+ /**
+ * Verbatim implementation part.
+ */
+ string impl;
+ /**
+ * The reference to the component factory object.
+ */
+ component_factory& factory;
+
+ /**
+ * @param f the component factory.
+ */
+ sitecing_parser(component_factory& f);
+
+ /**
+ * Preprocess file.
+ * @param in input file name.
+ */
+ void preprocess(const string& in);
+
+ virtual void LexerOutput(const char *buf,int size);
+ virtual int yylex();
+
+ /**
+ * Retrieve reference to the to of the modes stack.
+ * @return the reference in question.
+ */
+ modus_operandi& M() {
+ return modi.front();
+ }
+ /**
+ * Anchor the output with the #line, if we're not in the text output mode.
+ */
+ void soft_anchor();
+ /**
+ * Anchor the output with the #line directive, changing to the appropriate output mode if needed.
+ */
+ void anchor();
+};
+
+#endif /* __SITECING_SITECING_PARSER_H */