/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Types | Public Member Functions | Private Member Functions | Private Attributes
Gaudi::Parsers::Parser Class Reference

Parser controller. More...

#include <ParserUtils.h>

Collaboration diagram for Gaudi::Parsers::Parser:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Sign { S_ASSIGN = 0, S_PLUSASSIGN = 1, S_MINUSASSIGN = 2 }
typedef std::vector
< Gaudi::Parsers::Message
MessagesStoreT

Public Member Functions

 Parser (Catalogue &catalogue, std::vector< std::string > &included, std::ostream &m=std::cout)
 Default creator.
bool parse (const std::string &fileName)
 Start parse file.
const std::vector< Message > & messages ()
 Return parser messages.
int errorsCount ()
 Count of errors.
void matchInclude (const std::string &fileName, const Position &pos)
 Do actions when include file is matched.
void matchAssign (const std::string &objName, const std::string &propName, const Sign &oper, const std::vector< std::string > &vectorValues, const Position &pos, bool isVector)
 Do actions when we match property.
void setIsPrint (bool on, const Position &pos)
 Control printing.
void setIsPrintOptions (bool on, const Position &pos)
 Control printing options.

Private Member Functions

bool parseFile (const std::string &fileName, const Position &pos)
 Parse file from another file.
void resolveReferences ()
 Resolve references.
void addMessage (const Message::Severity &severity, const Message::Code &code, const std::string &message, const Position &pos)
 Add message.
std::string severityName (Message::Severity severity)
 String representation of severity.
bool isIncluded (const std::string &fileName)
 Test if file already included.
std::string sign (Sign aSign)
 String representation of sign.
std::string valueToString (std::vector< std::string > value, bool isVector)
 String representation of value vector.
std::string posString (int line, int column)
 Convert position to string.

Private Attributes

bool m_isPrint
bool m_isPrintOptions
Cataloguem_catalogue
std::vector< std::string > & m_included
MessagesStoreT m_messages
std::ostream & m_stream

Detailed Description

Parser controller.

Author:
Alexander Mazurov
Date:
2006-02-17

Definition at line 100 of file ParserUtils.h.


Member Typedef Documentation

Definition at line 103 of file ParserUtils.h.


Member Enumeration Documentation

Enumerator:
S_ASSIGN 
S_PLUSASSIGN 
S_MINUSASSIGN 

Definition at line 104 of file ParserUtils.h.

        {
          S_ASSIGN      = 0 ,
          S_PLUSASSIGN  = 1 ,
          S_MINUSASSIGN = 2
        };

Constructor & Destructor Documentation

Gaudi::Parsers::Parser::Parser ( Catalogue catalogue,
std::vector< std::string > &  included,
std::ostream &  m = std::cout 
)

Default creator.

Definition at line 29 of file Parser.cc.

  : m_isPrint(false)
  , m_isPrintOptions(true)
  , m_catalogue(catalogue)
  , m_included(included)
  , m_stream ( m )
{
}

Member Function Documentation

bool Gaudi::Parsers::Parser::parse ( const std::string &  fileName)

Start parse file.

Returns:
true if no errors
Parameters:
fileNameFile to parse

Definition at line 40 of file Parser.cc.

{
  //m_stream << GPP_COMMENT + std::string(80,'=') << std::endl;
  bool sc = parseFile(fileName,Position());
  resolveReferences();
  if ( sc && m_isPrintOptions ){
      m_stream << m_catalogue;
      m_stream << "// " << std::string(82,'=') << std::endl;
  }
  return errorsCount()==0?true:false;
}
const std::vector<Message>& Gaudi::Parsers::Parser::messages ( ) [inline]

Return parser messages.

Definition at line 120 of file ParserUtils.h.

{return m_messages;}
int Gaudi::Parsers::Parser::errorsCount ( )

Count of errors.

Definition at line 52 of file Parser.cc.

{
        int result=0;
        for ( MessagesStoreT::const_iterator cur=m_messages.begin();
        cur!=m_messages.end() ; ++cur)
  { if ( cur->severity() == Message::E_ERROR){ ++result; } }
        return result;
}
void Gaudi::Parsers::Parser::matchInclude ( const std::string &  fileName,
const Position pos 
)

Do actions when include file is matched.

Parameters:
fileNameFile to include

Definition at line 62 of file Parser.cc.

{ parseFile(fileName,pos); }
void Gaudi::Parsers::Parser::matchAssign ( const std::string &  objName,
const std::string &  propName,
const Sign oper,
const std::vector< std::string > &  vectorValues,
const Position pos,
bool  isVector 
)

Do actions when we match property.

Parameters:
objNameObject name
propNameProperty name
operOperation ("=","+=","-=")
valueString value
vectorValuesVector values

Definition at line 66 of file Parser.cc.

{
  // --------------------------------------------------------------------------
  if( m_isPrint )
  {
    m_stream 
      << boost::format("%2% %3% %4%;%|72t|%5% %1%") 
      % posString(pos.line(),pos.column()) 
      % (objName+"."+propName) 
      % sign(oper) 
      % valueToString(vectorValue , isVector) 
      % GPP_COMMENT 
      << std::endl ;
  }
  // --------------------------------------------------------------------------
  // --------------------------------------------------------------------------
  if (oper == S_ASSIGN)
  {
    // ------------------------------------------------------------------------
    PropertyEntry* assignProp;
    if(isVector){
      assignProp = new PropertyEntry(propName,vectorValue,pos);
    }else{
      assignProp = new PropertyEntry(propName,vectorValue[0],pos);
    }
    m_catalogue.addProperty(objName,*assignProp);
    delete assignProp;
    // ------------------------------------------------------------------------
  }
  else
  {
    // += or -=
    // ------------------------------------------------------------------------
    PropertyEntry foundProp;
    bool ok;
    ok = m_catalogue.findProperty(objName,propName,foundProp);
    if (!ok)
    {
      foundProp = PropertyEntry(propName,std::vector<std::string>());
    }
    if(oper == S_PLUSASSIGN)
    {
      ok = foundProp.addValues(vectorValue);
      if(!ok){
        addMessage
          ( Message::E_ERROR, 
            Message::C_CANNOTADDTONOTVECTOR,
            boost::str
            ( boost::format
              ("Cannot add values to not vector property \"%1%.%2%\"")
              %  objName % propName),pos);
        return;
      }
      m_catalogue.addProperty(objName,foundProp);
    }
    // ------------------------------------------------------------------------
    if(oper == S_MINUSASSIGN)
    {
      int count=0;
      ok = foundProp.removeValues(vectorValue,count);
      if(!ok){
        addMessage
          ( Message::E_ERROR, 
            Message::C_CANNOTREMOVEFROMNOTVECTOR,
            boost::str
            ( boost::format
              ( "Cannot remove values from not vector property \"%1%.%2%\"" ) 
              %  objName % propName),pos);
        return;
      }
      // ----------------------------------------------------------------------
      if (count == 0)
      {
        addMessage
          ( Message::E_WARNING, 
            Message::C_ZEROREMOVED,
            boost::str
            ( boost::format
              ( "Nothing removed from property \"%1%.%2%\"" ) 
              %  objName % propName),pos);   
      }
      else
      {
        m_catalogue.addProperty(objName,foundProp);
      }
      
    } 
    // ------------------------------------------------------------------------
  }
}
void Gaudi::Parsers::Parser::setIsPrint ( bool  on,
const Position pos 
)

Control printing.

Definition at line 162 of file Parser.cc.

{
  // ignore the printout if the full print is activated  
  if ( on && m_isPrintOptions ) { return ; }
  m_isPrint = on;
  //m_stream 
  //  << boost::format("%3% printing is %2% %|78t|%1%") 
  //  % posString(pos.line(),pos.column()) 
  //  % (on?"ON":"OFF") 
  //  % GPP_COMMENT 
  //  << std::endl ;
}
void Gaudi::Parsers::Parser::setIsPrintOptions ( bool  on,
const Position pos 
)

Control printing options.

Definition at line 176 of file Parser.cc.

{
  m_isPrintOptions = on;
  //m_stream 
  //  << boost::format ("%3% printing options is %2% %|78t|%1%") 
  //  % posString(pos.line(),pos.column()) 
  //  % (on?"ON":"OFF") 
  //  % GPP_COMMENT 
  //  << std::endl ;
  // deactivate the printout if the print of all options is activated 
  if ( m_isPrintOptions && m_isPrint ) { setIsPrint ( false , pos ) ; }
}
bool Gaudi::Parsers::Parser::parseFile ( const std::string &  fileName,
const Position pos 
) [private]

Parse file from another file.

Returns:
true if no *syntax* errors appears
Parameters:
fileNameFile to parse Information about from what file we call parsing of file

Definition at line 190 of file Parser.cc.

{
  std::string fileToParse;
  bool ok = Gaudi::Parsers::Utils::searchFile(fileName,fileToParse);
  if(!ok){
    addMessage( Message::E_ERROR, Message::C_FILENOTFOUND,
               boost::str(boost::format("Couldn't find file \"%1%\"") % fileName),pos);
    return false;
  }
  
  ok = isIncluded(fileToParse);
  if(ok)
  {
    const std::string _msg = 
      ( boost::format("Skip already included file  \"%1%\"") % fileToParse ).str() ;
    addMessage ( Message::E_WARNING , Message::C_OK , _msg , pos ) ;
    if ( m_isPrint ) 
    { 
      m_stream 
        << boost::format("%3% skip already included file  \"%2%\" %|78t|%1%") 
        % posString(pos.line(), pos.column()) 
        % fileToParse 
        % GPP_COMMENT
        << std::endl ; 
    }
    return true;
  }
  std::string input;
  ok = Gaudi::Parsers::Utils::readFile(fileToParse,input);
  if(!ok)
  {
    addMessage
      ( Message::E_ERROR, Message::C_FILENOTOPENED,
       boost::str
       (boost::format("Couldn't open file \"%1%\"") % fileToParse),pos);
    return false;
  }  
  m_included.push_back(fileToParse);
  
  
  IteratorT beginpos(input.begin(), input.end(), fileToParse);
  IteratorT endpos;
  
  boost::spirit::parse_info<IteratorT> info; 
  SkipperGrammar grSkipper;      
  
  //m_stream 
  //    << boost::format("%3% include \"%2%\" %|78t|%1%") 
  //    % posString(pos.line(), pos.column()) 
  //    % fileToParse 
  //    % GPP_COMMENT 
  //    << std::endl ;
  ParserGrammar grParser(this);
  info = boost::spirit::parse(beginpos, endpos, grParser >> end_p,grSkipper);

  boost::spirit::file_position stoppos = info.stop.get_position();
  if (!info.full) {
    addMessage(Message::E_ERROR, Message::C_SYNTAXERROR,
               "Syntax error",Position(stoppos.file,stoppos.line,stoppos.column));
    return false;      
  }
  {
    std::string _msg =
      ( boost::format("Parsed file \"%2%\" %|78t|%1%")  
        % posString(stoppos.line, stoppos.column) 
        % fileToParse ) .str() ;
    addMessage ( Message::E_VERBOSE , 
                 Message::C_OK , 
                 _msg ,
                 Position(stoppos.file,stoppos.line,stoppos.column) ) ;
    if ( m_isPrint )
    { 
      m_stream 
        << boost::format("%3% end  \"%2%\" %|78t|%1%")
        % posString(stoppos.line, stoppos.column) 
        % fileToParse 
        % GPP_COMMENT 
        << std::endl ; 
    }
  }
  return true;  
}
void Gaudi::Parsers::Parser::resolveReferences ( ) [private]

Resolve references.

Definition at line 323 of file Parser.cc.

{
  Catalogue::CatalogueT cat = m_catalogue.catalogue();
  // ----------------------------------------------------------------------------
  for( Catalogue::CatalogueT::const_iterator curObj = cat.begin();  
       curObj!=cat.end();curObj++)
  {
    std::string objName = curObj->first;
    // ------------------------------------------------------------------------
    for( std::vector<PropertyEntry>::const_iterator curProp = 
           curObj->second.begin();curProp != curObj->second.end(); curProp++)
    {
      std::string value = curProp->value();
      if ( (value.length()>0) && (value[0]=='@'))
      {
        // --------------------------------------------------------------------
        std::vector<std::string> objAndProp;
        std::string refprop(value.begin()+1,value.end());
        ba::split(objAndProp,
                  refprop,
                  ba::is_any_of("."));            
        PropertyEntry foundProperty;
        bool ok;
        ok = m_catalogue.findProperty(objAndProp[0],objAndProp[1],
                                      foundProperty);
        if(!ok)
        {
          addMessage
            ( Message::E_ERROR,
              Message::C_PROPERTYNOTFOUND,
              boost::str(boost::format("Cannot find property \"%1%.%2%\"")
                         % objAndProp[0] % objAndProp[1]),curProp->position());
        }
        else
        {
          // -------------------------------------------------------------------
          if((ba::to_lower_copy(objAndProp[0]) == objName)
             && 
             (ba::to_lower_copy(objAndProp[1]) 
              == curProp->name()))
          {
            // ----------------------------------------------------------------
            addMessage
              ( Message::E_ERROR,
                Message::C_BADREFERENCE,
                boost::str(boost::format("Reference to self \"%1%.%2%\"")
                           % objAndProp[0] % objAndProp[1]),curProp->position());
            // ----------------------------------------------------------------
          }
          else
          {
            PropertyEntry property = foundProperty;
            property.setName(curProp->name());
            m_catalogue.addProperty(objName,property);
          }
          // ------------------------------------------------------------------
        }
        // --------------------------------------------------------------------
      }
    }
    // ------------------------------------------------------------------------
  }
}
void Gaudi::Parsers::Parser::addMessage ( const Message::Severity severity,
const Message::Code code,
const std::string &  message,
const Position pos 
) [private]

Add message.

Parameters:
severityMessage severity
codeCode of message
messageMessage
posFile position

Definition at line 292 of file Parser.cc.

{
  Message result
    ( severity , code,
      boost::str(boost::format("%1%(%2%,%3%) : %4% #%5% : %6%") % pos.fileName()
                 % pos.line() % pos.column() % severityName(severity) % code 
                 % message));
  m_messages.push_back(result);
}
std::string Gaudi::Parsers::Parser::severityName ( Message::Severity  severity) [private]

String representation of severity.

Returns:
Representation of severity
Parameters:
severitySeverity

Definition at line 275 of file Parser.cc.

                          {
  switch(severity)
  {
  case Message::E_ERROR   :
    return "ERROR"     ;
  case Message::E_WARNING :
    return "WARNING"   ;
  case Message::E_NOTICE  :
    return "NOTICE"    ;
  case Message::E_VERBOSE :
    return "VERBOSE"   ;
  default:
    return "UNDEFINED" ; 
  }
}
bool Gaudi::Parsers::Parser::isIncluded ( const std::string &  fileName) [private]

Test if file already included.

Returns:
true if file already included
Parameters:
fileNameFile name

Definition at line 311 of file Parser.cc.

{
  for(std::vector<std::string>::const_iterator cur=m_included.begin();
      cur!=m_included.end();cur++)
  { if(fileName==*cur){ return true; } }
  return false;
}
std::string Gaudi::Parsers::Parser::sign ( Sign  aSign) [private]

String representation of sign.

Definition at line 389 of file Parser.cc.

{
  switch(aSign)
  {
  case S_ASSIGN:
    return "=";
  case S_PLUSASSIGN:
    return "+=";
  case S_MINUSASSIGN:
    return "-=";
  default:
    return "unknown_operation";
  }
}
std::string Gaudi::Parsers::Parser::valueToString ( std::vector< std::string >  value,
bool  isVector 
) [private]

String representation of value vector.

Definition at line 407 of file Parser.cc.

{
  if ( !isVector){ return value[0]; }
  //
  std::string result;
  std::string delim;
  result+=" [ ";
  for ( std::vector<std::string>::const_iterator cur = value.begin();
        cur != value.end(); cur++ )
  {
    result += delim + *cur;
    delim = " , ";
  }
  return result + " ] ";
}
std::string Gaudi::Parsers::Parser::posString ( int  line,
int  column 
) [private]

Convert position to string.

Returns:
string representation of position
Parameters:
lineLine
columnColumn

Definition at line 430 of file Parser.cc.

{ return boost::str(boost::format("(%1%,%2%)") % line % column); }

Member Data Documentation

Definition at line 146 of file ParserUtils.h.

Definition at line 147 of file ParserUtils.h.

Definition at line 148 of file ParserUtils.h.

std::vector<std::string>& Gaudi::Parsers::Parser::m_included [private]

Definition at line 149 of file ParserUtils.h.

Definition at line 150 of file ParserUtils.h.

std::ostream& Gaudi::Parsers::Parser::m_stream [private]

Definition at line 151 of file ParserUtils.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:50:18 for LafKernel by doxygen 1.7.4