Esempio n. 1
0
static ASTPtr parseSpecifiedLengthContent(const char** fptr, const char*** wordSourcesPtr, const LengthFunc** lengthFuncsPtr) {
  assert(**fptr == '\'' || std::isdigit(**fptr) || **fptr == '#');
  ASTPtr slc;
  if (**fptr == '\'') {
    slc = parseStringLiteral(fptr);
  } else if (**fptr == '#') {
    slc = parseRepeatedCharFL(fptr, lengthFuncsPtr);
  } else {
    const char* f_at = *fptr;
    LiteralLength length = parseLiteralLength(fptr);
    if (**fptr == '\'') {
      slc.reset(new RepeatedCharLL(f_at, length, parseCharLiteral(fptr)));
    } else if (**fptr == '[') {
      Block* block = new Block(f_at, length);
      slc.reset(block);
      ++*fptr;
      parseWhitespaces(fptr); // [ is a token
      while (**fptr != ']') {
        if (**fptr == '\'' || std::isdigit(**fptr) || **fptr == '#') {
          block->addChild(parseSpecifiedLengthContent(fptr, wordSourcesPtr, lengthFuncsPtr));
        } else if (**fptr == '{') {
          block->addWords(parseWords(fptr, wordSourcesPtr));
        } else {
          throw DSLException(*fptr, "Expected ', digit, or # to begin specified-length content, "
            "or { to begin greedy-length content.");
        }
      }
      ++*fptr;
      parseWhitespaces(fptr); // ] is a token
      if (**fptr == '^') {
        parseTopOrBottomFiller(fptr, &block->topFillers, true);
        if (**fptr == 'v') {
          parseTopOrBottomFiller(fptr, &block->bottomFillers, false);
        }
      } else if (**fptr == 'v') {
        parseTopOrBottomFiller(fptr, &block->bottomFillers, false);
        if (**fptr == '^') {
          parseTopOrBottomFiller(fptr, &block->topFillers, true);
        }
      }
    } else {
      throw DSLException(*fptr, "Expected ' or [ after length specifier.");
    }
  }
  return slc;
}
Esempio n. 2
0
// Parses 0 or more fillers
static void parseFillers(const char** fptr, std::vector<FillerPtr>* fillers) {
  while (**fptr == '\'' || std::isdigit(**fptr)) {
    FillerPtr filler;
    if (**fptr == '\'') {
      filler = parseStringLiteral(fptr);
    } else {
      const char* f_at = *fptr;
      LiteralLength length = parseLiteralLength(fptr);
      if (**fptr == '\'') {
        char c = parseCharLiteral(fptr);
        filler.reset(new RepeatedCharLL(f_at, length, c));
      } else {
        throw DSLException(*fptr, "Expected char literal after literal length.");
      }
    }
    fillers->push_back(std::move(filler));
  }
}
Esempio n. 3
0
char *OpenDDLParser::parseProperty( char *in, char *end, Property **prop ) {
    *prop = ddl_nullptr;
    if( ddl_nullptr == in || in == end ) {
        return in;
    }

    in = lookForNextToken( in, end );
    Text *id( ddl_nullptr );
    in = parseIdentifier( in, end, &id );
    if( ddl_nullptr != id ) {
        in = lookForNextToken( in, end );
        if( *in == '=' ) {
            ++in;
            in = getNextToken( in, end );
            Value *primData( ddl_nullptr );
            if( isInteger( in, end ) ) {
                in = parseIntegerLiteral( in, end, &primData );
                createPropertyWithData( id, primData, prop );
            } else if( isFloat( in, end ) ) {
                in = parseFloatingLiteral( in, end, &primData );
                createPropertyWithData( id, primData, prop );
            } else if( isStringLiteral( *in ) ) { // string data
                in = parseStringLiteral( in, end, &primData );
                createPropertyWithData( id, primData, prop );
            } else {                              // reference data
                std::vector<Name*> names;
                in = parseReference( in, end, names );
                if( !names.empty() ) {
                    Reference *ref = new Reference( names.size(), &names[ 0 ] );
                    ( *prop ) = new Property( id );
                    ( *prop )->m_ref = ref;
                }
            }
        } else {
            delete id;
        }
    }

    return in;
}
Esempio n. 4
0
char *OpenDDLParser::parseDataList( char *in, char *end, Value::ValueType type, Value **data, 
                                    size_t &numValues, Reference **refs, size_t &numRefs ) {
    *data = ddl_nullptr;
    numValues = numRefs = 0;
    if( ddl_nullptr == in || in == end ) {
        return in;
    }

    in = lookForNextToken( in, end );
    if( *in == '{' ) {
        ++in;
        Value *current( ddl_nullptr ), *prev( ddl_nullptr );
        while( '}' != *in ) {
            current = ddl_nullptr;
            in = lookForNextToken( in, end );
            if ( Value::ddl_ref == type ) {
                std::vector<Name*> names;
                in = parseReference( in, end, names );
                if ( !names.empty() ) {
                    Reference *ref = new Reference( names.size(), &names[ 0 ] );
                    *refs = ref;
                    numRefs = names.size();
                }
            } else  if ( Value::ddl_none == type ) {
                if (isInteger( in, end )) {
                    in = parseIntegerLiteral( in, end, &current );
                } else if (isFloat( in, end )) {
                    in = parseFloatingLiteral( in, end, &current );
                } else if (isStringLiteral( *in )) {
                    in = parseStringLiteral( in, end, &current );
                } else if (isHexLiteral( in, end )) {
                    in = parseHexaLiteral( in, end, &current );
                }
            } else {
                switch(type){
                    case Value::ddl_int8:
                    case Value::ddl_int16:
                    case Value::ddl_int32:
                    case Value::ddl_int64:
                    case Value::ddl_unsigned_int8:
                    case Value::ddl_unsigned_int16:
                    case Value::ddl_unsigned_int32:
                    case Value::ddl_unsigned_int64:
                        in = parseIntegerLiteral( in, end, &current, type);
                        break;
                    case Value::ddl_half:
                    case Value::ddl_float:
                    case Value::ddl_double:
                        in = parseFloatingLiteral( in, end, &current, type);
                        break;
                    case Value::ddl_string:
                        in = parseStringLiteral( in, end, &current );
                        break;
                    default:
                        break;
                }
            }

            if( ddl_nullptr != current ) {
                if( ddl_nullptr == *data ) {
                    *data = current;
                    prev = current;
                } else {
                    prev->setNext( current );
                    prev = current;
                }
                ++numValues;
            }

            in = getNextSeparator( in, end );
            if( ',' != *in && Grammar::CloseBracketToken[ 0 ] != *in && !isSpace( *in ) ) {
                break;
            }
        }
        ++in;
    }

    return in;
}
Esempio n. 5
0
bool
FormProcTokenParse(Units *units, Function *fn, llvm::BasicBlock *block,
                   Node *node, bool get_address, bool prefixed_with_core,
                   Type *wanted_type, ParseResult *pr)
{
    Context *ctx = units->top()->ctx;

    Token *t = node->token;

    if (t->type == TokenType::Int) {
        parseIntegerLiteral(ctx, wanted_type, block, t, pr);
        return true;
    } else if (t->type == TokenType::FloatingPoint) {
        parseFloatingPointLiteral(ctx, wanted_type, block, t, pr);
        return true;
    }

    Enum *enum_obj;
    if (wanted_type
            && (wanted_type->struct_name.size())
            && (enum_obj = ctx->getEnum(wanted_type->struct_name.c_str()))) {

        Struct *st = ctx->getStruct(wanted_type->struct_name.c_str());
        assert(st && "no struct associated with enum");

        int error_count_begin =
            ctx->er->getErrorTypeCount(ErrorType::Error);

        /* This will fail when the token is not a valid literal, so
         * in that case just continue onwards, because the token may
         * be validly parsed in other ways. */
        bool res = FormLiteralEnumParse(units, block, node, enum_obj,
                                        wanted_type, st, get_address,
                                        pr);
        if (res) {
            return res;
        } else {
            ctx->er->popErrors(error_count_begin);
        }
    }

    if (t->type == TokenType::String) {
        pr->value = NULL;
        parseBoolLiteral(ctx, block, node, pr);
        if (pr->value) {
            return true;
        }

        parseCharLiteral(ctx, block, node, pr);
        if (pr->value) {
            return true;
        }

        parseVariableLiteral(ctx, block, node, get_address, pr);
        if (pr->value) {
            return true;
        } else {
            return false;
        }
    } else if (t->type == TokenType::StringLiteral) {
        pr->value = NULL;
        return parseStringLiteral(units, ctx, block, node, pr);
    } else {
        Error *e = new Error(UnableToParseForm, node);
        ctx->er->addError(e);
        return false;
    }
}