Logo Search packages:      
Sourcecode: inkscape version File versions

enum CRStatus cr_parser_parse_expr ( CRParser a_this,
CRTerm **  a_expr 
)

Parses an expression as defined by the css2 spec in appendix D.1: expr: term [ operator term ]*

Definition at line 2942 of file cr-parser.c.

References CHECK_PARSING_STATUS, cr_parser_clear_errors(), cr_parser_parse_term(), cr_parser_try_to_skip_spaces_and_comments(), cr_term_append_term(), cr_term_destroy(), cr_tknzr_peek_byte(), READ_NEXT_BYTE, and RECORD_INITIAL_POS.

Referenced by cr_parser_parse_declaration(), cr_parser_parse_function(), and cr_term_parse_expression_from_buf().

{
        enum CRStatus status = CR_ERROR;
        CRInputPos init_pos;
        CRTerm *expr = NULL,
                *expr2 = NULL;
        guchar next_byte = 0;
        gulong nb_terms = 0;

        g_return_val_if_fail (a_this && PRIVATE (a_this)
                              && a_expr, CR_BAD_PARAM_ERROR);

        RECORD_INITIAL_POS (a_this, &init_pos);

        status = cr_parser_parse_term (a_this, &expr);

        CHECK_PARSING_STATUS (status, FALSE);

        for (;;) {
                guchar operatr = 0;

                status = cr_tknzr_peek_byte (PRIVATE (a_this)->tknzr,
                                             1, &next_byte);
                if (status != CR_OK) {
                        if (status == CR_END_OF_INPUT_ERROR) {
                                /*
                                   if (!nb_terms)
                                   {
                                   goto error ;
                                   }
                                 */
                                status = CR_OK;
                                break;
                        } else {
                                goto error;
                        }
                }

                if (next_byte == '/' || next_byte == ',') {
                        READ_NEXT_BYTE (a_this, &operatr);
                }

                cr_parser_try_to_skip_spaces_and_comments (a_this);

                status = cr_parser_parse_term (a_this, &expr2);

                if (status != CR_OK || expr2 == NULL) {
                        status = CR_OK;
                        break;
                }

                switch (operatr) {
                case '/':
                        expr2->the_operator = DIVIDE;
                        break;
                case ',':
                        expr2->the_operator = COMMA;

                default:
                        break;
                }

                expr = cr_term_append_term (expr, expr2);
                expr2 = NULL;
                operatr = 0;
                nb_terms++;
        }

        if (status == CR_OK) {
                *a_expr = cr_term_append_term (*a_expr, expr);
                expr = NULL;

                cr_parser_clear_errors (a_this);
                return CR_OK;
        }

      error:

        if (expr) {
                cr_term_destroy (expr);
                expr = NULL;
        }

        if (expr2) {
                cr_term_destroy (expr2);
                expr2 = NULL;
        }

        cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos);

        return status;
}


Generated by  Doxygen 1.6.0   Back to index