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

Documentation of CSS Preprocessor.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.