ELinks 0.18.0
scanner.h File Reference
#include "dom/string.h"
#include "util/error.h"
Include dependency graph for scanner.h:
This graph shows which files directly or indirectly include this file:

Data Structures

struct  dom_scanner_token
 DOM scanner token. More...
 
struct  dom_scan_table_info
 
struct  dom_scanner_string_mapping
 
struct  dom_scanner_info
 DOM scanner info. More...
 
struct  dom_scanner
 DOM scanner. More...
 

Macros

#define skip_dom_scanner_token_char(token)    do { (token)->string.string++; (token)->string.length--; } while (0)
 Skip the first charector of a token.
 
#define dom_scanner_token_contains(token, str)
 Compare the token string to a "static" string.
 
#define DOM_SCAN_TABLE_SIZE   256
 
#define DOM_SCAN_TABLE_INFO(type, data1, data2, bits)    { (type), INIT_DOM_STRING((data1), (data2)), (bits) }
 
#define DOM_SCAN_TABLE_RANGE(from, to, bits)    DOM_SCAN_TABLE_INFO(DOM_SCAN_RANGE, from, to, bits)
 
#define DOM_SCAN_TABLE_STRING(str, bits)    DOM_SCAN_TABLE_INFO(DOM_SCAN_STRING, str, sizeof(str) - 1, bits)
 
#define DOM_SCAN_TABLE_END    DOM_SCAN_TABLE_INFO(DOM_SCAN_END, NULL, 0, 0)
 
#define DOM_STRING_MAP(str, type, family)    { STATIC_DOM_STRING(str), (type), (family) }
 
#define DOM_STRING_MAP_END    { INIT_DOM_STRING(NULL, 0), 0, 0 }
 
#define DOM_SCANNER_TOKENS   10
 The number of tokens in the scanners token table.
 
#define dom_scanner_has_tokens(scanner)    ((scanner)->tokens > 0 && (scanner)->current < (scanner)->table + (scanner)->tokens)
 Check if there are more tokens.
 
#define check_dom_scanner(scanner)
 
#define check_next_dom_scanner_token(scanner, token_type)
 Check the type of the next token.
 
#define skip_dom_scanner_token(scanner)   get_next_dom_scanner_token(scanner)
 Skip the current token.
 

Enumerations

enum  dom_scan_type { DOM_SCAN_RANGE , DOM_SCAN_STRING , DOM_SCAN_END }
 

Functions

void init_dom_scanner (struct dom_scanner *scanner, struct dom_scanner_info *scanner_info, struct dom_string *string, int state, int count_lines, int complete, int check_complete, int detect_error)
 Initializes a DOM scanner.
 
static struct dom_scanner_tokenget_dom_scanner_token (struct dom_scanner *scanner)
 Get the current token.
 
static struct dom_scanner_tokenget_next_dom_scanner_token (struct dom_scanner *scanner)
 Get the next token.
 
struct dom_scanner_tokenskip_dom_scanner_tokens (struct dom_scanner *scanner, int skipto, int precedence)
 Conditionally skip tokens.
 
int map_dom_scanner_string (struct dom_scanner *scanner, char *ident, char *end, int base_type)
 Map a string to internal ID.
 
static struct dom_scanner_tokenbegin_dom_token_scanning (struct dom_scanner *scanner)
 
static struct dom_scanner_tokenend_dom_token_scanning (struct dom_scanner *scanner, struct dom_scanner_token *end)
 

Macro Definition Documentation

◆ check_dom_scanner

#define check_dom_scanner ( scanner)
Value:
#define DOM_SCANNER_TOKENS
The number of tokens in the scanners token table.
Definition scanner.h:121
The struct scanner describes the current state of the scanner.
Definition scanner.h:107
int tokens
Definition scanner.h:117
struct scanner_token * current
The current token and number of scanned tokens in the table.
Definition scanner.h:116
struct scanner_token table[SCANNER_TOKENS]
The table contain already scanned tokens.
Definition scanner.h:137

◆ check_next_dom_scanner_token

#define check_next_dom_scanner_token ( scanner,
token_type )
Value:
(scanner_has_tokens(scanner) \
&& ((scanner)->current + 1 < (scanner)->table + (scanner)->tokens) \
&& (scanner)->current[1].type == (token_type))
const char * type
Definition download.c:1899

Check the type of the next token.

◆ DOM_SCAN_TABLE_END

#define DOM_SCAN_TABLE_END    DOM_SCAN_TABLE_INFO(DOM_SCAN_END, NULL, 0, 0)

◆ DOM_SCAN_TABLE_INFO

#define DOM_SCAN_TABLE_INFO ( type,
data1,
data2,
bits )    { (type), INIT_DOM_STRING((data1), (data2)), (bits) }

◆ DOM_SCAN_TABLE_RANGE

#define DOM_SCAN_TABLE_RANGE ( from,
to,
bits )    DOM_SCAN_TABLE_INFO(DOM_SCAN_RANGE, from, to, bits)

◆ DOM_SCAN_TABLE_SIZE

#define DOM_SCAN_TABLE_SIZE   256

◆ DOM_SCAN_TABLE_STRING

#define DOM_SCAN_TABLE_STRING ( str,
bits )    DOM_SCAN_TABLE_INFO(DOM_SCAN_STRING, str, sizeof(str) - 1, bits)

◆ dom_scanner_has_tokens

#define dom_scanner_has_tokens ( scanner)     ((scanner)->tokens > 0 && (scanner)->current < (scanner)->table + (scanner)->tokens)

Check if there are more tokens.

◆ dom_scanner_token_contains

#define dom_scanner_token_contains ( token,
str )
Value:
((token)->string.length == (sizeof(str) - 1) \
&& !c_strncasecmp((token)->string.string, str, sizeof(str) - 1))
int c_strncasecmp(const char *s1, const char *s2, size_t n)
Definition string.c:279

Compare the token string to a "static" string.

◆ DOM_SCANNER_TOKENS

#define DOM_SCANNER_TOKENS   10

The number of tokens in the scanners token table.

At best it should be big enough to contain properties with space separated values and function calls with up to 3 variables like rgb(). At worst it should be no less than 2 in order to be able to peek at the next token in the scanner.

◆ DOM_STRING_MAP

#define DOM_STRING_MAP ( str,
type,
family )    { STATIC_DOM_STRING(str), (type), (family) }

◆ DOM_STRING_MAP_END

#define DOM_STRING_MAP_END    { INIT_DOM_STRING(NULL, 0), 0, 0 }

◆ skip_dom_scanner_token

#define skip_dom_scanner_token ( scanner)    get_next_dom_scanner_token(scanner)

Skip the current token.

◆ skip_dom_scanner_token_char

#define skip_dom_scanner_token_char ( token)     do { (token)->string.string++; (token)->string.length--; } while (0)

Skip the first charector of a token.

Enumeration Type Documentation

◆ dom_scan_type

Enumerator
DOM_SCAN_RANGE 
DOM_SCAN_STRING 
DOM_SCAN_END 

Function Documentation

◆ begin_dom_token_scanning()

static struct dom_scanner_token * begin_dom_token_scanning ( struct dom_scanner * scanner)
inlinestatic

◆ end_dom_token_scanning()

static struct dom_scanner_token * end_dom_token_scanning ( struct dom_scanner * scanner,
struct dom_scanner_token * end )
inlinestatic

◆ get_dom_scanner_token()

static struct dom_scanner_token * get_dom_scanner_token ( struct dom_scanner * scanner)
inlinestatic

Get the current token.

◆ get_next_dom_scanner_token()

static struct dom_scanner_token * get_next_dom_scanner_token ( struct dom_scanner * scanner)
inlinestatic

Get the next token.

Getting the next token might cause a rescan so any token pointers that has been stored in a local variable might not be valid after the call.

◆ init_dom_scanner()

void init_dom_scanner ( struct dom_scanner * scanner,
struct dom_scanner_info * scanner_info,
struct dom_string * string,
int state,
int count_lines,
int complete,
int check_complete,
int detect_error )

Initializes a DOM scanner.

See struct dom_scanner for a description of the int flags.

◆ map_dom_scanner_string()

int map_dom_scanner_string ( struct dom_scanner * scanner,
char * ident,
char * end,
int base_type )

Map a string to internal ID.

Looks up the string from ident to end to in the scanners string mapping table.

◆ skip_dom_scanner_tokens()

struct dom_scanner_token * skip_dom_scanner_tokens ( struct dom_scanner * scanner,
int skipto,
int precedence )

Conditionally skip tokens.

Removes tokens from the scanner until it meets a token of the given type. This token will then also be skipped.