summaryrefslogtreecommitdiff
path: root/src/lex/lex.h
blob: 81a7355f0434964baab6ab8d3040986e63025a46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * This file is part of LibCSS.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
 */

#ifndef css_lex_lex_h_
#define css_lex_lex_h_

#include <libcss/errors.h>
#include <libcss/functypes.h>
#include <libcss/types.h>

#include <parserutils/input/inputstream.h>
#include <parserutils/utils/hash.h>

typedef struct css_lexer css_lexer;

/**
 * Lexer option types
 */
typedef enum css_lexer_opttype {
	CSS_LEXER_EMIT_COMMENTS,
} css_lexer_opttype;

/**
 * Lexer option parameters
 */
typedef union css_lexer_optparams {
	bool emit_comments;
} css_lexer_optparams;

/**
 * Token type
 */
typedef enum css_token_type { 
	CSS_TOKEN_IDENT, CSS_TOKEN_ATKEYWORD, CSS_TOKEN_HASH,
	CSS_TOKEN_FUNCTION, 

	/* Those tokens that want lowercase strings interned appear above */
	CSS_TOKEN_LAST_INTERN_LOWER,

	CSS_TOKEN_STRING, CSS_TOKEN_INVALID_STRING, CSS_TOKEN_URI,
	CSS_TOKEN_UNICODE_RANGE, CSS_TOKEN_CHAR, CSS_TOKEN_NUMBER, 
	CSS_TOKEN_PERCENTAGE, CSS_TOKEN_DIMENSION,

	/* Those tokens that want strings interned appear above */
	CSS_TOKEN_LAST_INTERN,

 	CSS_TOKEN_CDO, CSS_TOKEN_CDC, CSS_TOKEN_S, CSS_TOKEN_COMMENT, 
	CSS_TOKEN_INCLUDES, CSS_TOKEN_DASHMATCH, CSS_TOKEN_PREFIXMATCH, 
	CSS_TOKEN_SUFFIXMATCH, CSS_TOKEN_SUBSTRINGMATCH, CSS_TOKEN_EOF 
} css_token_type;

/**
 * Token object
 */
typedef struct css_token {
	css_token_type type;

	css_string data;

	const parserutils_hash_entry *idata;
	const parserutils_hash_entry *ilower;
	
	uint32_t col;
	uint32_t line;
} css_token;

css_error css_lexer_create(parserutils_inputstream *input, 
		css_alloc alloc, void *pw, css_lexer **lexer);
css_error css_lexer_destroy(css_lexer *lexer);

css_error css_lexer_setopt(css_lexer *lexer, css_lexer_opttype type, 
		css_lexer_optparams *params);

css_error css_lexer_get_token(css_lexer *lexer, css_token **token);

#endif