Photon 1.0.0
Loading...
Searching...
No Matches
parser.c File Reference
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "attribute.h"
#include "error.h"
#include "gumbo.h"
#include "insertion_mode.h"
#include "parser.h"
#include "tokenizer.h"
#include "tokenizer_states.h"
#include "utf8.h"
#include "util.h"
#include "vector.h"

Classes

struct  _ReplacementEntry
 
struct  _NamespacedAttributeReplacement
 
struct  _TextNodeBufferState
 
struct  GumboInternalParserState
 
struct  InsertionLocation
 

Macros

#define AVOID_UNUSED_VARIABLE_WARNING(i)   (void)(i)
 
#define GUMBO_STRING(literal)    { literal, sizeof(literal) - 1 }
 
#define TERMINATOR    { "", 0 }
 
#define TAG(tag)   [GUMBO_TAG_##tag] = (1 << GUMBO_NAMESPACE_HTML)
 
#define TAG_SVG(tag)   [GUMBO_TAG_##tag] = (1 << GUMBO_NAMESPACE_SVG)
 
#define TAG_MATHML(tag)   [GUMBO_TAG_##tag] = (1 << GUMBO_NAMESPACE_MATHML)
 
#define TAGSET_INCLUDES(tagset, namespace, tag)    (tag < GUMBO_TAG_LAST && tagset[(int) tag] & (1 << (int) namespace))
 
#define REPLACEMENT_ENTRY(from, to)    { GUMBO_STRING(from), GUMBO_STRING(to) }
 

Typedefs

typedef char gumbo_tagset[GUMBO_TAG_LAST]
 
typedef struct _ReplacementEntry ReplacementEntry
 
typedef struct _NamespacedAttributeReplacement NamespacedAttributeReplacement
 
typedef struct _TextNodeBufferState TextNodeBufferState
 
typedef struct GumboInternalParserState GumboParserState
 
typedef bool(* TokenHandler) (GumboParser *parser, GumboToken *token)
 

Functions

InsertionLocation get_appropriate_insertion_location (GumboParser *parser, GumboNode *override_target)
 
void clear_stack_to_table_body_context (GumboParser *parser)
 
GumboNodeclone_node (GumboParser *parser, GumboNode *node, GumboParseFlags reason)
 
const char * gumbo_normalize_svg_tagname (const GumboStringPiece *tag)
 
GumboOutputgumbo_parse (const char *buffer)
 
GumboOutputgumbo_parse_with_options (const GumboOptions *options, const char *buffer, size_t length)
 
void gumbo_destroy_node (GumboOptions *options, GumboNode *node)
 
void gumbo_destroy_output (const GumboOptions *options, GumboOutput *output)
 

Variables

const GumboOptions kGumboDefaultOptions
 

Macro Definition Documentation

◆ AVOID_UNUSED_VARIABLE_WARNING

#define AVOID_UNUSED_VARIABLE_WARNING (   i)    (void)(i)

◆ GUMBO_STRING

#define GUMBO_STRING (   literal)     { literal, sizeof(literal) - 1 }

◆ REPLACEMENT_ENTRY

#define REPLACEMENT_ENTRY (   from,
  to 
)     { GUMBO_STRING(from), GUMBO_STRING(to) }

◆ TAG

#define TAG (   tag)    [GUMBO_TAG_##tag] = (1 << GUMBO_NAMESPACE_HTML)

◆ TAG_MATHML

#define TAG_MATHML (   tag)    [GUMBO_TAG_##tag] = (1 << GUMBO_NAMESPACE_MATHML)

◆ TAG_SVG

#define TAG_SVG (   tag)    [GUMBO_TAG_##tag] = (1 << GUMBO_NAMESPACE_SVG)

◆ TAGSET_INCLUDES

#define TAGSET_INCLUDES (   tagset,
  namespace,
  tag 
)     (tag < GUMBO_TAG_LAST && tagset[(int) tag] & (1 << (int) namespace))

◆ TERMINATOR

#define TERMINATOR    { "", 0 }

Typedef Documentation

◆ gumbo_tagset

typedef char gumbo_tagset[GUMBO_TAG_LAST]

◆ GumboParserState

◆ NamespacedAttributeReplacement

◆ ReplacementEntry

◆ TextNodeBufferState

◆ TokenHandler

typedef bool(* TokenHandler) (GumboParser *parser, GumboToken *token)

Function Documentation

◆ clear_stack_to_table_body_context()

void clear_stack_to_table_body_context ( GumboParser parser)

◆ clone_node()

GumboNode * clone_node ( GumboParser parser,
GumboNode node,
GumboParseFlags  reason 
)

◆ get_appropriate_insertion_location()

InsertionLocation get_appropriate_insertion_location ( GumboParser parser,
GumboNode override_target 
)

◆ gumbo_destroy_node()

void gumbo_destroy_node ( GumboOptions options,
GumboNode node 
)

◆ gumbo_destroy_output()

void gumbo_destroy_output ( const GumboOptions options,
GumboOutput output 
)

Release the memory used for the parse tree & parse errors.

◆ gumbo_normalize_svg_tagname()

const char * gumbo_normalize_svg_tagname ( const GumboStringPiece tagname)

Fixes the case of SVG elements that are not all lowercase. http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html#parsing-main-inforeign This is not done at parse time because there's no place to store a mutated tag name. tag_name is an enum (which will be TAG_UNKNOWN for most SVG tags without special handling), while original_tag_name is a pointer into the original buffer. Instead, we provide this helper function that clients can use to rename SVG tags as appropriate. Returns the case-normalized SVG tagname if a replacement is found, or NULL if no normalization is called for. The return value is static data and owned by the library.

◆ gumbo_parse()

GumboOutput * gumbo_parse ( const char *  buffer)

Parses a buffer of UTF8 text into an GumboNode parse tree. The buffer must live at least as long as the parse tree, as some fields (eg. original_text) point directly into the original buffer.

This doesn't support buffers longer than 4 gigabytes.

◆ gumbo_parse_with_options()

GumboOutput * gumbo_parse_with_options ( const GumboOptions options,
const char *  buffer,
size_t  buffer_length 
)

Extended version of gumbo_parse that takes an explicit options structure, buffer, and length.

Variable Documentation

◆ kGumboDefaultOptions

const GumboOptions kGumboDefaultOptions
Initial value:
= {&malloc_wrapper, &free_wrapper, NULL,
@ GUMBO_NAMESPACE_HTML
Definition gumbo.h:335
@ GUMBO_TAG_LAST
Definition gumbo.h:164
#define NULL
Definition strtod.cpp:30

Default options struct; use this with gumbo_parse_with_options.