Gitweb links:

...log 
http://git.netsurf-browser.org/libcss.git/shortlog/54b14acee8d6c45c747c486c2d531fea2b30502e
...commit 
http://git.netsurf-browser.org/libcss.git/commit/54b14acee8d6c45c747c486c2d531fea2b30502e
...tree 
http://git.netsurf-browser.org/libcss.git/tree/54b14acee8d6c45c747c486c2d531fea2b30502e

The branch, lcneves/flexbox has been updated
       via  54b14acee8d6c45c747c486c2d531fea2b30502e (commit)
       via  59a6f810bf6f5c817f33650a3c22871610edb4cc (commit)
      from  4a8f14d9e6a1a3a33c0075f803c6826802383630 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/libcss.git/commit/?id=54b14acee8d6c45c747c486c2d531fea2b30502e
commit 54b14acee8d6c45c747c486c2d531fea2b30502e
Author: Lucas Neves <[email protected]>
Commit: Lucas Neves <[email protected]>

    Cleanup

diff --git a/src/parse/properties/flex_old.c b/src/parse/properties/flex_old.c
deleted file mode 100644
index f189b3b..0000000
--- a/src/parse/properties/flex_old.c
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * This file is part of LibCSS.
- * Licensed under the MIT License,
- *               http://www.opensource.org/licenses/mit-license.php
- * Copyright 2017 Lucas Neves <[email protected]>
- */
-
-#include <assert.h>
-#include <string.h>
-
-#include "bytecode/bytecode.h"
-#include "bytecode/opcodes.h"
-#include "parse/properties/properties.h"
-#include "parse/properties/utils.h"
-
-/**
- * Parse list-style
- *
- * \param c      Parsing context
- * \param vector  Vector of tokens to process
- * \param ctx    Pointer to vector iteration context
- * \param result  Pointer to location to receive resulting style
- * \return CSS_OK on success,
- *        CSS_NOMEM on memory exhaustion,
- *        CSS_INVALID if the input is not valid
- *
- * Post condition: \a *ctx is updated with the next token to process
- *                If the input is invalid, then \a *ctx remains unchanged.
- */
-
-css_error flex_grow_helper(const css_token *token, css_fixed *number);
-css_error flex_basis_helper(css_language *c,
-               const parserutils_vector *vector, int *ctx,
-               css_fixed *basis_length, uint32_t *basis_unit,
-               opcode_t *basis_op);
-
-
-css_error flex_basis_helper(css_language *c,
-               const parserutils_vector *vector, int *ctx,
-               css_fixed *basis_length, uint32_t *basis_unit,
-               opcode_t *basis_op)
-{
-       css_error error;
-       error = css__parse_unit_specifier(c, vector, ctx,
-                               UNIT_PX, basis_length, basis_unit);
-
-       if (error == CSS_OK) {
-               if (*basis_unit & UNIT_ANGLE ||
-                               *basis_unit & UNIT_TIME ||
-                               *basis_unit & UNIT_FREQ) {
-                       return CSS_INVALID;
-               }
-               *basis_op = FLEX_BASIS_SET;
-       }
-
-       return error;
-}
-
-css_error flex_grow_helper(const css_token *token, css_fixed *number)
-{
-       if (token->type != CSS_TOKEN_NUMBER)
-               return CSS_INVALID;
-
-       size_t consumed = 0;
-       css_fixed num = css__number_from_lwc_string(
-                       token->idata, false, &consumed);
-
-       /* Invalid if there are trailing characters */
-       if (consumed != lwc_string_length(token->idata))
-               return CSS_INVALID;
-
-       /* Invalid if number is negative */
-       if (num < 0)
-               return CSS_INVALID;
-
-       *number = num;
-       return CSS_OK;
-}
-
-css_error css__parse_flex(css_language *c,
-               const parserutils_vector *vector, int *ctx,
-               css_style *result)
-{
-       int orig_ctx = *ctx;
-       const css_token *token;
-       css_error error;
-
-       /* Firstly, handle inherit */
-       token = parserutils_vector_peek(vector, *ctx);
-       if (token == NULL) 
-               return CSS_INVALID;
-               
-       if (is_css_inherit(c, token)) {
-               error = css_stylesheet_style_inherit(result,
-                               CSS_PROP_FLEX_GROW);
-               if (error != CSS_OK) 
-                       return error;
-
-               error = css_stylesheet_style_inherit(result,
-                               CSS_PROP_FLEX_SHRINK);
-               if (error != CSS_OK) 
-                       return error;
-
-
-               error = css_stylesheet_style_inherit(result,
-                               CSS_PROP_FLEX_BASIS);
-
-               if (error == CSS_OK) 
-                       parserutils_vector_iterate(vector, ctx);
-
-               return error;
-       } 
-
-       /* Default values */
-       opcode_t grow_op = FLEX_GROW_SET;
-       css_fixed grow_number = 0;
-       opcode_t shrink_op = FLEX_SHRINK_SET;
-       css_fixed shrink_number = INTTOFIX(1);
-       opcode_t basis_op = FLEX_BASIS_AUTO;
-       css_fixed basis_length = 0;
-       uint32_t basis_unit = UNIT_PX;
-
-       /* Attempt to parse the various longhand properties */
-       *ctx = orig_ctx;
-       size_t length = -1;
-
-       do {
-               ++length;
-               token = parserutils_vector_iterate(vector, ctx);
-       } while (token != NULL);
-
-       *ctx = orig_ctx;
-
-       switch (length) {
-       case 1:
-               token = parserutils_vector_iterate(vector, ctx);
-               if (token == NULL || token->type != CSS_TOKEN_IDENT) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /*
-                * Handle auto and none
-                * auto = flex: 1 1 auto;
-                * none = flex: 0 0 auto;
-                */
-               bool match;
-               if ((lwc_string_caseless_isequal(
-                               token->idata, c->strings[AUTO],
-                               &match) == lwc_error_ok && match) ||
-                               (lwc_string_caseless_isequal(
-                               token->idata, c->strings[NONE],
-                               &match) == lwc_error_ok && match)) {
-                       if ((lwc_string_caseless_isequal(
-                                       token->idata, c->strings[AUTO],
-                                       &match) == lwc_error_ok && match)) {
-                               grow_number = INTTOFIX(1);
-                       }
-                       else {
-                               shrink_number = 0;
-                       }
-
-               }
-
-               /* Token must be either flex-basis or flex-grow */
-               else {
-                       *ctx = orig_ctx;
-                       error = flex_basis_helper(c, vector, ctx,
-                                       &basis_length, &basis_unit,
-                                       &basis_op);
-
-                       if (error != CSS_OK) {
-                               /* Positive number: equivalent of
-                                * flex: <positive number> 1 0; */
-                               *ctx = orig_ctx;
-                               token = parserutils_vector_iterate(vector, ctx);
-                               error = flex_grow_helper(
-                                               token, &grow_number);
-                               if (error != CSS_OK) {
-                                       *ctx = orig_ctx;
-                                       return CSS_INVALID;
-                               }
-                               basis_op = FLEX_BASIS_SET;
-                       }
-               }
-               break;
-
-       case 2:
-               /* First value must be flex-grow */
-               token = parserutils_vector_iterate(vector, ctx);
-               error = flex_grow_helper(
-                               token, &grow_number);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /* Second value must be either flex-basis or flex-shrink */
-               int prev_ctx = *ctx;
-               error = flex_basis_helper(c, vector, ctx,
-                               &basis_length, &basis_unit, &basis_op);
-
-               if (error != CSS_OK) {
-                       /* Two positive numbers: equivalent of
-                        * flex: <number_1> <number_2> 0; */
-                       *ctx = prev_ctx;
-                       token = parserutils_vector_iterate(vector, ctx);
-                       error = flex_grow_helper(
-                                       token, &shrink_number);
-                       if (error != CSS_OK) {
-                               *ctx = orig_ctx;
-                               return CSS_INVALID;
-                       }
-                       basis_op = FLEX_BASIS_SET;
-               }
-               break;
-
-       case 3:
-               /* First value must be flex-grow */
-               token = parserutils_vector_iterate(vector, ctx);
-               error = flex_grow_helper(
-                               token, &grow_number);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /* Second value must be flex-shrink */
-               token = parserutils_vector_iterate(vector, ctx);
-               error = flex_grow_helper(
-                               token, &shrink_number);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /* Third value must be flex-basis */
-               error = flex_basis_helper(c, vector, ctx,
-                               &basis_length, &basis_unit, &basis_op);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-               break;
-
-       default:
-               return CSS_INVALID;
-       }
-
-       /* allocate styles */
-       css_style *grow_style;
-       css_style *shrink_style;
-       css_style *basis_style;
-
-       error = css__stylesheet_style_create(c->sheet, &grow_style);
-       if (error != CSS_OK) 
-               return error;
-
-       error = css__stylesheet_style_create(c->sheet, &shrink_style);
-       if (error != CSS_OK) {
-               css__stylesheet_style_destroy(grow_style);
-               return error;
-        }
-
-       error = css__stylesheet_style_create(c->sheet, &basis_style);
-       if (error != CSS_OK) {
-               css__stylesheet_style_destroy(shrink_style);
-               css__stylesheet_style_destroy(grow_style);
-               return error;
-       }
-
-       error = css__stylesheet_style_appendOPV(grow_style, 
-                       CSS_PROP_FLEX_GROW, 0, grow_op);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
-
-       error = css__stylesheet_style_append(grow_style, grow_number);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
-
-       error = css__stylesheet_style_appendOPV(shrink_style, 
-                       CSS_PROP_FLEX_SHRINK, 0, shrink_op);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
-
-       error = css__stylesheet_style_append(shrink_style, shrink_number);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
-
-       error = css__stylesheet_style_appendOPV(basis_style, 
-                       CSS_PROP_FLEX_BASIS, 0, basis_op);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
-
-       if (basis_op == (opcode_t) FLEX_BASIS_SET) {
-               error = css__stylesheet_style_append(basis_style, basis_length);
-               if (error != CSS_OK)
-                       goto css__parse_flex_flow_cleanup;
-
-               error = css__stylesheet_style_append(basis_style, basis_unit);
-               if (error != CSS_OK)
-                       goto css__parse_flex_flow_cleanup;
-       }
-
-       error = css__stylesheet_merge_style(result, grow_style);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
-
-       error = css__stylesheet_merge_style(result, shrink_style);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
-
-       error = css__stylesheet_merge_style(result, basis_style);
-
-css__parse_flex_flow_cleanup:
-
-       css__stylesheet_style_destroy(basis_style);
-       css__stylesheet_style_destroy(shrink_style);
-       css__stylesheet_style_destroy(grow_style);
-
-       if (error != CSS_OK)
-               *ctx = orig_ctx;
-
-       return error;
-}
-


commitdiff 
http://git.netsurf-browser.org/libcss.git/commit/?id=59a6f810bf6f5c817f33650a3c22871610edb4cc
commit 59a6f810bf6f5c817f33650a3c22871610edb4cc
Author: Lucas Neves <[email protected]>
Commit: Lucas Neves <[email protected]>

    WIP: Parse: rewrite flex shorthand parser to comply with standards

diff --git a/src/parse/properties/flex.c b/src/parse/properties/flex.c
index f189b3b..b2fd67e 100644
--- a/src/parse/properties/flex.c
+++ b/src/parse/properties/flex.c
@@ -28,62 +28,21 @@
  *                If the input is invalid, then \a *ctx remains unchanged.
  */
 
-css_error flex_grow_helper(const css_token *token, css_fixed *number);
-css_error flex_basis_helper(css_language *c,
-               const parserutils_vector *vector, int *ctx,
-               css_fixed *basis_length, uint32_t *basis_unit,
-               opcode_t *basis_op);
-
-
-css_error flex_basis_helper(css_language *c,
-               const parserutils_vector *vector, int *ctx,
-               css_fixed *basis_length, uint32_t *basis_unit,
-               opcode_t *basis_op)
-{
-       css_error error;
-       error = css__parse_unit_specifier(c, vector, ctx,
-                               UNIT_PX, basis_length, basis_unit);
-
-       if (error == CSS_OK) {
-               if (*basis_unit & UNIT_ANGLE ||
-                               *basis_unit & UNIT_TIME ||
-                               *basis_unit & UNIT_FREQ) {
-                       return CSS_INVALID;
-               }
-               *basis_op = FLEX_BASIS_SET;
-       }
-
-       return error;
-}
-
-css_error flex_grow_helper(const css_token *token, css_fixed *number)
-{
-       if (token->type != CSS_TOKEN_NUMBER)
-               return CSS_INVALID;
-
-       size_t consumed = 0;
-       css_fixed num = css__number_from_lwc_string(
-                       token->idata, false, &consumed);
-
-       /* Invalid if there are trailing characters */
-       if (consumed != lwc_string_length(token->idata))
-               return CSS_INVALID;
-
-       /* Invalid if number is negative */
-       if (num < 0)
-               return CSS_INVALID;
-
-       *number = num;
-       return CSS_OK;
-}
-
 css_error css__parse_flex(css_language *c,
                const parserutils_vector *vector, int *ctx,
                css_style *result)
 {
        int orig_ctx = *ctx;
+       int prev_ctx;
        const css_token *token;
        css_error error;
+       bool grow = true;
+       bool shrink = true;
+       bool basis = true;
+       css_style *grow_style;
+       css_style *shrink_style;
+       css_style *basis_style;
+       bool match;
 
        /* Firstly, handle inherit */
        token = parserutils_vector_peek(vector, *ctx);
@@ -92,16 +51,16 @@ css_error css__parse_flex(css_language *c,
                
        if (is_css_inherit(c, token)) {
                error = css_stylesheet_style_inherit(result,
-                               CSS_PROP_FLEX_GROW);
+                               CSS_PROP_FLEX_SHRINK);
                if (error != CSS_OK) 
                        return error;
 
                error = css_stylesheet_style_inherit(result,
-                               CSS_PROP_FLEX_SHRINK);
+                               CSS_PROP_FLEX_GROW);
+
                if (error != CSS_OK) 
                        return error;
 
-
                error = css_stylesheet_style_inherit(result,
                                CSS_PROP_FLEX_BASIS);
 
@@ -109,149 +68,9 @@ css_error css__parse_flex(css_language *c,
                        parserutils_vector_iterate(vector, ctx);
 
                return error;
-       } 
-
-       /* Default values */
-       opcode_t grow_op = FLEX_GROW_SET;
-       css_fixed grow_number = 0;
-       opcode_t shrink_op = FLEX_SHRINK_SET;
-       css_fixed shrink_number = INTTOFIX(1);
-       opcode_t basis_op = FLEX_BASIS_AUTO;
-       css_fixed basis_length = 0;
-       uint32_t basis_unit = UNIT_PX;
-
-       /* Attempt to parse the various longhand properties */
-       *ctx = orig_ctx;
-       size_t length = -1;
-
-       do {
-               ++length;
-               token = parserutils_vector_iterate(vector, ctx);
-       } while (token != NULL);
-
-       *ctx = orig_ctx;
-
-       switch (length) {
-       case 1:
-               token = parserutils_vector_iterate(vector, ctx);
-               if (token == NULL || token->type != CSS_TOKEN_IDENT) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /*
-                * Handle auto and none
-                * auto = flex: 1 1 auto;
-                * none = flex: 0 0 auto;
-                */
-               bool match;
-               if ((lwc_string_caseless_isequal(
-                               token->idata, c->strings[AUTO],
-                               &match) == lwc_error_ok && match) ||
-                               (lwc_string_caseless_isequal(
-                               token->idata, c->strings[NONE],
-                               &match) == lwc_error_ok && match)) {
-                       if ((lwc_string_caseless_isequal(
-                                       token->idata, c->strings[AUTO],
-                                       &match) == lwc_error_ok && match)) {
-                               grow_number = INTTOFIX(1);
-                       }
-                       else {
-                               shrink_number = 0;
-                       }
-
-               }
-
-               /* Token must be either flex-basis or flex-grow */
-               else {
-                       *ctx = orig_ctx;
-                       error = flex_basis_helper(c, vector, ctx,
-                                       &basis_length, &basis_unit,
-                                       &basis_op);
-
-                       if (error != CSS_OK) {
-                               /* Positive number: equivalent of
-                                * flex: <positive number> 1 0; */
-                               *ctx = orig_ctx;
-                               token = parserutils_vector_iterate(vector, ctx);
-                               error = flex_grow_helper(
-                                               token, &grow_number);
-                               if (error != CSS_OK) {
-                                       *ctx = orig_ctx;
-                                       return CSS_INVALID;
-                               }
-                               basis_op = FLEX_BASIS_SET;
-                       }
-               }
-               break;
-
-       case 2:
-               /* First value must be flex-grow */
-               token = parserutils_vector_iterate(vector, ctx);
-               error = flex_grow_helper(
-                               token, &grow_number);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /* Second value must be either flex-basis or flex-shrink */
-               int prev_ctx = *ctx;
-               error = flex_basis_helper(c, vector, ctx,
-                               &basis_length, &basis_unit, &basis_op);
-
-               if (error != CSS_OK) {
-                       /* Two positive numbers: equivalent of
-                        * flex: <number_1> <number_2> 0; */
-                       *ctx = prev_ctx;
-                       token = parserutils_vector_iterate(vector, ctx);
-                       error = flex_grow_helper(
-                                       token, &shrink_number);
-                       if (error != CSS_OK) {
-                               *ctx = orig_ctx;
-                               return CSS_INVALID;
-                       }
-                       basis_op = FLEX_BASIS_SET;
-               }
-               break;
-
-       case 3:
-               /* First value must be flex-grow */
-               token = parserutils_vector_iterate(vector, ctx);
-               error = flex_grow_helper(
-                               token, &grow_number);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /* Second value must be flex-shrink */
-               token = parserutils_vector_iterate(vector, ctx);
-               error = flex_grow_helper(
-                               token, &shrink_number);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /* Third value must be flex-basis */
-               error = flex_basis_helper(c, vector, ctx,
-                               &basis_length, &basis_unit, &basis_op);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-               break;
-
-       default:
-               return CSS_INVALID;
        }
-
+       
        /* allocate styles */
-       css_style *grow_style;
-       css_style *shrink_style;
-       css_style *basis_style;
-
        error = css__stylesheet_style_create(c->sheet, &grow_style);
        if (error != CSS_OK) 
                return error;
@@ -260,59 +79,153 @@ css_error css__parse_flex(css_language *c,
        if (error != CSS_OK) {
                css__stylesheet_style_destroy(grow_style);
                return error;
-        }
+       }
 
        error = css__stylesheet_style_create(c->sheet, &basis_style);
        if (error != CSS_OK) {
-               css__stylesheet_style_destroy(shrink_style);
                css__stylesheet_style_destroy(grow_style);
+               css__stylesheet_style_destroy(shrink_style);
                return error;
        }
 
-       error = css__stylesheet_style_appendOPV(grow_style, 
-                       CSS_PROP_FLEX_GROW, 0, grow_op);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+       /* Handle none = flex: 0 0 auto; */
+       if ((token->type == CSS_TOKEN_IDENT) &&
+               (lwc_string_caseless_isequal(
+                       token->idata, c->strings[NONE],
+                       &match) == lwc_error_ok && match)) {
+               error = css__stylesheet_style_appendOPV(grow_style, 
+                               CSS_PROP_FLEX_GROW, 0, FLEX_GROW_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
 
-       error = css__stylesheet_style_append(grow_style, grow_number);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               error = css__stylesheet_style_append(grow_style, 0);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
 
-       error = css__stylesheet_style_appendOPV(shrink_style, 
-                       CSS_PROP_FLEX_SHRINK, 0, shrink_op);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               error = css__stylesheet_style_appendOPV(shrink_style, 
+                               CSS_PROP_FLEX_SHRINK, 0, FLEX_SHRINK_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
 
-       error = css__stylesheet_style_append(shrink_style, shrink_number);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               error = css__stylesheet_style_append(shrink_style, 0);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
 
-       error = css__stylesheet_style_appendOPV(basis_style, 
-                       CSS_PROP_FLEX_BASIS, 0, basis_op);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               error = css__stylesheet_style_appendOPV(basis_style, 
+                               CSS_PROP_FLEX_BASIS, 0, FLEX_BASIS_AUTO);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               grow = shrink = basis = false;
+       }
+
+       /* Handle auto = flex: 1 1 auto; */
+       else if ((token->type == CSS_TOKEN_IDENT) &&
+               (lwc_string_caseless_isequal(
+                       token->idata, c->strings[AUTO],
+                       &match) == lwc_error_ok && match)) {
+               error = css__stylesheet_style_appendOPV(grow_style, 
+                               CSS_PROP_FLEX_GROW, 0, FLEX_GROW_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_append(grow_style, INTTOFIX(1));
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_appendOPV(shrink_style, 
+                               CSS_PROP_FLEX_SHRINK, 0, FLEX_SHRINK_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_append(shrink_style, INTTOFIX(1));
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_appendOPV(basis_style, 
+                               CSS_PROP_FLEX_BASIS, 0, FLEX_BASIS_AUTO);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               grow = shrink = basis = false;
+       }
+
+       /* Attempt to parse the various longhand properties */
+       else do {
+               prev_ctx = *ctx;
+               error = CSS_OK;
+
+               /* Ensure that we're not about to parse another inherit */
+               token = parserutils_vector_peek(vector, *ctx);
+               if (token != NULL && is_css_inherit(c, token)) {
+                       error = CSS_INVALID;
+                       goto css__parse_flex_cleanup;
+               }
 
-       if (basis_op == (opcode_t) FLEX_BASIS_SET) {
-               error = css__stylesheet_style_append(basis_style, basis_length);
+               if ((grow) && 
+                          (error = css__parse_flex_grow(c, vector,
+                               ctx, grow_style)) == CSS_OK) {
+                       grow = false;
+               } else if ((basis) && 
+                          (error = css__parse_flex_basis(c, vector, 
+                               ctx, basis_style)) == CSS_OK) {
+                       basis = false;
+               } else if ((shrink) && 
+                          (error = css__parse_flex_shrink(c, vector, 
+                               ctx, shrink_style)) == CSS_OK) {
+                       shrink = false;
+               }
+
+               if (error == CSS_OK) {
+                       consumeWhitespace(vector, ctx);
+                       token = parserutils_vector_peek(vector, *ctx);
+               } else {
+                       /* Forcibly cause loop to exit */
+                       token = NULL;
+               }
+       } while (*ctx != prev_ctx && token != NULL);
+
+       /* defaults */
+       if (grow) {
+               error = css__stylesheet_style_appendOPV(grow_style, 
+                               CSS_PROP_FLEX_GROW, 0, FLEX_GROW_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_append(grow_style, 0);
                if (error != CSS_OK)
-                       goto css__parse_flex_flow_cleanup;
+                       goto css__parse_flex_cleanup;
+       }
+
+       if (shrink) {
+               error = css__stylesheet_style_appendOPV(shrink_style, 
+                               CSS_PROP_FLEX_SHRINK, 0, FLEX_SHRINK_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_append(shrink_style, INTTOFIX(1));
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+       }
 
-               error = css__stylesheet_style_append(basis_style, basis_unit);
+       if (basis) {
+               error = css__stylesheet_style_appendOPV(basis_style, 
+                               CSS_PROP_FLEX_BASIS, 0, FLEX_BASIS_AUTO);
                if (error != CSS_OK)
-                       goto css__parse_flex_flow_cleanup;
+                       goto css__parse_flex_cleanup;
        }
 
        error = css__stylesheet_merge_style(result, grow_style);
        if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               goto css__parse_flex_cleanup;
 
        error = css__stylesheet_merge_style(result, shrink_style);
        if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               goto css__parse_flex_cleanup;
 
        error = css__stylesheet_merge_style(result, basis_style);
 
-css__parse_flex_flow_cleanup:
+css__parse_flex_cleanup:
 
        css__stylesheet_style_destroy(basis_style);
        css__stylesheet_style_destroy(shrink_style);
diff --git a/src/parse/properties/flex_old.c b/src/parse/properties/flex_old.c
new file mode 100644
index 0000000..f189b3b
--- /dev/null
+++ b/src/parse/properties/flex_old.c
@@ -0,0 +1,326 @@
+/*
+ * This file is part of LibCSS.
+ * Licensed under the MIT License,
+ *               http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2017 Lucas Neves <[email protected]>
+ */
+
+#include <assert.h>
+#include <string.h>
+
+#include "bytecode/bytecode.h"
+#include "bytecode/opcodes.h"
+#include "parse/properties/properties.h"
+#include "parse/properties/utils.h"
+
+/**
+ * Parse list-style
+ *
+ * \param c      Parsing context
+ * \param vector  Vector of tokens to process
+ * \param ctx    Pointer to vector iteration context
+ * \param result  Pointer to location to receive resulting style
+ * \return CSS_OK on success,
+ *        CSS_NOMEM on memory exhaustion,
+ *        CSS_INVALID if the input is not valid
+ *
+ * Post condition: \a *ctx is updated with the next token to process
+ *                If the input is invalid, then \a *ctx remains unchanged.
+ */
+
+css_error flex_grow_helper(const css_token *token, css_fixed *number);
+css_error flex_basis_helper(css_language *c,
+               const parserutils_vector *vector, int *ctx,
+               css_fixed *basis_length, uint32_t *basis_unit,
+               opcode_t *basis_op);
+
+
+css_error flex_basis_helper(css_language *c,
+               const parserutils_vector *vector, int *ctx,
+               css_fixed *basis_length, uint32_t *basis_unit,
+               opcode_t *basis_op)
+{
+       css_error error;
+       error = css__parse_unit_specifier(c, vector, ctx,
+                               UNIT_PX, basis_length, basis_unit);
+
+       if (error == CSS_OK) {
+               if (*basis_unit & UNIT_ANGLE ||
+                               *basis_unit & UNIT_TIME ||
+                               *basis_unit & UNIT_FREQ) {
+                       return CSS_INVALID;
+               }
+               *basis_op = FLEX_BASIS_SET;
+       }
+
+       return error;
+}
+
+css_error flex_grow_helper(const css_token *token, css_fixed *number)
+{
+       if (token->type != CSS_TOKEN_NUMBER)
+               return CSS_INVALID;
+
+       size_t consumed = 0;
+       css_fixed num = css__number_from_lwc_string(
+                       token->idata, false, &consumed);
+
+       /* Invalid if there are trailing characters */
+       if (consumed != lwc_string_length(token->idata))
+               return CSS_INVALID;
+
+       /* Invalid if number is negative */
+       if (num < 0)
+               return CSS_INVALID;
+
+       *number = num;
+       return CSS_OK;
+}
+
+css_error css__parse_flex(css_language *c,
+               const parserutils_vector *vector, int *ctx,
+               css_style *result)
+{
+       int orig_ctx = *ctx;
+       const css_token *token;
+       css_error error;
+
+       /* Firstly, handle inherit */
+       token = parserutils_vector_peek(vector, *ctx);
+       if (token == NULL) 
+               return CSS_INVALID;
+               
+       if (is_css_inherit(c, token)) {
+               error = css_stylesheet_style_inherit(result,
+                               CSS_PROP_FLEX_GROW);
+               if (error != CSS_OK) 
+                       return error;
+
+               error = css_stylesheet_style_inherit(result,
+                               CSS_PROP_FLEX_SHRINK);
+               if (error != CSS_OK) 
+                       return error;
+
+
+               error = css_stylesheet_style_inherit(result,
+                               CSS_PROP_FLEX_BASIS);
+
+               if (error == CSS_OK) 
+                       parserutils_vector_iterate(vector, ctx);
+
+               return error;
+       } 
+
+       /* Default values */
+       opcode_t grow_op = FLEX_GROW_SET;
+       css_fixed grow_number = 0;
+       opcode_t shrink_op = FLEX_SHRINK_SET;
+       css_fixed shrink_number = INTTOFIX(1);
+       opcode_t basis_op = FLEX_BASIS_AUTO;
+       css_fixed basis_length = 0;
+       uint32_t basis_unit = UNIT_PX;
+
+       /* Attempt to parse the various longhand properties */
+       *ctx = orig_ctx;
+       size_t length = -1;
+
+       do {
+               ++length;
+               token = parserutils_vector_iterate(vector, ctx);
+       } while (token != NULL);
+
+       *ctx = orig_ctx;
+
+       switch (length) {
+       case 1:
+               token = parserutils_vector_iterate(vector, ctx);
+               if (token == NULL || token->type != CSS_TOKEN_IDENT) {
+                       *ctx = orig_ctx;
+                       return CSS_INVALID;
+               }
+
+               /*
+                * Handle auto and none
+                * auto = flex: 1 1 auto;
+                * none = flex: 0 0 auto;
+                */
+               bool match;
+               if ((lwc_string_caseless_isequal(
+                               token->idata, c->strings[AUTO],
+                               &match) == lwc_error_ok && match) ||
+                               (lwc_string_caseless_isequal(
+                               token->idata, c->strings[NONE],
+                               &match) == lwc_error_ok && match)) {
+                       if ((lwc_string_caseless_isequal(
+                                       token->idata, c->strings[AUTO],
+                                       &match) == lwc_error_ok && match)) {
+                               grow_number = INTTOFIX(1);
+                       }
+                       else {
+                               shrink_number = 0;
+                       }
+
+               }
+
+               /* Token must be either flex-basis or flex-grow */
+               else {
+                       *ctx = orig_ctx;
+                       error = flex_basis_helper(c, vector, ctx,
+                                       &basis_length, &basis_unit,
+                                       &basis_op);
+
+                       if (error != CSS_OK) {
+                               /* Positive number: equivalent of
+                                * flex: <positive number> 1 0; */
+                               *ctx = orig_ctx;
+                               token = parserutils_vector_iterate(vector, ctx);
+                               error = flex_grow_helper(
+                                               token, &grow_number);
+                               if (error != CSS_OK) {
+                                       *ctx = orig_ctx;
+                                       return CSS_INVALID;
+                               }
+                               basis_op = FLEX_BASIS_SET;
+                       }
+               }
+               break;
+
+       case 2:
+               /* First value must be flex-grow */
+               token = parserutils_vector_iterate(vector, ctx);
+               error = flex_grow_helper(
+                               token, &grow_number);
+               if (error != CSS_OK) {
+                       *ctx = orig_ctx;
+                       return CSS_INVALID;
+               }
+
+               /* Second value must be either flex-basis or flex-shrink */
+               int prev_ctx = *ctx;
+               error = flex_basis_helper(c, vector, ctx,
+                               &basis_length, &basis_unit, &basis_op);
+
+               if (error != CSS_OK) {
+                       /* Two positive numbers: equivalent of
+                        * flex: <number_1> <number_2> 0; */
+                       *ctx = prev_ctx;
+                       token = parserutils_vector_iterate(vector, ctx);
+                       error = flex_grow_helper(
+                                       token, &shrink_number);
+                       if (error != CSS_OK) {
+                               *ctx = orig_ctx;
+                               return CSS_INVALID;
+                       }
+                       basis_op = FLEX_BASIS_SET;
+               }
+               break;
+
+       case 3:
+               /* First value must be flex-grow */
+               token = parserutils_vector_iterate(vector, ctx);
+               error = flex_grow_helper(
+                               token, &grow_number);
+               if (error != CSS_OK) {
+                       *ctx = orig_ctx;
+                       return CSS_INVALID;
+               }
+
+               /* Second value must be flex-shrink */
+               token = parserutils_vector_iterate(vector, ctx);
+               error = flex_grow_helper(
+                               token, &shrink_number);
+               if (error != CSS_OK) {
+                       *ctx = orig_ctx;
+                       return CSS_INVALID;
+               }
+
+               /* Third value must be flex-basis */
+               error = flex_basis_helper(c, vector, ctx,
+                               &basis_length, &basis_unit, &basis_op);
+               if (error != CSS_OK) {
+                       *ctx = orig_ctx;
+                       return CSS_INVALID;
+               }
+               break;
+
+       default:
+               return CSS_INVALID;
+       }
+
+       /* allocate styles */
+       css_style *grow_style;
+       css_style *shrink_style;
+       css_style *basis_style;
+
+       error = css__stylesheet_style_create(c->sheet, &grow_style);
+       if (error != CSS_OK) 
+               return error;
+
+       error = css__stylesheet_style_create(c->sheet, &shrink_style);
+       if (error != CSS_OK) {
+               css__stylesheet_style_destroy(grow_style);
+               return error;
+        }
+
+       error = css__stylesheet_style_create(c->sheet, &basis_style);
+       if (error != CSS_OK) {
+               css__stylesheet_style_destroy(shrink_style);
+               css__stylesheet_style_destroy(grow_style);
+               return error;
+       }
+
+       error = css__stylesheet_style_appendOPV(grow_style, 
+                       CSS_PROP_FLEX_GROW, 0, grow_op);
+       if (error != CSS_OK)
+               goto css__parse_flex_flow_cleanup;
+
+       error = css__stylesheet_style_append(grow_style, grow_number);
+       if (error != CSS_OK)
+               goto css__parse_flex_flow_cleanup;
+
+       error = css__stylesheet_style_appendOPV(shrink_style, 
+                       CSS_PROP_FLEX_SHRINK, 0, shrink_op);
+       if (error != CSS_OK)
+               goto css__parse_flex_flow_cleanup;
+
+       error = css__stylesheet_style_append(shrink_style, shrink_number);
+       if (error != CSS_OK)
+               goto css__parse_flex_flow_cleanup;
+
+       error = css__stylesheet_style_appendOPV(basis_style, 
+                       CSS_PROP_FLEX_BASIS, 0, basis_op);
+       if (error != CSS_OK)
+               goto css__parse_flex_flow_cleanup;
+
+       if (basis_op == (opcode_t) FLEX_BASIS_SET) {
+               error = css__stylesheet_style_append(basis_style, basis_length);
+               if (error != CSS_OK)
+                       goto css__parse_flex_flow_cleanup;
+
+               error = css__stylesheet_style_append(basis_style, basis_unit);
+               if (error != CSS_OK)
+                       goto css__parse_flex_flow_cleanup;
+       }
+
+       error = css__stylesheet_merge_style(result, grow_style);
+       if (error != CSS_OK)
+               goto css__parse_flex_flow_cleanup;
+
+       error = css__stylesheet_merge_style(result, shrink_style);
+       if (error != CSS_OK)
+               goto css__parse_flex_flow_cleanup;
+
+       error = css__stylesheet_merge_style(result, basis_style);
+
+css__parse_flex_flow_cleanup:
+
+       css__stylesheet_style_destroy(basis_style);
+       css__stylesheet_style_destroy(shrink_style);
+       css__stylesheet_style_destroy(grow_style);
+
+       if (error != CSS_OK)
+               *ctx = orig_ctx;
+
+       return error;
+}
+


-----------------------------------------------------------------------

Summary of changes:
 src/parse/properties/flex.c |  355 ++++++++++++++++---------------------------
 1 file changed, 134 insertions(+), 221 deletions(-)

diff --git a/src/parse/properties/flex.c b/src/parse/properties/flex.c
index f189b3b..b2fd67e 100644
--- a/src/parse/properties/flex.c
+++ b/src/parse/properties/flex.c
@@ -28,62 +28,21 @@
  *                If the input is invalid, then \a *ctx remains unchanged.
  */
 
-css_error flex_grow_helper(const css_token *token, css_fixed *number);
-css_error flex_basis_helper(css_language *c,
-               const parserutils_vector *vector, int *ctx,
-               css_fixed *basis_length, uint32_t *basis_unit,
-               opcode_t *basis_op);
-
-
-css_error flex_basis_helper(css_language *c,
-               const parserutils_vector *vector, int *ctx,
-               css_fixed *basis_length, uint32_t *basis_unit,
-               opcode_t *basis_op)
-{
-       css_error error;
-       error = css__parse_unit_specifier(c, vector, ctx,
-                               UNIT_PX, basis_length, basis_unit);
-
-       if (error == CSS_OK) {
-               if (*basis_unit & UNIT_ANGLE ||
-                               *basis_unit & UNIT_TIME ||
-                               *basis_unit & UNIT_FREQ) {
-                       return CSS_INVALID;
-               }
-               *basis_op = FLEX_BASIS_SET;
-       }
-
-       return error;
-}
-
-css_error flex_grow_helper(const css_token *token, css_fixed *number)
-{
-       if (token->type != CSS_TOKEN_NUMBER)
-               return CSS_INVALID;
-
-       size_t consumed = 0;
-       css_fixed num = css__number_from_lwc_string(
-                       token->idata, false, &consumed);
-
-       /* Invalid if there are trailing characters */
-       if (consumed != lwc_string_length(token->idata))
-               return CSS_INVALID;
-
-       /* Invalid if number is negative */
-       if (num < 0)
-               return CSS_INVALID;
-
-       *number = num;
-       return CSS_OK;
-}
-
 css_error css__parse_flex(css_language *c,
                const parserutils_vector *vector, int *ctx,
                css_style *result)
 {
        int orig_ctx = *ctx;
+       int prev_ctx;
        const css_token *token;
        css_error error;
+       bool grow = true;
+       bool shrink = true;
+       bool basis = true;
+       css_style *grow_style;
+       css_style *shrink_style;
+       css_style *basis_style;
+       bool match;
 
        /* Firstly, handle inherit */
        token = parserutils_vector_peek(vector, *ctx);
@@ -92,16 +51,16 @@ css_error css__parse_flex(css_language *c,
                
        if (is_css_inherit(c, token)) {
                error = css_stylesheet_style_inherit(result,
-                               CSS_PROP_FLEX_GROW);
+                               CSS_PROP_FLEX_SHRINK);
                if (error != CSS_OK) 
                        return error;
 
                error = css_stylesheet_style_inherit(result,
-                               CSS_PROP_FLEX_SHRINK);
+                               CSS_PROP_FLEX_GROW);
+
                if (error != CSS_OK) 
                        return error;
 
-
                error = css_stylesheet_style_inherit(result,
                                CSS_PROP_FLEX_BASIS);
 
@@ -109,149 +68,9 @@ css_error css__parse_flex(css_language *c,
                        parserutils_vector_iterate(vector, ctx);
 
                return error;
-       } 
-
-       /* Default values */
-       opcode_t grow_op = FLEX_GROW_SET;
-       css_fixed grow_number = 0;
-       opcode_t shrink_op = FLEX_SHRINK_SET;
-       css_fixed shrink_number = INTTOFIX(1);
-       opcode_t basis_op = FLEX_BASIS_AUTO;
-       css_fixed basis_length = 0;
-       uint32_t basis_unit = UNIT_PX;
-
-       /* Attempt to parse the various longhand properties */
-       *ctx = orig_ctx;
-       size_t length = -1;
-
-       do {
-               ++length;
-               token = parserutils_vector_iterate(vector, ctx);
-       } while (token != NULL);
-
-       *ctx = orig_ctx;
-
-       switch (length) {
-       case 1:
-               token = parserutils_vector_iterate(vector, ctx);
-               if (token == NULL || token->type != CSS_TOKEN_IDENT) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /*
-                * Handle auto and none
-                * auto = flex: 1 1 auto;
-                * none = flex: 0 0 auto;
-                */
-               bool match;
-               if ((lwc_string_caseless_isequal(
-                               token->idata, c->strings[AUTO],
-                               &match) == lwc_error_ok && match) ||
-                               (lwc_string_caseless_isequal(
-                               token->idata, c->strings[NONE],
-                               &match) == lwc_error_ok && match)) {
-                       if ((lwc_string_caseless_isequal(
-                                       token->idata, c->strings[AUTO],
-                                       &match) == lwc_error_ok && match)) {
-                               grow_number = INTTOFIX(1);
-                       }
-                       else {
-                               shrink_number = 0;
-                       }
-
-               }
-
-               /* Token must be either flex-basis or flex-grow */
-               else {
-                       *ctx = orig_ctx;
-                       error = flex_basis_helper(c, vector, ctx,
-                                       &basis_length, &basis_unit,
-                                       &basis_op);
-
-                       if (error != CSS_OK) {
-                               /* Positive number: equivalent of
-                                * flex: <positive number> 1 0; */
-                               *ctx = orig_ctx;
-                               token = parserutils_vector_iterate(vector, ctx);
-                               error = flex_grow_helper(
-                                               token, &grow_number);
-                               if (error != CSS_OK) {
-                                       *ctx = orig_ctx;
-                                       return CSS_INVALID;
-                               }
-                               basis_op = FLEX_BASIS_SET;
-                       }
-               }
-               break;
-
-       case 2:
-               /* First value must be flex-grow */
-               token = parserutils_vector_iterate(vector, ctx);
-               error = flex_grow_helper(
-                               token, &grow_number);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /* Second value must be either flex-basis or flex-shrink */
-               int prev_ctx = *ctx;
-               error = flex_basis_helper(c, vector, ctx,
-                               &basis_length, &basis_unit, &basis_op);
-
-               if (error != CSS_OK) {
-                       /* Two positive numbers: equivalent of
-                        * flex: <number_1> <number_2> 0; */
-                       *ctx = prev_ctx;
-                       token = parserutils_vector_iterate(vector, ctx);
-                       error = flex_grow_helper(
-                                       token, &shrink_number);
-                       if (error != CSS_OK) {
-                               *ctx = orig_ctx;
-                               return CSS_INVALID;
-                       }
-                       basis_op = FLEX_BASIS_SET;
-               }
-               break;
-
-       case 3:
-               /* First value must be flex-grow */
-               token = parserutils_vector_iterate(vector, ctx);
-               error = flex_grow_helper(
-                               token, &grow_number);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /* Second value must be flex-shrink */
-               token = parserutils_vector_iterate(vector, ctx);
-               error = flex_grow_helper(
-                               token, &shrink_number);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-
-               /* Third value must be flex-basis */
-               error = flex_basis_helper(c, vector, ctx,
-                               &basis_length, &basis_unit, &basis_op);
-               if (error != CSS_OK) {
-                       *ctx = orig_ctx;
-                       return CSS_INVALID;
-               }
-               break;
-
-       default:
-               return CSS_INVALID;
        }
-
+       
        /* allocate styles */
-       css_style *grow_style;
-       css_style *shrink_style;
-       css_style *basis_style;
-
        error = css__stylesheet_style_create(c->sheet, &grow_style);
        if (error != CSS_OK) 
                return error;
@@ -260,59 +79,153 @@ css_error css__parse_flex(css_language *c,
        if (error != CSS_OK) {
                css__stylesheet_style_destroy(grow_style);
                return error;
-        }
+       }
 
        error = css__stylesheet_style_create(c->sheet, &basis_style);
        if (error != CSS_OK) {
-               css__stylesheet_style_destroy(shrink_style);
                css__stylesheet_style_destroy(grow_style);
+               css__stylesheet_style_destroy(shrink_style);
                return error;
        }
 
-       error = css__stylesheet_style_appendOPV(grow_style, 
-                       CSS_PROP_FLEX_GROW, 0, grow_op);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+       /* Handle none = flex: 0 0 auto; */
+       if ((token->type == CSS_TOKEN_IDENT) &&
+               (lwc_string_caseless_isequal(
+                       token->idata, c->strings[NONE],
+                       &match) == lwc_error_ok && match)) {
+               error = css__stylesheet_style_appendOPV(grow_style, 
+                               CSS_PROP_FLEX_GROW, 0, FLEX_GROW_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
 
-       error = css__stylesheet_style_append(grow_style, grow_number);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               error = css__stylesheet_style_append(grow_style, 0);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
 
-       error = css__stylesheet_style_appendOPV(shrink_style, 
-                       CSS_PROP_FLEX_SHRINK, 0, shrink_op);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               error = css__stylesheet_style_appendOPV(shrink_style, 
+                               CSS_PROP_FLEX_SHRINK, 0, FLEX_SHRINK_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
 
-       error = css__stylesheet_style_append(shrink_style, shrink_number);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               error = css__stylesheet_style_append(shrink_style, 0);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
 
-       error = css__stylesheet_style_appendOPV(basis_style, 
-                       CSS_PROP_FLEX_BASIS, 0, basis_op);
-       if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               error = css__stylesheet_style_appendOPV(basis_style, 
+                               CSS_PROP_FLEX_BASIS, 0, FLEX_BASIS_AUTO);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               grow = shrink = basis = false;
+       }
+
+       /* Handle auto = flex: 1 1 auto; */
+       else if ((token->type == CSS_TOKEN_IDENT) &&
+               (lwc_string_caseless_isequal(
+                       token->idata, c->strings[AUTO],
+                       &match) == lwc_error_ok && match)) {
+               error = css__stylesheet_style_appendOPV(grow_style, 
+                               CSS_PROP_FLEX_GROW, 0, FLEX_GROW_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_append(grow_style, INTTOFIX(1));
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_appendOPV(shrink_style, 
+                               CSS_PROP_FLEX_SHRINK, 0, FLEX_SHRINK_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_append(shrink_style, INTTOFIX(1));
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_appendOPV(basis_style, 
+                               CSS_PROP_FLEX_BASIS, 0, FLEX_BASIS_AUTO);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               grow = shrink = basis = false;
+       }
+
+       /* Attempt to parse the various longhand properties */
+       else do {
+               prev_ctx = *ctx;
+               error = CSS_OK;
+
+               /* Ensure that we're not about to parse another inherit */
+               token = parserutils_vector_peek(vector, *ctx);
+               if (token != NULL && is_css_inherit(c, token)) {
+                       error = CSS_INVALID;
+                       goto css__parse_flex_cleanup;
+               }
 
-       if (basis_op == (opcode_t) FLEX_BASIS_SET) {
-               error = css__stylesheet_style_append(basis_style, basis_length);
+               if ((grow) && 
+                          (error = css__parse_flex_grow(c, vector,
+                               ctx, grow_style)) == CSS_OK) {
+                       grow = false;
+               } else if ((basis) && 
+                          (error = css__parse_flex_basis(c, vector, 
+                               ctx, basis_style)) == CSS_OK) {
+                       basis = false;
+               } else if ((shrink) && 
+                          (error = css__parse_flex_shrink(c, vector, 
+                               ctx, shrink_style)) == CSS_OK) {
+                       shrink = false;
+               }
+
+               if (error == CSS_OK) {
+                       consumeWhitespace(vector, ctx);
+                       token = parserutils_vector_peek(vector, *ctx);
+               } else {
+                       /* Forcibly cause loop to exit */
+                       token = NULL;
+               }
+       } while (*ctx != prev_ctx && token != NULL);
+
+       /* defaults */
+       if (grow) {
+               error = css__stylesheet_style_appendOPV(grow_style, 
+                               CSS_PROP_FLEX_GROW, 0, FLEX_GROW_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_append(grow_style, 0);
                if (error != CSS_OK)
-                       goto css__parse_flex_flow_cleanup;
+                       goto css__parse_flex_cleanup;
+       }
+
+       if (shrink) {
+               error = css__stylesheet_style_appendOPV(shrink_style, 
+                               CSS_PROP_FLEX_SHRINK, 0, FLEX_SHRINK_SET);
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+
+               error = css__stylesheet_style_append(shrink_style, INTTOFIX(1));
+               if (error != CSS_OK)
+                       goto css__parse_flex_cleanup;
+       }
 
-               error = css__stylesheet_style_append(basis_style, basis_unit);
+       if (basis) {
+               error = css__stylesheet_style_appendOPV(basis_style, 
+                               CSS_PROP_FLEX_BASIS, 0, FLEX_BASIS_AUTO);
                if (error != CSS_OK)
-                       goto css__parse_flex_flow_cleanup;
+                       goto css__parse_flex_cleanup;
        }
 
        error = css__stylesheet_merge_style(result, grow_style);
        if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               goto css__parse_flex_cleanup;
 
        error = css__stylesheet_merge_style(result, shrink_style);
        if (error != CSS_OK)
-               goto css__parse_flex_flow_cleanup;
+               goto css__parse_flex_cleanup;
 
        error = css__stylesheet_merge_style(result, basis_style);
 
-css__parse_flex_flow_cleanup:
+css__parse_flex_cleanup:
 
        css__stylesheet_style_destroy(basis_style);
        css__stylesheet_style_destroy(shrink_style);


-- 
Cascading Style Sheets library

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to