Пример #1
0
bool binspector_parser_t::is_atom_field(atom_base_type_t& atom_base_type,
                                        adobe::array_t&   bit_count_expression,
                                        adobe::array_t&   is_big_endian_expression)
{
    static const adobe::array_t is_little_endian_expression_k(1, adobe::any_regular_t(false));
    static const adobe::array_t is_big_endian_expression_k(1, adobe::any_regular_t(true));

    if (is_keyword(key_signed))
        atom_base_type = atom_signed_k;
    else if (is_keyword(key_unsigned))
        atom_base_type = atom_unsigned_k;
    else if (is_keyword(key_float))
        atom_base_type = atom_float_k;
    else
        return false;

    require_expression(bit_count_expression);

    if (is_keyword(key_little))
        is_big_endian_expression = is_little_endian_expression_k;
    else if (is_keyword(key_big))
        is_big_endian_expression = is_big_endian_expression_k;
    else
        require_expression(is_big_endian_expression);

    return true;
}
Пример #2
0
bool binspector_parser_t::is_skip()
{
    if (!is_keyword(key_skip))
        return false;

    adobe::name_t name;

    require_identifier(name);

    require_token(adobe::open_bracket_k);

    adobe::array_t expression;

    require_expression(expression);

    require_token(adobe::close_bracket_k);

    adobe::dictionary_t parameters;

    parameters[key_field_type].assign(value_field_type_skip);
    parameters[key_field_name].assign(name);
    parameters[key_skip_expression].assign(expression);

    insert_parser_metadata(parameters);
    add_field_proc_m(name, parameters);

    return true;
}
Пример #3
0
bool binspector_parser_t::is_simple_assign_field(adobe::name_t keyword, adobe::name_t field_type)
{
    if (!is_keyword(keyword))
        return false;

    adobe::name_t name;

    require_identifier(name);

    require_token(adobe::assign_k);

    adobe::array_t expression;

    require_expression(expression);

    adobe::dictionary_t parameters;

    parameters[key_field_type].assign(field_type);
    parameters[key_field_name].assign(name);
    parameters[key_field_assign_expression].assign(expression);

    parameters[key_field_size_type].assign(field_size_none_k); // intentionally fixed
    parameters[key_field_size_expression].assign(adobe::array_t()); // intentionally fixed
    parameters[key_field_offset_expression].assign(adobe::array_t()); // intentionally fixed

    insert_parser_metadata(parameters);
    add_field_proc_m(name, parameters);

    return true;
}
Пример #4
0
//  define_expression       = "<==" expression.
bool adam_parser::is_define_expression(line_position_t& position, array_t& expression)
{
    if (!is_token(is_k)) return false;
    
    position = next_position();
    require_expression(expression);
    return true;
}
Пример #5
0
bool binspector_parser_t::is_offset(adobe::array_t& offset_expression)
{
    if (!is_token(adobe::at_k))
        return false;

    require_expression(offset_expression);

    return true;
}
//  expression = or_expression ["?" expression ":" expression].
bool expression_parser::is_expression(array_t& expression_stack) {
    if (!is_or_expression(expression_stack))
        return false;

    if (!is_token(question_k))
        return true;

    array_t operand2;
    array_t operand3;

    require_expression(operand2);
    require_token(colon_k);
    require_expression(operand3);

    push_back(expression_stack, operand2);
    push_back(expression_stack, operand3);
    expression_stack.push_back(any_regular_t(ifelse_k));

    return true;
}
Пример #7
0
bool adam_parser::is_conditional(line_position_t& position, array_t& expression)
{
    if (!is_keyword(when_k)) return false;

    require_token(open_parenthesis_k);
    
    position = next_position();
    
    require_expression(expression);
    require_token(close_parenthesis_k);

    return true;
}
//  argument_list = expression { "," expression }.
bool expression_parser::is_argument_list(array_t& expression_stack) {
    if (!is_expression(expression_stack))
        return false;

    std::size_t count = 1;

    while (is_token(comma_k)) {
        require_expression(expression_stack);
        ++count;
    }

    expression_stack.push_back(any_regular_t(double(count)));
    expression_stack.push_back(any_regular_t(array_k));

    return true;
}
Пример #9
0
bool binspector_parser_t::is_if_scope()
{
    if (!is_keyword(key_if))
        return false;

    adobe::array_t expression;

    require_token(adobe::open_parenthesis_k);

    require_expression(expression);

    require_token(adobe::close_parenthesis_k);

    static std::size_t          uid_s(0);
    static const adobe::array_t empty_array_k;

    std::string lambda_identifier;

    // REVISIT (fbrereto) : String concatenation here.
    lambda_identifier += std::string("<")
                      + current_struct_m.c_str()
                      + ":if_"
                      + boost::lexical_cast<std::string>(++uid_s)
                      + ">";

    adobe::name_t       identifier(lambda_identifier.c_str());
    adobe::dictionary_t parameters;

    parameters[key_field_if_expression].assign(expression);
    parameters[key_field_conditional_type].assign(conditional_expression_t(if_k));
    parameters[key_field_name].assign(identifier);
    parameters[key_field_size_expression].assign(empty_array_k);
    parameters[key_field_offset_expression].assign(empty_array_k);
    parameters[key_field_type].assign(value_field_type_struct);
    parameters[key_named_type_name].assign(identifier);

    insert_parser_metadata(parameters);
    add_field_proc_m(identifier, parameters);

    require_scope_content(identifier);

    return true;
}
//  named_argument = identifier ":" expression.
bool expression_parser::is_named_argument(array_t& expression_stack) {
    /* NOTE (sparent) : This is the one point in the grammar where we need the LL(2) parser. */

    name_t ident;

    if (!is_identifier(ident))
        return false;

    if (!is_token(colon_k)) {
        putback(); // the identifier

        return false;
    }

    expression_stack.push_back(any_regular_t(ident));
    require_expression(expression_stack);

    return true;
}
bool expression_parser::is_postfix_expression(array_t& expression_stack) {
    if (!is_primary_expression(expression_stack))
        return false;

    while (true) {
        if (is_token(open_bracket_k)) {
            require_expression(expression_stack);
            require_token(close_bracket_k);
        } else if (is_token(dot_k)) {
            any_regular_t result;
            require_token(identifier_k, result);
            expression_stack.push_back(result);
        } else
            break;

        expression_stack.push_back(any_regular_t(index_k));
    }

    return true;
}
bool expression_parser::is_primary_expression(array_t& expression_stack) {
    any_regular_t result; // empty result used if is_keyword(empty_k)

    if (is_name(result) || is_token(number_k, result) || is_boolean(result) ||
        is_token(string_k, result) || is_keyword(empty_k)) {
        expression_stack.push_back(std::move(result));
        return true;
    } else if (is_array(expression_stack))
        return true;
    else if (is_dictionary(expression_stack))
        return true;
    else if (is_variable_or_function(expression_stack))
        return true;
    else if (is_token(open_parenthesis_k)) {
        require_expression(expression_stack);
        require_token(close_parenthesis_k);
        return true;
    }

    return false;
}
Пример #13
0
bool binspector_parser_t::is_field_size(field_size_t&   field_size_type,
                                        adobe::array_t& field_size_expression,
                                        bool&           shuffleable)
{
    if (!is_token(adobe::open_bracket_k))
        return false;

    if (is_keyword(key_while))
    {
        field_size_type = field_size_while_k;

        require_token(adobe::colon_k);
    }
    else if (is_keyword(key_terminator))
    {
        field_size_type = field_size_terminator_k;

        require_token(adobe::colon_k);
    }
    else if (is_keyword(key_delimiter))
    {
        field_size_type = field_size_delimiter_k;

        require_token(adobe::colon_k);
    }
    else
    {
        field_size_type = field_size_integer_k;
    }

    require_expression(field_size_expression);

    require_token(adobe::close_bracket_k);

    shuffleable = is_keyword(key_shuffle);

    return true;
}
Пример #14
0
bool binspector_parser_t::is_constant()
{
    bool is_const(is_keyword(key_const));
    bool is_invis(!is_const && is_keyword(key_invis));

    if (!is_const && !is_invis)
        return false;

    adobe::name_t name;

    require_identifier(name);

    require_token(adobe::assign_k);

    adobe::array_t expression;

    require_expression(expression);

    // REVISIT (fbrereto) :
    // I should generalize these into "decorators", add them to the grammar and
    // reduce is_constant into a forwarding of is_simple_assign_field
    bool noprint(false);

    if (is_keyword(key_noprint) || is_invis)
        noprint = true;

    adobe::dictionary_t parameters;

    parameters[key_field_type].assign(value_field_type_const);
    parameters[key_field_name].assign(name);
    parameters[key_const_expression].assign(expression);
    parameters[key_const_no_print].assign(noprint);

    insert_parser_metadata(parameters);
    add_field_proc_m(name, parameters);

    return true;
}