Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * This file is part of LibCSS.
  3.  * Licensed under the MIT License,
  4.  *                http://www.opensource.org/licenses/mit-license.php
  5.  * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
  6.  */
  7.  
  8. #include <assert.h>
  9. #include <string.h>
  10.  
  11. #include "bytecode/bytecode.h"
  12. #include "bytecode/opcodes.h"
  13. #include "parse/properties/properties.h"
  14. #include "parse/properties/utils.h"
  15.  
  16. /**
  17.  * Parse pause shorthand
  18.  *
  19.  * \param c       Parsing context
  20.  * \param vector  Vector of tokens to process
  21.  * \param ctx     Pointer to vector iteration context
  22.  * \param result  Pointer to location to receive resulting style
  23.  * \return CSS_OK on success,
  24.  *         CSS_NOMEM on memory exhaustion,
  25.  *         CSS_INVALID if the input is not valid
  26.  *
  27.  * Post condition: \a *ctx is updated with the next token to process
  28.  *                 If the input is invalid, then \a *ctx remains unchanged.
  29.  */
  30. css_error css__parse_pause(css_language *c,
  31.                 const parserutils_vector *vector, int *ctx,
  32.                 css_style *result)
  33. {
  34.         int orig_ctx = *ctx;
  35.         css_error error;
  36.         const css_token *first_token;
  37.         const css_token *token;
  38.  
  39.         /* one or two tokens follow:
  40.          *  if one emit for both BEFORE and AFTER
  41.          *  if two first is before second is after
  42.          *  tokens are either IDENT:none or URI
  43.          */
  44.  
  45.         first_token = parserutils_vector_peek(vector, *ctx);
  46.  
  47.         error = css__parse_pause_before(c, vector, ctx, result);
  48.         if (error == CSS_OK) {
  49.                 /* first token parsed */
  50.  
  51.                 consumeWhitespace(vector, ctx);
  52.  
  53.                 token = parserutils_vector_peek(vector, *ctx);
  54.                 if (token == NULL)  {
  55.                         /* no second token, re-parse the first */
  56.                         *ctx = orig_ctx;
  57.                         error = css__parse_pause_after(c, vector, ctx, result);
  58.                 } else {
  59.                         /* second token - might be useful */
  60.                         if (is_css_inherit(c, token)) {
  61.                                 /* another bogus inherit */
  62.                                 error = CSS_INVALID;
  63.                         } else {
  64.                                 error = css__parse_pause_after(c, vector, ctx, result);
  65.                                 if (error == CSS_OK) {
  66.                                         /* second token parsed */
  67.                                         if (is_css_inherit(c, first_token)) {
  68.                                                 /* valid second token after inherit */
  69.                                                 error = CSS_INVALID;
  70.                                         }
  71.                                 } else {
  72.                                         /* second token appears to be junk re-try with first */
  73.                                         *ctx = orig_ctx;
  74.                                         error = css__parse_pause_after(c, vector, ctx, result);
  75.                                 }
  76.                         }
  77.                 }
  78.         }
  79.  
  80.  
  81.         if (error != CSS_OK)
  82.                 *ctx = orig_ctx;
  83.  
  84.         return error;
  85. }
  86.