ELinks 0.18.0
parser.c File Reference

CSS main parser. More...

#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "config/options.h"
#include "document/css/css.h"
#include "document/css/parser.h"
#include "document/css/property.h"
#include "document/css/scanner.h"
#include "document/css/stylesheet.h"
#include "document/css/value.h"
#include "util/color.h"
#include "util/lists.h"
#include "util/error.h"
#include "util/memory.h"
#include "util/string.h"
Include dependency graph for parser.c:

Data Structures

struct  selector_pkg

Functions

static void css_parse_ruleset (struct css_stylesheet *css, struct scanner *scanner)
 Parse a ruleset from scanner to css.
void css_parse_properties (struct css_property list *props, struct scanner *scanner)
 This function takes a semicolon separated list of declarations from the given string, parses them to atoms, and chains the newly created struct css_property objects to the specified list.
static void skip_css_block (struct scanner *scanner)
static int css_parse_media_types (struct scanner *scanner)
static void css_parse_atrule (struct css_stylesheet *css, struct scanner *scanner, struct uri *base_uri)
 Parse an atrule from scanner and update css accordingly.
static struct css_selectorreparent_selector (struct css_selector_set *sels, struct css_selector *selector, struct css_selector **watch)
 Move a CSS selector and its leaves into a new set.
static void css_parse_selector (struct css_stylesheet *css, struct scanner *scanner, struct selector_pkg list *selectors)
 Parse a comma-separated list of CSS selectors from scanner.
void css_parse_stylesheet (struct css_stylesheet *css, struct uri *base_uri, const char *string, const char *end)
 Parses the string and adds any recognized selectors + properties to the given stylesheet css.

Detailed Description

CSS main parser.

Function Documentation

◆ css_parse_atrule()

void css_parse_atrule ( struct css_stylesheet * css,
struct scanner * scanner,
struct uri * base_uri )
static

Parse an atrule from scanner and update css accordingly.

Atrules grammar:

* atrule:
*    '@charset' <string> ';'
*  | '@import' <string> media_types ';'
*  | '@import' <uri> media_types ';'
*  | '@media' media_types '{' ruleset* '}'
*  | '@page' <ident>? [':' <ident>]? '{' properties '}'
*  | '@font-face' '{' properties '}'
* 

◆ css_parse_media_types()

int css_parse_media_types ( struct scanner * scanner)
static

◆ css_parse_properties()

void css_parse_properties ( struct css_property list * props,
struct scanner * scanner )

This function takes a semicolon separated list of declarations from the given string, parses them to atoms, and chains the newly created struct css_property objects to the specified list.

Returns
positive value in case it recognized a property in the given string, or zero in case of an error.

◆ css_parse_ruleset()

void css_parse_ruleset ( struct css_stylesheet * css,
struct scanner * scanner )
static

Parse a ruleset from scanner to css.

Ruleset grammar:

* ruleset:
*    selector [ ',' selector ]* '{' properties '}'
* 

◆ css_parse_selector()

void css_parse_selector ( struct css_stylesheet * css,
struct scanner * scanner,
struct selector_pkg list * selectors )
static

Parse a comma-separated list of CSS selectors from scanner.

Register the selectors in css so that get_css_selector_for_element() will find them, and add them to selectors so that the caller can attach properties to them.

Our selector grammar:

* selector:
*    element_name? ('#' id)? ('.' class)? (':' pseudo_class)? \
*       ((' ' | '>') selector)?
* 

◆ css_parse_stylesheet()

void css_parse_stylesheet ( struct css_stylesheet * css,
struct uri * base_uri,
const char * string,
const char * end )

Parses the string and adds any recognized selectors + properties to the given stylesheet css.

If the selector is already in the stylesheet it properties are added to the that selector.

◆ reparent_selector()

struct css_selector * reparent_selector ( struct css_selector_set * sels,
struct css_selector * selector,
struct css_selector ** watch )
static

Move a CSS selector and its leaves into a new set.

If a similar selector already exists in the set, merge them.

Parameters
selsThe set to which selector should be moved. Must not be NULL.
selectorThe selector that should be moved. Must not be NULL. If it is already in some set, this function removes it from there.
watchThis function updates *watch if it merges that selector into another one. watch must not be NULL but *watch may be.
Returns
selector or the one into which it was merged.

◆ skip_css_block()

void skip_css_block ( struct scanner * scanner)
static