Photon 1.0.0
Loading...
Searching...
No Matches
tokenizer.h
Go to the documentation of this file.
1// Copyright 2010 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Author: jdtang@google.com (Jonathan Tang)
16//
17// This contains an implementation of a tokenizer for HTML5. It consumes a
18// buffer of UTF-8 characters, and then emits a stream of tokens.
19
20#ifndef GUMBO_TOKENIZER_H_
21#define GUMBO_TOKENIZER_H_
22
23#include <stdbool.h>
24#include <stddef.h>
25
26#include "gumbo.h"
27#include "token_type.h"
28#include "tokenizer_states.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
35
36// Struct containing all information pertaining to doctype tokens.
38 const char* name;
39 const char* public_identifier;
40 const char* system_identifier;
42 // There's no way to tell a 0-length public or system ID apart from the
43 // absence of a public or system ID, but they're handled different by the
44 // spec, so we need bool flags for them.
48
49// Struct containing all information pertaining to start tag tokens.
55
56// A data structure representing a single token in the input stream. This
57// contains an enum for the type, the source position, a GumboStringPiece
58// pointing to the original text, and then a union for any parsed data.
71
72// Initializes the tokenizer state within the GumboParser object, setting up a
73// parse of the specified text.
75 struct GumboInternalParser* parser, const char* text, size_t text_length);
76
77// Destroys the tokenizer state within the GumboParser object, freeing any
78// dynamically-allocated structures within it.
80
81// Sets the tokenizer state to the specified value. This is needed by some
82// parser states, which alter the state of the tokenizer in response to tags
83// seen.
85 struct GumboInternalParser* parser, GumboTokenizerEnum state);
86
87// Flags whether the current node is a foreign content element. This is
88// necessary for the markup declaration open state, where the tokenizer must be
89// aware of the state of the parser to properly tokenize bad comment tags.
90// http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#markup-declaration-open-state
92 struct GumboInternalParser* parser, bool is_foreign);
93
94// Lexes a single token from the specified buffer, filling the output with the
95// parsed GumboToken data structure. Returns true for a successful
96// tokenization, false if a parse error occurs.
97//
98// Example:
99// struct GumboInternalParser parser;
100// GumboToken output;
101// gumbo_tokenizer_state_init(&parser, text, strlen(text));
102// while (gumbo_lex(&parser, &output)) {
103// ...do stuff with output.
104// gumbo_token_destroy(&parser, &token);
105// }
106// gumbo_tokenizer_state_destroy(&parser);
107bool gumbo_lex(struct GumboInternalParser* parser, GumboToken* output);
108
109// Frees the internally-allocated pointers within an GumboToken. Note that this
110// doesn't free the token itself, since oftentimes it will be allocated on the
111// stack. A simple call to free() (or GumboParser->deallocator, if
112// appropriate) can handle that.
113//
114// Note that if you are handing over ownership of the internal strings to some
115// other data structure - for example, a parse tree - these do not need to be
116// freed.
117void gumbo_token_destroy(struct GumboInternalParser* parser, GumboToken* token);
118
119#ifdef __cplusplus
120}
121#endif
122
123#endif // GUMBO_TOKENIZER_H_
GumboTag
Definition gumbo.h:156
Definition parser.h:35
Definition tokenizer.h:37
const char * name
Definition tokenizer.h:38
bool force_quirks
Definition tokenizer.h:41
const char * system_identifier
Definition tokenizer.h:40
bool has_public_identifier
Definition tokenizer.h:45
const char * public_identifier
Definition tokenizer.h:39
bool has_system_identifier
Definition tokenizer.h:46
Definition tokenizer.h:59
union GumboInternalToken::@17 v
GumboTokenType type
Definition tokenizer.h:60
GumboStringPiece original_text
Definition tokenizer.h:62
GumboTokenStartTag start_tag
Definition tokenizer.h:65
GumboSourcePosition position
Definition tokenizer.h:61
GumboTag end_tag
Definition tokenizer.h:66
GumboTokenDocType doc_type
Definition tokenizer.h:64
const char * text
Definition tokenizer.h:67
int character
Definition tokenizer.h:68
Definition tokenizer.h:50
GumboVector attributes
Definition tokenizer.h:52
GumboTag tag
Definition tokenizer.h:51
bool is_self_closing
Definition tokenizer.h:53
Definition gumbo.h:67
Definition gumbo.h:88
Definition gumbo.h:122
annotation output
Definition tag_strings.h:122
GumboTokenType
Definition token_type.h:25
struct GumboInternalTokenStartTag GumboTokenStartTag
bool gumbo_lex(struct GumboInternalParser *parser, GumboToken *output)
Definition tokenizer.c:2813
void gumbo_token_destroy(struct GumboInternalParser *parser, GumboToken *token)
Definition tokenizer.c:2870
void gumbo_tokenizer_state_destroy(struct GumboInternalParser *parser)
Definition tokenizer.c:870
void gumbo_tokenizer_state_init(struct GumboInternalParser *parser, const char *text, size_t text_length)
Definition tokenizer.c:846
struct GumboInternalToken GumboToken
void gumbo_tokenizer_set_is_current_node_foreign(struct GumboInternalParser *parser, bool is_foreign)
Definition tokenizer.c:884
void gumbo_tokenizer_set_state(struct GumboInternalParser *parser, GumboTokenizerEnum state)
Definition tokenizer.c:880
struct GumboInternalTokenDocType GumboTokenDocType
GumboTokenizerEnum
Definition tokenizer_states.h:32