Exemple #1
0
bool lex_stream_t::implementation_t::is_compound(char c, stream_lex_token_t& result)
{
    char next_char (compound_match_g[(unsigned char)c]);
    
    if (next_char == '0') return false;
    
    int actual_char (_super::peek_char());
    
    if (actual_char == EOF || actual_char != next_char) return false;
    
    _super::ignore_char();
    
    /*
    There is only a single 3 character compound. It is special cased here rather than adding an
    additional table. The token is '<=='.
    */
    
    if (c == '<' && _super::peek_char() == '=')
    {
        _super::ignore_char();
        result = stream_lex_token_t(is_k, any_regular_t());
        return true;
    }

    result = stream_lex_token_t(name_table_g[compound_index_g[(unsigned char)c]], any_regular_t());
    return true;
}
image_t::image_t(const view_model_type& image) :
    image_m(image),
    enabled_m(false),
    handler_m(*this)
{
    metadata_m.insert(dictionary_t::value_type("delta_x"_name, any_regular_t(0)));
    metadata_m.insert(dictionary_t::value_type("delta_y"_name, any_regular_t(0)));
    metadata_m.insert(dictionary_t::value_type("dragging"_name, any_regular_t(false)));
    metadata_m.insert(dictionary_t::value_type("x"_name, any_regular_t(0)));
    metadata_m.insert(dictionary_t::value_type("y"_name, any_regular_t(0)));
}
bool expression_parser::is_boolean(any_regular_t& result) {
    if (is_keyword(true_k)) {
        result = any_regular_t(true);
        return true;
    } else if (is_keyword(false_k)) {
        result = any_regular_t(false);
        return true;
    }

    return false;
}
Exemple #4
0
bool lex_stream_t::implementation_t::is_comment(char c, stream_lex_token_t& result)
{
    if (c != '/') return false;
    
    std::istream::int_type peek_c (_super::peek_char());
    
    if (peek_c == EOF || (peek_c != '/' && peek_c != '*')) return false;

    (void)_super::get_char(c);

    identifier_buffer_m.clear();

    if (c == '/')
    {
        while (_super::get_char(c) && !is_line_end(c))
        {
            identifier_buffer_m.push_back(c);
        }

        identifier_buffer_m.push_back(0);
    
        result = stream_lex_token_t(trail_comment_k, any_regular_t(std::string(&identifier_buffer_m[0])));
    }
    else // if (c == '*')
    {
        while (true)
        {
            if (!_super::get_char(c))
                throw_parser_exception("Unexpected EOF in comment.");

            if (c == '*')
            {
                peek_c = _super::peek_char();

                if (peek_c != EOF && peek_c == '/')
                    { _super::ignore_char(); break; }
            }
            else if (is_line_end(c))
                { c = '\n'; }
                
            identifier_buffer_m.push_back(c);
        }
            
        identifier_buffer_m.push_back(0);
    
        result = stream_lex_token_t(lead_comment_k, any_regular_t(std::string(&identifier_buffer_m[0])));
    }
    
    return true;
    
}
any_regular_t vm_array_image_proc(const array_t& argument_set)
{
    if (argument_set.empty())
        return any_regular_t(empty_t());

    std::string               filename;
    boost::gil::rgba8_image_t the_image;

    argument_set[0].cast(filename);

    if (!filename.empty())
        image_slurp(boost::filesystem::path(filename), the_image);

    return any_regular_t(the_image);
}
any_regular_t number_formatter_platform_data_t::parse(const std::string& str, any_regular_t the_type)
{
    assert(formatter_m);

    if (the_type.type_info() == typeid(double)) {
        return any_regular_t(number_parse<double>(formatter_m.get(), str));
    }
    
#if 0
    // REVISIT (sparent) : Pulled 64 bit support for formatting - do we need this?
    //else if (the_type.type() == typeid(boost::intmax_t))  return any_regular_t(number_parse<boost::intmax_t>(formatter_m.get(), str));
    //else if (the_type.type() == typeid(boost::uintmax_t))  return any_regular_t(number_parse<boost::uintmax_t>(formatter_m.get(), str));
#endif
    else return any_regular_t(std::string("formatter_format_number error"));
}
//  equality_expression = relational_expression { ("==" | "!=") relational_expression }.
bool expression_parser::is_equality_expression(array_t& expression_stack) {
    if (!is_relational_expression(expression_stack))
        return false;

    bool is_equal = false;

    while ((is_equal = is_token(equal_k)) || is_token(not_equal_k)) {
        if (!is_relational_expression(expression_stack))
            throw_exception("Primary required.");

        expression_stack.push_back(is_equal ? any_regular_t(equal_k) : any_regular_t(not_equal_k));
    }

    return true;
}
Exemple #8
0
bool lex_stream_t::implementation_t::is_dec_number(char c, stream_lex_token_t& result)
{
    if (!std::isdigit(c)) return false;
    
    _super::putback_char(c);

    std::stringstream temp;
    temp.imbue(std::locale::classic());

    while (true)
    {
        if (!_super::get_char(c)) break;

        if (!std::isdigit(c) && c != '.')
        {
            _super::putback_char(c);

            break;
        }

        temp << c;
    }

    double re(0);
    temp >> re;

    result = stream_lex_token_t(number_k, any_regular_t(re));
    return true;
}
Exemple #9
0
bool lex_stream_t::implementation_t::is_string(char c, stream_lex_token_t& result)
{
    if (c != '\'' && c != '\"') return false;
    
    identifier_buffer_m.clear();
    
    while (true)
    {
        char end_char (c);
        
        while (_super::get_char(c) && c != end_char)
        {
            // REVISIT (sparent) : Handle quoted characters here.
            // Also handle invalid characters such as line endings.
            identifier_buffer_m.push_back(c);
        }

        if (c != end_char) throw_parser_exception("Unexpected EOF in string.");
        
        if (!skip_space(c)) break;
        
        if (c != '\'' && c != '\"') 
        {
            _super::putback_char(c);
            break;
        }
    }
    
    identifier_buffer_m.push_back(0);
    result = stream_lex_token_t(string_k, any_regular_t(std::string(&identifier_buffer_m[0])));
    
    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;
}
any_regular_t vm_dictionary_image_proc(const dictionary_t& named_argument_set)
{
    if (named_argument_set.empty())
        return any_regular_t(empty_t());

    std::string               filename;
    boost::gil::rgba8_image_t the_image;

    get_value(named_argument_set, key_name, filename);

    if (!filename.empty()) {
        auto path = boost::filesystem::path(filename);
        image_slurp(path, the_image);
    }

    return any_regular_t(the_image);
}
inline dictionary_t extra_widget_context(const edit_text_t& w)
{
    static_name_t    is_scrollable(w.scrollable_m ? "true"_name : "false"_name);
    dictionary_t     result;

    result.insert(std::make_pair("scroll"_name, any_regular_t(is_scrollable)));

    return result;
}
void image_t::place(const place_data_t& place_data)
{
    implementation::set_bounds(*this, place_data);

    if (callback_m)
    {
        dictionary_t old_metadata(metadata_m);

        double width(callback_m ? std::min<long>(fixed_width, image_m.width()) : image_m.width());
        double height(callback_m ? std::min<long>(fixed_height, image_m.height()) : image_m.height());
    
        metadata_m.insert(dictionary_t::value_type("width"_name, any_regular_t(width)));
        metadata_m.insert(dictionary_t::value_type("height"_name, any_regular_t(height)));

        if (old_metadata != metadata_m)
            callback_m(metadata_m);
    }
}
Exemple #14
0
bool lex_stream_t::implementation_t::is_simple(char c, stream_lex_token_t& result)
{
    int index (simple_index_g[(unsigned char)c]);
    
    if (index == 0) return false;
    
    result = stream_lex_token_t(name_table_g[index], any_regular_t());
    return true;
}
//  named_argument_list = named_argument { "," named_argument }.
bool expression_parser::is_named_argument_list(array_t& expression_stack) {
    if (!is_named_argument(expression_stack))
        return false;

    std::size_t count = 1;

    while (is_token(comma_k)) {
        if (!is_named_argument(expression_stack))
            throw_exception("Named argument required.");

        ++count;
    }

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

    return true;
}
    any_regular_t convert(const any_regular_t& new_value) const
    {
        typedef typename DragAndDropConverterConcept<T>::source_type  const_source_type;
        typedef typename boost::remove_const<const_source_type>::type source_type;
        typedef typename DragAndDropConverterConcept<T>::dest_type    const_dest_type;
        typedef typename boost::remove_const<const_dest_type>::type   dest_type;

        return any_regular_t(DragAndDropConverterConcept<T>::convert(this->get(),
                                                                     new_value.cast<source_type>()));
    }
//  variable_or_function = identifier ["(" [argument_expression_list] ")"].
bool expression_parser::is_variable_or_function(array_t& expression_stack) {
    any_regular_t result;

    if (!is_token(identifier_k, result))
        return false;

    if (is_token(open_parenthesis_k)) {
        // If there are no parameters then set the parameters to an empty array.
        if (!is_argument_expression_list(expression_stack))
            expression_stack.push_back(any_regular_t(adobe::array_t()));

        require_token(close_parenthesis_k);
        expression_stack.push_back(result);
        expression_stack.push_back(any_regular_t(function_k));
    } else {
        expression_stack.push_back(result);
        expression_stack.push_back(any_regular_t(variable_k));
    }

    return true;
}
any_regular_t vm_dictionary_image_proc(const dictionary_t& named_argument_set)
{
    if (named_argument_set.empty())
        return any_regular_t(empty_t());

    std::string                    filename;
    boost::shared_ptr<GG::Texture> the_image;

    get_value(named_argument_set, key_name, filename);

    if (!filename.empty()) {
        try {
            the_image = GG::GUI::GetGUI()->GetTexture(filename);
            the_image->SetFilters(GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST);
        } catch (...) {
            return any_regular_t(empty_t());
        }
    }

    return any_regular_t(the_image);
}
any_regular_t vm_array_image_proc(const array_t& argument_set)
{
    if (argument_set.empty())
        return any_regular_t(empty_t());

    std::string                    filename;
    boost::shared_ptr<GG::Texture> the_image;

    argument_set[0].cast(filename);

    if (!filename.empty()) {
        try {
            the_image = GG::GUI::GetGUI()->GetTexture(filename);
            the_image->SetFilters(GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST);
        } catch (...) {
            return any_regular_t(empty_t());
        }
    }

    return any_regular_t(the_image);
}
void adam_test_parser::populate_dict(dictionary_t& dict, const queryable_sheet_t::index_t& index,
                                     const queryable_sheet_t& qs, bool want_contributors,
                                     bool want_active) const {
    for (queryable_sheet_t::index_t::iterator iter = index.begin(), e = index.end(); iter != e;
         ++iter) {
        std::size_t i(iter->second);

        if (want_contributors) {
            dictionary_t cell_dict;
            cell_dict[name_t("contributors")] = any_regular_t(qs.cell_contributors()[i]);
            if (want_active) {
                cell_dict[name_t("active")] = any_regular_t(qs.cell_active()[i]);
                cell_dict[name_t("priority_accessed")] =
                    any_regular_t(qs.cell_priority_accessed()[i]);
            }
            cell_dict[name_t("_value")] = qs.cell_value()[i];
            dict[qs.cell_name()[i]] = any_regular_t(cell_dict);

        } else
            dict[qs.cell_name()[i]] = qs.cell_value()[i];
    }
}
any_regular_t asl_standard_array_function_lookup(name_t         function_name,
                                                 const array_t& argument_set)
{
    if (function_name == static_name_t("image"))
    {
        return implementation::vm_array_image_proc(argument_set);
    }
    else
    {
        throw_function_not_defined(function_name);
    }

    return any_regular_t(empty_t());
}
Exemple #22
0
bool lex_stream_t::implementation_t::is_identifier_or_keyword(char c, stream_lex_token_t& result)
{
    if (!std::isalpha(c) && c != '_') return false;

    identifier_buffer_m.clear();

    do
    {
        if (std::isalnum(c) || c == '_')
        {
            identifier_buffer_m.push_back(c);
        }
        else
        {
            _super::putback_char(c);
            break;
        }
    }
    while (_super::get_char(c));
    
    identifier_buffer_m.push_back(0);
    
    name_t                          ident(&identifier_buffer_m.front());
    keyword_table_t::const_iterator iter(lower_bound(*keywords_g, ident));

    if ((iter != keywords_g->end() && *iter == ident) ||
        (!keyword_proc_m.empty() && keyword_proc_m(ident)))
    {
        result = stream_lex_token_t(keyword_k, any_regular_t(ident));
    }
    else
    {
        result = stream_lex_token_t(identifier_k, any_regular_t(ident));
    }

    return true;
}
//  multiplicative_expression = unary_expression { ("*" | "/" | "%") unary_expression }.
bool expression_parser::is_multiplicative_expression(array_t& expression_stack) {
    if (!is_unary_expression(expression_stack))
        return false;

    name_t operator_l;

    while (is_multiplicative_operator(operator_l)) {
        if (!is_unary_expression(expression_stack))
            throw_exception("Primary required.");

        expression_stack.push_back(any_regular_t(operator_l));
    }

    return true;
}
//  bitwise_and_expression = equality_expression { "&" equality_expression }.
bool expression_parser::is_bitwise_and_expression(array_t& expression_stack) {
    if (!is_equality_expression(expression_stack))
        return false;

    while (is_token(bitwise_and_k)) {
        array_t operand2;

        if (!is_equality_expression(operand2))
            throw_exception("equality_expression required");

        push_back(expression_stack, operand2);
        expression_stack.push_back(any_regular_t(bitwise_and_k));
    }

    return true;
}
bool asl_standard_array_function_lookup(name_t         function_name,
                                        const array_t& argument_set,
                                        any_regular_t& result)
{
    if (function_name == static_name_t("image"))
    {
        result = implementation::vm_array_image_proc(argument_set);
        return true;
    }
    else
    {
        return false;
    }

    result = any_regular_t(empty_t());
    return false;
}
bool expression_parser::is_unary_expression(array_t& expression_stack) {
    if (is_postfix_expression(expression_stack))
        return true;

    name_t operator_l;

    if (is_unary_operator(operator_l)) {
        if (!is_unary_expression(expression_stack))
            throw_exception("Unary expression required.");

        if (operator_l != add_k)
            expression_stack.push_back(any_regular_t(operator_l));

        return true;
    }

    return false;
}
//  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;
}
//  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;
}
Exemple #30
0
GG::ListBox::Row* item_to_row(const dictionary_t& item,
                              const row_factory_t* row_factory,
                              const GG::Clr& default_item_color)
{
    const bool contains_color = item.count(static_name_t("color"));
    dictionary_t colorful_dictionary;
    if (!contains_color) {
        colorful_dictionary = item;
        colorful_dictionary[static_name_t("color")] = any_regular_t(default_item_color);
    }
    const dictionary_t& dictionary = contains_color ? item : colorful_dictionary;
    name_t type;
    get_value(dictionary, static_name_t("type"), type);
    row_factory_t::const_iterator it;
    GG::ListBox::Row* retval = 0;
    if (row_factory && (it = row_factory->find(type)) != row_factory->end())
        retval = it->second(dictionary);
    else
        retval = GG::DefaultRowFactoryFunction(dictionary);
    retval->SetItem(item);
    return retval;
}