Photon 1.0.0
Loading...
Searching...
No Matches
error.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// Error types, enums, and handling functions.
18
19#ifndef GUMBO_ERROR_H_
20#define GUMBO_ERROR_H_
21#ifdef _MSC_VER
22#define _CRT_SECURE_NO_WARNINGS
23#endif
24#include <stdint.h>
25
26#include "gumbo.h"
27#include "insertion_mode.h"
28#include "string_buffer.h"
29#include "token_type.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
36
81
82// Additional data for duplicated attributes.
84 // The name of the attribute. Owned by this struct.
85 const char* name;
86
87 // The (0-based) index within the attributes vector of the original
88 // occurrence.
89 unsigned int original_index;
90
91 // The (0-based) index where the new occurrence would be.
92 unsigned int new_index;
94
95// A simplified representation of the tokenizer state, designed to be more
96// useful to clients of this library than the internal representation. This
97// condenses the actual states used in the tokenizer state machine into a few
98// values that will be familiar to users of HTML.
115
116// Additional data for tokenizer errors.
117// This records the current state and codepoint encountered - this is usually
118// enough to reconstruct what went wrong and provide a friendly error message.
120 // The bad codepoint encountered.
122
123 // The state that the tokenizer was in at the time.
126
127// Additional data for parse errors.
129 // The type of input token that resulted in this error.
131
132 // The HTML tag of the input token. TAG_UNKNOWN if this was not a tag token.
134
135 // The insertion mode that the parser was in at the time.
137
138 // The tag stack at the point of the error. Note that this is an GumboVector
139 // of GumboTag's *stored by value* - cast the void* to an GumboTag directly to
140 // get at the tag.
141 GumboVector /* GumboTag */ tag_stack;
143
144// The overall error struct representing an error in decoding/tokenizing/parsing
145// the HTML. This contains an enumerated type flag, a source position, and then
146// a union of fields containing data specific to the error.
147typedef struct GumboInternalError {
148 // The type of error.
150
151 // The position within the source file where the error occurred.
153
154 // A pointer to the byte within the original source file text where the error
155 // occurred (note that this is not the same as position.offset, as that gives
156 // character-based instead of byte-based offsets).
157 const char* original_text;
158
159 // Type-specific error information.
160 union {
161 // The code point we encountered, for:
162 // * GUMBO_ERR_UTF8_INVALID
163 // * GUMBO_ERR_UTF8_TRUNCATED
164 // * GUMBO_ERR_NUMERIC_CHAR_REF_WITHOUT_SEMICOLON
165 // * GUMBO_ERR_NUMERIC_CHAR_REF_INVALID
166 uint64_t codepoint;
167
168 // Tokenizer errors.
170
171 // Short textual data, for:
172 // * GUMBO_ERR_NAMED_CHAR_REF_WITHOUT_SEMICOLON
173 // * GUMBO_ERR_NAMED_CHAR_REF_INVALID
175
176 // Duplicate attribute data, for GUMBO_ERR_DUPLICATE_ATTR.
178
179 // Parser state, for GUMBO_ERR_PARSER and
180 // GUMBO_ERR_UNACKNOWLEDGE_SELF_CLOSING_TAG.
182 } v;
184
185// Adds a new error to the parser's error list, and returns a pointer to it so
186// that clients can fill out the rest of its fields. May return NULL if we're
187// already over the max_errors field specified in GumboOptions.
189
190// Initializes the errors vector in the parser.
191void gumbo_init_errors(struct GumboInternalParser* errors);
192
193// Frees all the errors in the 'errors_' field of the parser.
194void gumbo_destroy_errors(struct GumboInternalParser* errors);
195
196// Frees the memory used for a single GumboError.
197void gumbo_error_destroy(struct GumboInternalParser* parser, GumboError* error);
198
199// Prints an error to a string. This fills an empty GumboStringBuffer with a
200// freshly-allocated buffer containing the error message text. The caller is
201// responsible for deleting the buffer. (Note that the buffer is allocated with
202// the allocator specified in the GumboParser config and hence should be freed
203// by gumbo_parser_deallocate().)
205 const GumboError* error, GumboStringBuffer* output);
206
207// Prints a caret diagnostic to a string. This fills an empty GumboStringBuffer
208// with a freshly-allocated buffer containing the error message text. The
209// caller is responsible for deleting the buffer. (Note that the buffer is
210// allocated with the allocator specified in the GumboParser config and hence
211// should be freed by gumbo_parser_deallocate().)
213 const GumboError* error, const char* source_text,
215
216// Like gumbo_caret_diagnostic_to_string, but prints the text to stdout instead
217// of writing to a string.
219 const GumboError* error, const char* source_text);
220
221#ifdef __cplusplus
222}
223#endif
224
225#endif // GUMBO_ERROR_H_
void gumbo_error_destroy(struct GumboInternalParser *parser, GumboError *error)
Definition error.c:267
void gumbo_destroy_errors(struct GumboInternalParser *errors)
Definition error.c:281
GumboError * gumbo_add_error(struct GumboInternalParser *parser)
Definition error.c:164
void gumbo_print_caret_diagnostic(struct GumboInternalParser *parser, const GumboError *error, const char *source_text)
Definition error.c:258
struct GumboInternalError GumboError
struct GumboInternalParserError GumboParserError
struct GumboInternalDuplicateAttrError GumboDuplicateAttrError
GumboErrorType
Definition error.h:37
@ GUMBO_ERR_DOCTYPE_SPACE_OR_RIGHT_BRACKET
Definition error.h:76
@ GUMBO_ERR_COMMENT_END_BANG_EOF
Definition error.h:71
@ GUMBO_ERR_SOLIDUS_EOF
Definition error.h:63
@ GUMBO_ERR_NUMERIC_CHAR_REF_NO_DIGITS
Definition error.h:41
@ GUMBO_ERR_SCRIPT_EOF
Definition error.h:52
@ GUMBO_ERR_NUMERIC_CHAR_REF_WITHOUT_SEMICOLON
Definition error.h:42
@ GUMBO_ERR_UTF8_TRUNCATED
Definition error.h:39
@ GUMBO_ERR_DOCTYPE_SPACE
Definition error.h:74
@ GUMBO_ERR_DUPLICATE_ATTR
Definition error.h:62
@ GUMBO_ERR_NUMERIC_CHAR_REF_INVALID
Definition error.h:43
@ GUMBO_ERR_CLOSE_TAG_INVALID
Definition error.h:51
@ GUMBO_ERR_ATTR_UNQUOTED_EQUALS
Definition error.h:59
@ GUMBO_ERR_COMMENT_BANG_AFTER_DOUBLE_DASH
Definition error.h:68
@ GUMBO_ERR_NAMED_CHAR_REF_WITHOUT_SEMICOLON
Definition error.h:44
@ GUMBO_ERR_DOCTYPE_INVALID
Definition error.h:73
@ GUMBO_ERR_DOCTYPE_END
Definition error.h:77
@ GUMBO_ERR_COMMENT_EOF
Definition error.h:66
@ GUMBO_ERR_UTF8_INVALID
Definition error.h:38
@ GUMBO_ERR_UTF8_NULL
Definition error.h:40
@ GUMBO_ERR_TAG_EOF
Definition error.h:47
@ GUMBO_ERR_ATTR_UNQUOTED_RIGHT_BRACKET
Definition error.h:58
@ GUMBO_ERR_ATTR_AFTER_EOF
Definition error.h:60
@ GUMBO_ERR_COMMENT_DASH_AFTER_DOUBLE_DASH
Definition error.h:69
@ GUMBO_ERR_COMMENT_SPACE_AFTER_DOUBLE_DASH
Definition error.h:70
@ GUMBO_ERR_CLOSE_TAG_EOF
Definition error.h:50
@ GUMBO_ERR_TAG_STARTS_WITH_QUESTION
Definition error.h:46
@ GUMBO_ERR_DOCTYPE_EOF
Definition error.h:72
@ GUMBO_ERR_UNACKNOWLEDGED_SELF_CLOSING_TAG
Definition error.h:79
@ GUMBO_ERR_CLOSE_TAG_EMPTY
Definition error.h:49
@ GUMBO_ERR_TAG_INVALID
Definition error.h:48
@ GUMBO_ERR_COMMENT_INVALID
Definition error.h:67
@ GUMBO_ERR_ATTR_SINGLE_QUOTE_EOF
Definition error.h:56
@ GUMBO_ERR_ATTR_AFTER_INVALID
Definition error.h:61
@ GUMBO_ERR_NAMED_CHAR_REF_INVALID
Definition error.h:45
@ GUMBO_ERR_SOLIDUS_INVALID
Definition error.h:64
@ GUMBO_ERR_ATTR_NAME_EOF
Definition error.h:53
@ GUMBO_ERR_ATTR_UNQUOTED_EOF
Definition error.h:57
@ GUMBO_ERR_ATTR_NAME_INVALID
Definition error.h:54
@ GUMBO_ERR_PARSER
Definition error.h:78
@ GUMBO_ERR_DASHES_OR_DOCTYPE
Definition error.h:65
@ GUMBO_ERR_DOCTYPE_RIGHT_BRACKET
Definition error.h:75
@ GUMBO_ERR_ATTR_DOUBLE_QUOTE_EOF
Definition error.h:55
void gumbo_init_errors(struct GumboInternalParser *errors)
Definition error.c:277
void gumbo_caret_diagnostic_to_string(struct GumboInternalParser *parser, const GumboError *error, const char *source_text, GumboStringBuffer *output)
Definition error.c:235
void gumbo_error_to_string(struct GumboInternalParser *parser, const GumboError *error, GumboStringBuffer *output)
Definition error.c:174
struct GumboInternalTokenizerError GumboTokenizerError
GumboTokenizerErrorState
Definition error.h:99
@ GUMBO_ERR_TOKENIZER_MARKUP_DECLARATION
Definition error.h:110
@ GUMBO_ERR_TOKENIZER_COMMENT
Definition error.h:111
@ GUMBO_ERR_TOKENIZER_ATTR_VALUE
Definition error.h:109
@ GUMBO_ERR_TOKENIZER_DATA
Definition error.h:100
@ GUMBO_ERR_TOKENIZER_RAWTEXT
Definition error.h:103
@ GUMBO_ERR_TOKENIZER_SCRIPT
Definition error.h:105
@ GUMBO_ERR_TOKENIZER_ATTR_NAME
Definition error.h:108
@ GUMBO_ERR_TOKENIZER_CHAR_REF
Definition error.h:101
@ GUMBO_ERR_TOKENIZER_CDATA
Definition error.h:113
@ GUMBO_ERR_TOKENIZER_RCDATA
Definition error.h:102
@ GUMBO_ERR_TOKENIZER_DOCTYPE
Definition error.h:112
@ GUMBO_ERR_TOKENIZER_SELF_CLOSING_TAG
Definition error.h:107
@ GUMBO_ERR_TOKENIZER_PLAINTEXT
Definition error.h:104
@ GUMBO_ERR_TOKENIZER_TAG
Definition error.h:106
GumboTag
Definition gumbo.h:156
GumboInsertionMode
Definition insertion_mode.h:27
Definition error.h:83
unsigned int new_index
Definition error.h:92
const char * name
Definition error.h:85
unsigned int original_index
Definition error.h:89
Definition error.h:147
union GumboInternalError::@16 v
uint64_t codepoint
Definition error.h:166
GumboStringPiece text
Definition error.h:174
const char * original_text
Definition error.h:157
struct GumboInternalParserError parser
Definition error.h:181
GumboSourcePosition position
Definition error.h:152
GumboTokenizerError tokenizer
Definition error.h:169
GumboErrorType type
Definition error.h:149
GumboDuplicateAttrError duplicate_attr
Definition error.h:177
Definition error.h:128
GumboTag input_tag
Definition error.h:133
GumboTokenType input_type
Definition error.h:130
GumboVector tag_stack
Definition error.h:141
GumboInsertionMode parser_state
Definition error.h:136
Definition parser.h:35
Definition error.h:119
GumboTokenizerErrorState state
Definition error.h:124
int codepoint
Definition error.h:121
Definition gumbo.h:67
Definition string_buffer.h:36
Definition gumbo.h:88
Definition gumbo.h:122
annotation output
Definition tag_strings.h:122
GumboTokenType
Definition token_type.h:25