Marmot - Main Menu

Marmot Specifications

1. Data class generator specifications

This Marmot File is constitued of 3 parts :

1.1 Options

%class name : where name represents the Class name to generate
%herit father : class name herit from father
%namespace father : give class namespace (for example : Test::Marmot)
%language name : name can be one one the following : c++/java/eiffel
%debug : when given, marmot give a verbose output
%assert : add assert on vector and list (check bounds)
%template <details> : details represents the template type, for example %template <Type, Type2>

1.2 C++/Java/... user code

this code is added to generated file, it can contains include, methods, variables...

1.3 Class Variable

you can add severals kind of variable :

%var type name(init_val) : type represents the varible type (int, float, std::string, ...)
This will generate a protected variable (type _name) and three public methods (example for C++) :

  • const type& get_name() const { return _name; }
  • type& get_name() { return _name; }
  • void set_name(const type& name) { _name = name; }

  • %var_list type name : type represents the list type (int, float, std::string, ...)
    This will generate a protected variable (std::list _name) and four public methods (example for C++) :

  • const std::list& get_name() const { return _name; }
  • std::list& get_name() { return _name; }
  • void set_name(const std::list& name) { _name = name; }
  • void add_name(const type& name) { _name.push_back(name); }

  • %var_vect type name : type represents the vector type (int, float, std::string, ...)
    This will generate a protected variable (std::vector _name) and six public methods (example for C++) :

  • const std::vector& get_name() const { return _name; }
  • std::vector& get_name() { return _name; }
  • const type& get_name(unsigned int pos) const { return _name[pos]; }
  • type& get_name(unsigned int pos) { return _name[pos]; }
  • void set_name(const std::vector& name) { _name = name; }
  • void add_name(const type& name) { _name.push_back(name); }
  • 2. XML parser generator specifications

    This Marmot File is constitued of 3 parts :

    2.1 Options

    %backend type : where type can be one of the following : (xerces-dom, xerces-sax, expat, libxml)
    %dtd "file" : file represent a dtd file for xml check
    %gen_data file1 file2 : file1 and file2 are data file to generate, this does not need to lauch Marmot many times
    %language name : name can be one one the following : c++/java/eiffel
    %debug : output verbose information

    2.2 C++/Java/... user code

    this code is added to generated file, it can contains include, methods, variables...

    2.3 XML parser details

    A Marmot file has four main sections, show here with the appropriate delimiters:
    OPTIONS
    
    %{
      PROLOGUE
    %}
    
    TYPES
    
    XML RULES
    
    Comments enclosed in `/* ... */' may appear in any of the sections.

    2.3.1 PROLOGUE

    The PROLOGUE section contains macro definitions and declarations of functions and variables that are used in the actions in the XML rules. These are copied to the beginning of the parser file so that they precede the definition of rules. You can use `#include' to get the declarations from a header file. If you don't need any C declarations, you may omit the `%{' and `%}' delimiters that bracket this section.

    2.3.2 TYPES

    The TYPES section contains node type. In some simple xml rules, you may not need any declarations.

    Synthax of Type is :
    %type type_name node_name

    2.3.3 XML RULES

    A XML rule has the following general form:
    result{1} : components ...
    @read@
    { code statements }
    @write@
    { code statements }
    
    where result is the name of the node, and components are various sub nodes name that are associates with this node.
    {a} is the number of node 'result' than can be found as child of a father.
    'a' can contains symbols : '>', '<', '>=', '<=', '||', '&&'
    For example '{5 || 10}', '{>=2}', '{<=10}'
  • @read@ code statements are executed when entering in 'result' node in a read XML parser
  • @write@ c++ statements are executed when entering in 'result' node in a write XML parser
  • This blocs(@...@ {...}) are needed(at least one), you can have nodes with only @read@ or @write@.

    sometimes, write blocs need a loop (many node to write), you can add a loop between the '@write@' and the '{', For example :
    example_node:
    @write@
    @for(unsigned int i = 0; i < $father->get_vars().size(); i++)@
    {
      //Code in this loop
    }
    
    2.3.3.1 Read/Write node data and attributs
    you can read/write atrtibut of a node with @attribut_name@
    you can read/write node data with $data
    you can use father node (when there is a %type on father) with $father
    you can call Method of objet associted with current node with $$

    2.4 Toolbox functions

    Marmot contains many functions to simply convertions :

  • int marmot::toInt(const std::string str);
  • float marmot::toFloat(const std::string str);
  • double marmot::toDouble(const std::string str);
  • bool marmot::toBool(const std::string str);
  • std::string marmot::toString(const float);
  • std::string marmot::toString(const int);
  • std::string marmot::toString(const double);
  • std::string marmot::toString(const bool);

  • Copyright © 2002-2003 Julien LEMOINE