Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
Arc::RSLParser Class Reference

#include <RSLParser.h>

Collaboration diagram for Arc::RSLParser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RSLParser (const std::string s)
 ~RSLParser ()
const RSLParse (bool evaluate=true)

Private Member Functions

void SkipWS ()
RSLBoolOp ParseBoolOp ()
RSLRelOp ParseRelOp ()
std::string ParseString (int &status)
RSLListParseList ()
RSLParseRSL ()

Private Attributes

std::string s
std::string::size_type n
RSLparsed
RSLevaluated

Static Private Attributes

static Logger logger

Detailed Description

Definition at line 210 of file RSLParser.h.


Constructor & Destructor Documentation

Arc::RSLParser::RSLParser ( const std::string  s)

Definition at line 384 of file RSLParser.cpp.

    : s(s),
      n(0),
      parsed(NULL),
      evaluated(NULL) {}

Definition at line 390 of file RSLParser.cpp.

                        {
    if (parsed)
      delete parsed;
    if (evaluated)
      delete evaluated;
  }

Member Function Documentation

const RSL * Arc::RSLParser::Parse ( bool  evaluate = true)

Definition at line 397 of file RSLParser.cpp.

                                           {
    if (n == 0) {
      std::string::size_type pos = 0;
      while ((pos = s.find("(*", pos)) != std::string::npos) {
        std::string::size_type pos2 = s.find("*)", pos);
        if (pos2 == std::string::npos) {
          logger.msg(ERROR, "End of comment not found at position %ld", pos);
          return NULL;
        }
        s.replace(pos, pos2 - pos + 2, 1, ' ');
      }
      parsed = ParseRSL();
      if (!parsed)
        logger.msg(VERBOSE, "RSL parsing failed at position %ld", n);
      else {
        SkipWS();
        if (n != std::string::npos) {
          logger.msg(ERROR, "Junk at end of RSL at position %ld", n);
          delete parsed;
        }
      }
      if (parsed)
        evaluated = parsed->Evaluate();
    }
    return evaluate ? evaluated : parsed;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 428 of file RSLParser.cpp.

                                   {
    switch (s[n]) {
    case '+':
      n++;
      return RSLMulti;
      break;

    case '&':
      n++;
      return RSLAnd;
      break;

    case '|':
      n++;
      return RSLOr;
      break;

    default:
      return RSLBoolError;
      break;
    }
  }

Here is the caller graph for this function:

Definition at line 562 of file RSLParser.cpp.

                                {

    RSLList *values = new RSLList();
    RSLValue *left = NULL;
    RSLValue *right = NULL;

    try {
      int concat = 0; // 0 = No, 1 = Explicit, 2 = Implicit
      do {
        right = NULL;
        int nextconcat = 0;
        std::string::size_type nsave = n;
        SkipWS();
        if (n != nsave)
          concat = 0;
        if (s[n] == '#') {
          n++;
          SkipWS();
          concat = 1;
        }
        if (s[n] == '(') {
          n++;
          RSLList *seq = ParseList();
          SkipWS();
          if (s[n] != ')') {
            logger.msg(ERROR, "Expected ) at position %ld", n);
            throw std::exception();
          }
          n++;
          right = new RSLSequence(seq);
        }
        else if (s[n] == '$') {
          n++;
          SkipWS();
          if (s[n] != '(') {
            logger.msg(ERROR, "Expected ( at position %ld", n);
            throw std::exception();
          }
          n++;
          SkipWS();
          int status;
          std::string var = ParseString(status);
          if (status != 1) {
            logger.msg(ERROR, "Expected variable name at position %ld", n);
            throw std::exception();
          }
          if (var.find_first_of("+&|()=<>!\"'^#$") != std::string::npos) {
            logger.msg(ERROR, "Variable name contains invalid character "
                       "at position %ld", n);
            throw std::exception();
          }
          SkipWS();
          if (s[n] != ')') {
            logger.msg(ERROR, "Expected ) at position %ld", n);
            throw std::exception();
          }
          n++;
          right = new RSLVariable(var);
          nextconcat = 2;
        }
        else {
          int status;
          std::string val = ParseString(status);
          if (status == -1) {
            logger.msg(ERROR, "Broken string at position %ld", n);
            throw std::exception();
          }
          right = (status == 1) ? new RSLLiteral(val) : NULL;
          nextconcat = right ? 2 : 0;
        }
        if (concat == 0) {
          if (left)
            values->Add(left);
          left = right;
        }
        else if (concat == 1) {
          if (!left) {
            logger.msg(ERROR, "no left operand for concatenation operator "
                       "at position %ld", n);
            throw std::exception();
          }
          if (!right) {
            logger.msg(ERROR, "no right operand for concatenation operator "
                       "at position %ld", n);
            throw std::exception();
          }
          left = new RSLConcat(left, right);
        }
        else if (concat == 2) {
          if (left) {
            if (right)
              left = new RSLConcat(left, right);
          }
          else
            left = right;
        }
        concat = nextconcat;
      } while (left || right);
      return values;
    } catch (std::exception e) {
      if (values)
        delete values;
      if (left)
        delete left;
      if (right)
        delete right;
      return NULL;
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 451 of file RSLParser.cpp.

                                 {
    switch (s[n]) {
    case '=':
      n++;
      return RSLEqual;
      break;

    case '!':
      if (s[n + 1] == '=') {
        n += 2;
        return RSLNotEqual;
      }
      return RSLRelError;
      break;

    case '<':
      n++;
      if (s[n] == '=') {
        n++;
        return RSLLessOrEqual;
      }
      return RSLLess;
      break;

    case '>':
      n++;
      if (s[n] == '=') {
        n++;
        return RSLGreaterOrEqual;
      }
      return RSLGreater;
      break;

    default:
      return RSLRelError;
      break;
    }
  }

Here is the caller graph for this function:

RSL * Arc::RSLParser::ParseRSL ( ) [private]

Definition at line 672 of file RSLParser.cpp.

                           {
    SkipWS();
    RSLBoolOp op = ParseBoolOp();
    if (op != RSLBoolError) {
      SkipWS();
      RSLBoolean *b = new RSLBoolean(op);
      do {
        if (s[n] != '(') {
          logger.msg(ERROR, "Expected ( at position %ld", n);
          delete b;
          return NULL;
        }
        n++;
        SkipWS();
        RSL *rsl = ParseRSL();
        if (!rsl) {
          logger.msg(ERROR, "RSL parsing error at position %ld", n);
          delete b;
          return NULL;
        }
        b->Add(rsl);
        SkipWS();
        if (s[n] != ')') {
          logger.msg(ERROR, "Expected ) at position %ld", n);
          delete b;
          return NULL;
        }
        n++;
        SkipWS();
      } while (s[n] == '(');
      return b;
    }
    else {
      int status;
      std::string attr = ParseString(status);
      if (status != 1) {
        logger.msg(VERBOSE, "Expected attribute name at position %ld", n);
        return NULL;
      }
      if (attr.find_first_of("+&|()=<>!\"'^#$") != std::string::npos) {
        logger.msg(ERROR, "Attribute name contains invalid character "
                   "at position %ld", n);
        return NULL;
      }
      SkipWS();
      RSLRelOp op = ParseRelOp();
      if (op == RSLRelError) {
        logger.msg(VERBOSE, "Expected relation operator at position %ld", n);
        return NULL;
      }
      SkipWS();
      RSLList *values = ParseList();
      if (!values) {
        logger.msg(ERROR, "RSL parsing error at position %ld", n);
        return NULL;
      }
      RSLCondition *c = new RSLCondition(attr, op, values);
      return c;
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string Arc::RSLParser::ParseString ( int &  status) [private]

Definition at line 490 of file RSLParser.cpp.

                                              {
    // status: 1 - OK, 0 - not a string, -1 - error
    if (s[n] == '\'') {
      std::string str;
      do {
        std::string::size_type pos = s.find('\'', n + 1);
        if (pos == std::string::npos) {
          logger.msg(ERROR, "End of single quoted string not found "
                     "at position %ld", n);
          status = -1;
          return "";
        }
        str += s.substr(n + 1, pos - n - 1);
        n = pos + 1;
        if (s[n] == '\'')
          str += '\'';
      } while (s[n] == '\'');
      status = 1;
      return str;
    }
    else if (s[n] == '"') {
      std::string str;
      do {
        std::string::size_type pos = s.find('"', n + 1);
        if (pos == std::string::npos) {
          logger.msg(ERROR, "End of double quoted string not found "
                     "at position %ld", n);
          status = -1;
          return "";
        }
        str += s.substr(n + 1, pos - n - 1);
        n = pos + 1;
        if (s[n] == '"')
          str += '"';
      } while (s[n] == '"');
      status = 1;
      return str;
    }
    else if (s[n] == '^') {
      n++;
      char delim = s[n];
      std::string str;
      do {
        std::string::size_type pos = s.find(delim, n + 1);
        if (pos == std::string::npos) {
          logger.msg(ERROR, "End of user delimiter quoted string not found "
                     "at position %ld", n);
          status = -1;
          return "";
        }
        str += s.substr(n + 1, pos - n - 1);
        n = pos + 1;
        if (s[n] == delim)
          str += delim;
      } while (s[n] == delim);
      status = 1;
      return str;
    }
    else {
      std::string::size_type pos =
        s.find_first_of("+&|()=<>!\"'^#$ \t\n\v\f\r", n);
      if (pos == n) {
        status = 0;
        return "";
      }
      std::string str = s.substr(n, pos - n);
      n = pos;
      status = 1;
      return str;
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::RSLParser::SkipWS ( ) [private]

Definition at line 424 of file RSLParser.cpp.

                         {
    n = s.find_first_not_of(" \t\n\v\f\r", n);
  }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 238 of file RSLParser.h.

Logger Arc::RSLParser::logger [static, private]

Definition at line 239 of file RSLParser.h.

std::string::size_type Arc::RSLParser::n [private]

Definition at line 236 of file RSLParser.h.

Definition at line 237 of file RSLParser.h.

std::string Arc::RSLParser::s [private]

Definition at line 235 of file RSLParser.h.


The documentation for this class was generated from the following files: