Current Version: 1.0.10
Project Name: csspp
lexer.h
Go to the documentation of this file.
1 #ifndef CSSPP_LEXER_H
2 #define CSSPP_LEXER_H
3 // CSS Preprocessor
4 // Copyright (C) 2015-2016 Made to Order Software Corp.
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 #include "csspp/node.h"
21 
22 namespace csspp
23 {
24 
25 class lexer
26 {
27 public:
28  typedef std::shared_ptr<lexer> pointer_t;
29 
30  lexer(std::istream & in, position const & pos);
31 
33 
34  wide_char_t mbtowc(char const * mb);
35  void wctomb(wide_char_t const wc, char * mb, size_t max_length);
36  std::string wctomb(wide_char_t const wc);
37 
38  static bool constexpr is_space(wide_char_t c)
39  {
40  // when called '\r' and '\f' were already converted to '\n'
41  return c == ' '
42  || c == '\t'
43  || c == '\n';
44  }
45 
46  static bool constexpr is_non_printable(wide_char_t c)
47  {
48  return c == 0x00
49  || c == 0x08
50  || c == 0x0B
51  || (c >= 0x0E && c <= 0x1F)
52  || c == 0x7F
53  || c == 0xFFFD;
54  }
55 
56  static bool constexpr is_variable(wide_char_t c)
57  {
58  // part of identifier except escape
59  return (c >= '0' && c <= '9')
60  || (c >= 'A' && c <= 'Z')
61  || (c >= 'a' && c <= 'z')
62  || c == '-'
63  || c == '_';
64  }
65 
66  static bool constexpr is_identifier(wide_char_t c)
67  {
68  // part of identifier except escape
69  return (c >= '0' && c <= '9')
70  || (c >= 'A' && c <= 'Z')
71  || (c >= 'a' && c <= 'z')
72  || c == '-'
73  || c == '_'
74  || c >= 0x80;
75  }
76 
77  static bool constexpr is_start_identifier(wide_char_t c)
78  {
79  // start except for the possible escape
80  return (c >= 'A' && c <= 'Z')
81  || (c >= 'a' && c <= 'z')
82  || (c >= 0x80 && c != 0xFFFD)
83  || c == '_';
84  }
85 
86  static bool constexpr is_digit(wide_char_t c)
87  {
88  return c >= '0' && c <= '9';
89  }
90 
91  static bool constexpr is_hex(wide_char_t c)
92  {
93  return (c >= '0' && c <= '9')
94  || (c >= 'A' && c <= 'F')
95  || (c >= 'a' && c <= 'f');
96  }
97 
98  static bool constexpr is_hash_character(wide_char_t c)
99  {
100  return (c >= '0' && c <= '9')
101  || (c >= 'A' && c <= 'Z')
102  || (c >= 'a' && c <= 'z')
103  || c == '-'
104  || c == '_'
105  || (c >= 0x80 && c != 0xFFFD);
106  }
107 
108  static int hex_to_dec(wide_char_t c);
109 
110 private:
111  static size_t const UNGETSIZ = 16;
112 
113  wide_char_t getc();
114  void ungetc(wide_char_t c);
115 
119  std::string string(wide_char_t const quote);
120  node::pointer_t comment(bool c_comment);
124 
125  std::istream & f_in;
129  size_t f_ungetc_pos = 0;
130 };
131 
132 } // namespace csspp
133 #endif
134 // #ifndef CSSPP_LEXER_H
135 
136 // Local Variables:
137 // mode: cpp
138 // indent-tabs-mode: nil
139 // c-basic-offset: 4
140 // tab-width: 4
141 // End:
142 
143 // vim: ts=4 sw=4 et
int32_t wide_char_t
Definition: csspp.h:49
static bool constexpr is_non_printable(wide_char_t c)
Definition: lexer.h:46
static size_t const UNGETSIZ
Definition: lexer.h:111
static bool constexpr is_digit(wide_char_t c)
Definition: lexer.h:86
wide_char_t getc()
Definition: lexer.cpp:618
static bool constexpr is_hex(wide_char_t c)
Definition: lexer.h:91
static bool constexpr is_space(wide_char_t c)
Definition: lexer.h:38
std::shared_ptr< node > pointer_t
Definition: node.h:122
node::pointer_t hash()
Definition: lexer.cpp:1212
wide_char_t escape()
Definition: lexer.cpp:763
node::pointer_t number(wide_char_t c)
Definition: lexer.cpp:1002
static bool constexpr is_hash_character(wide_char_t c)
Definition: lexer.h:98
std::string string(wide_char_t const quote)
Definition: lexer.cpp:1245
position f_position
Definition: lexer.h:126
node::pointer_t next_token()
Definition: lexer.cpp:60
void ungetc(wide_char_t c)
Definition: lexer.cpp:716
node::pointer_t identifier(wide_char_t c)
Definition: lexer.cpp:823
void wctomb(wide_char_t const wc, char *mb, size_t max_length)
Definition: lexer.cpp:548
node::pointer_t variable(wide_char_t c)
Definition: lexer.cpp:1511
static bool constexpr is_variable(wide_char_t c)
Definition: lexer.h:56
std::istream & f_in
Definition: lexer.h:125
static bool constexpr is_start_identifier(wide_char_t c)
Definition: lexer.h:77
wide_char_t mbtowc(char const *mb)
Definition: lexer.cpp:487
std::shared_ptr< lexer > pointer_t
Definition: lexer.h:28
node::pointer_t unicode_range(wide_char_t c)
Definition: lexer.cpp:1423
position f_start_position
Definition: lexer.h:127
static int hex_to_dec(wide_char_t c)
Definition: lexer.cpp:744
lexer(std::istream &in, position const &pos)
Definition: lexer.cpp:53
wide_char_t f_ungetc[UNGETSIZ]
Definition: lexer.h:128
size_t f_ungetc_pos
Definition: lexer.h:129
static bool constexpr is_identifier(wide_char_t c)
Definition: lexer.h:66
node::pointer_t comment(bool c_comment)
Definition: lexer.cpp:1304

Documentation of CSS Preprocessor.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.