Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * This file is part of LibCSS.
  3.  * Licensed under the MIT License,
  4.  *                http://www.opensource.org/licenses/mit-license.php
  5.  * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
  6.  */
  7.  
  8. #ifndef css_lex_lex_h_
  9. #define css_lex_lex_h_
  10.  
  11. #include <libwapcaplet/libwapcaplet.h>
  12.  
  13. #include <libcss/errors.h>
  14. #include <libcss/functypes.h>
  15. #include <libcss/types.h>
  16.  
  17. #include <parserutils/input/inputstream.h>
  18.  
  19. typedef struct css_lexer css_lexer;
  20.  
  21. /**
  22.  * Lexer option types
  23.  */
  24. typedef enum css_lexer_opttype {
  25.         CSS_LEXER_EMIT_COMMENTS
  26. } css_lexer_opttype;
  27.  
  28. /**
  29.  * Lexer option parameters
  30.  */
  31. typedef union css_lexer_optparams {
  32.         bool emit_comments;
  33. } css_lexer_optparams;
  34.  
  35. /**
  36.  * Token type
  37.  */
  38. typedef enum css_token_type {
  39.         CSS_TOKEN_IDENT, CSS_TOKEN_ATKEYWORD, CSS_TOKEN_HASH,
  40.         CSS_TOKEN_FUNCTION, CSS_TOKEN_STRING, CSS_TOKEN_INVALID_STRING,
  41.         CSS_TOKEN_URI, CSS_TOKEN_UNICODE_RANGE, CSS_TOKEN_CHAR,
  42.         CSS_TOKEN_NUMBER, CSS_TOKEN_PERCENTAGE, CSS_TOKEN_DIMENSION,
  43.  
  44.         /* Those tokens that want strings interned appear above */
  45.         CSS_TOKEN_LAST_INTERN,
  46.  
  47.         CSS_TOKEN_CDO, CSS_TOKEN_CDC, CSS_TOKEN_S, CSS_TOKEN_COMMENT,
  48.         CSS_TOKEN_INCLUDES, CSS_TOKEN_DASHMATCH, CSS_TOKEN_PREFIXMATCH,
  49.         CSS_TOKEN_SUFFIXMATCH, CSS_TOKEN_SUBSTRINGMATCH, CSS_TOKEN_EOF
  50. } css_token_type;
  51.  
  52. /**
  53.  * Token object
  54.  */
  55. typedef struct css_token {
  56.         css_token_type type;
  57.  
  58.         struct {
  59.                 uint8_t *data;
  60.                 size_t len;
  61.         } data;
  62.  
  63.         lwc_string *idata;
  64.        
  65.         uint32_t col;
  66.         uint32_t line;
  67. } css_token;
  68.  
  69. css_error css__lexer_create(parserutils_inputstream *input,
  70.                 css_allocator_fn alloc, void *pw, css_lexer **lexer);
  71. css_error css__lexer_destroy(css_lexer *lexer);
  72.  
  73. css_error css__lexer_setopt(css_lexer *lexer, css_lexer_opttype type,
  74.                 css_lexer_optparams *params);
  75.  
  76. css_error css__lexer_get_token(css_lexer *lexer, css_token **token);
  77.  
  78. #endif
  79.  
  80.