libcss
Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions
lex.c File Reference
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <parserutils/charset/utf8.h>
#include <parserutils/input/inputstream.h>
#include <parserutils/utils/buffer.h>
#include <libcss/errors.h>
#include "lex/lex.h"
#include "utils/parserutilserror.h"
#include "utils/utils.h"

Classes

struct  css_lexer
 

Macros

#define APPEND(lexer, data, len)
 

Enumerations

enum  {
  sSTART = 0 , sATKEYWORD = 1 , sSTRING = 2 , sHASH = 3 ,
  sNUMBER = 4 , sCDO = 5 , sCDC = 6 , sS = 7 ,
  sCOMMENT = 8 , sMATCH = 9 , sURI = 10 , sIDENT = 11 ,
  sESCAPEDIDENT = 12 , sURL = 13 , sUCR = 14
}
 

Functions

css_error css__lexer_create (parserutils_inputstream *input, 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)
 

Macro Definition Documentation

◆ APPEND

#define APPEND (   lexer,
  data,
  len 
)
Value:
do { \
css_error error; \
error = appendToTokenData((lexer), \
(const uint8_t *) (data), (len)); \
if (error != CSS_OK) \
return error; \
(lexer)->bytesReadForToken += (len); \
(lexer)->currentCol += (len); \
} while(0) \
css_error
Definition errors.h:18
@ CSS_OK
Definition errors.h:19

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Todo:
Optimisation – we're currently revisiting a bunch of input characters (Currently, we're calling parserutils_inputstream_peek about 1.5x the number of characters in the input stream). Ideally, we'll visit each character in the input exactly once. In reality, the upper bound is twice, due to the need, in some cases, to read one character beyond the end of a token's input to detect the end of the token. Resumability adds a little overhead here, unless we're somewhat more clever when it comes to having support for restarting mid-escape sequence. Currently, we rewind back to the start of the sequence and process the whole thing again.
Enumerator
sSTART 
sATKEYWORD 
sSTRING 
sHASH 
sNUMBER 
sCDO 
sCDC 
sS 
sCOMMENT 
sMATCH 
sURI 
sIDENT 
sESCAPEDIDENT 
sURL 
sUCR 

Function Documentation

◆ css__lexer_create()

css_error css__lexer_create ( parserutils_inputstream *  input,
css_lexer **  lexer 
)

Create a lexer instance

Parameters
inputThe inputstream to read from
lexerPointer to location to receive lexer instance
Returns
CSS_OK on success, CSS_BADPARM on bad parameters, CSS_NOMEM on memory exhaustion

◆ css__lexer_destroy()

css_error css__lexer_destroy ( css_lexer lexer)

Destroy a lexer instance

Parameters
lexerThe instance to destroy
Returns
CSS_OK on success, appropriate error otherwise

◆ css__lexer_get_token()

css_error css__lexer_get_token ( css_lexer lexer,
css_token **  token 
)

Retrieve a token from a lexer

Parameters
lexerThe lexer instance to read from
tokenPointer to location to receive pointer to token
Returns
CSS_OK on success, appropriate error otherwise

The returned token object is owned by the lexer. However, the client is permitted to modify the data members of the token. The token must not be freed by the client (it may not have been allocated in the first place), nor may any of the pointers contained within it. The client may, if they wish, overwrite any data member of the returned token object – the lexer does not depend on these remaining constant. This allows the client code to efficiently implement a push-back buffer with interned string data.

◆ css__lexer_setopt()

css_error css__lexer_setopt ( css_lexer lexer,
css_lexer_opttype  type,
css_lexer_optparams params 
)

Configure a lexer instance

Parameters
lexerThe lexer to configure
typeThe option type to modify
paramsOption-specific parameters
Returns
CSS_OK on success, appropriate error otherwise