Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Concepts
lexer.hpp
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <exception>
27
28#include <ext/istream>
29
30namespace ext {
31
33public:
34 static void putback ( ext::istream & input, const std::string & data );
35
36 static bool test ( ext::istream & input, const std::string & value );
37
38 static void consume ( ext::istream & input, const std::string & value );
39
40 static bool testAndConsume ( ext::istream & input, const std::string & value );
41
42};
43
44template < typename SuperLexer >
45class Lexer : public BasicLexer {
46public:
47 struct Token {
48 typename SuperLexer::TokenType type;
49 std::string value;
50 std::string raw;
51 };
52
53 static Token peek ( ext::istream & input ) {
54 Token token = SuperLexer::next ( input );
55 putback ( input, token );
56 return token;
57 }
58
60
61 static void putback ( ext::istream & input, const Token & token ) {
62 putback ( input, token.raw );
63 }
64
65};
66
67} /* namespace ext */
68
Definition: lexer.hpp:32
static bool test(ext::istream &input, const std::string &value)
Definition: lexer.cpp:22
static void putback(ext::istream &input, const std::string &data)
Definition: lexer.cpp:15
static void consume(ext::istream &input, const std::string &value)
Definition: lexer.cpp:31
static bool testAndConsume(ext::istream &input, const std::string &value)
Definition: lexer.cpp:36
Definition: lexer.hpp:45
static Token peek(ext::istream &input)
Definition: lexer.hpp:53
static void putback(ext::istream &input, const Token &token)
Definition: lexer.hpp:61
Definition: istream.h:32
Definition: sigHandler.cpp:20
Definition: lexer.hpp:47
std::string value
Definition: lexer.hpp:49
SuperLexer::TokenType type
Definition: lexer.hpp:48
std::string raw
Definition: lexer.hpp:50