root/tlate/scanner.hh

Revision 868b365c127bbf4f0b52f22da03e32a94a4f6653, 3.0 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 3 years ago)

Update the project blurb

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

  • Property mode set to 100644
Line 
1/*  This file is part of Alue, the multiprotocol Internet discussion daemon
2
3    Copyright © 2009 Antti-Juhani Kaijanaho
4
5    Alue is free software: you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    Alue is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with Alue.  If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20#ifndef GUARD_TLATE_SCANNER_HH
21#define GUARD_TLATE_SCANNER_HH
22
23#include <boost/shared_ptr.hpp>
24#include <iostream>
25#include <list>
26
27namespace tlate
28{
29        class scanner
30        {
31        public:
32                enum token { END, INVALID,
33                             LITERAL, ID, OBRACE, CBRACE,
34                             OPAREN, CPAREN, COMMA, PERIOD,
35                             DEF, ELSE, FOR, IF, IN
36                };
37
38                scanner(boost::shared_ptr<std::istream> is, std::string fname);
39                scanner(std::string fname);
40
41                token peek() const;
42                std::string peekValue() const;
43                std::string peekFileName() const;
44                size_t peekLineNo() const;
45                token get();
46
47        private:
48                void setup_include();
49                void next();
50                void next_();
51                bool next_lit();
52                bool next_dir();
53                bool next_eof();
54                bool next_comment();
55                bool do_include();
56
57                std::string include_prefix;
58                std::string fname;
59                size_t lineno;
60                boost::shared_ptr<std::istream> is;
61                enum mode { LIT, DIR } m;
62                token cur;
63                std::string strval;
64
65                struct saved_item {
66                        std::string fname;
67                        size_t lineno;
68                        boost::shared_ptr<std::istream> is;
69                        mode m;
70                        token cur;
71                        std::string strval;
72                };
73                std::list<saved_item> safe;
74
75                void push();
76                void pop();
77        };
78
79        inline scanner::token scanner::peek() const
80        {
81                return cur;
82        }
83
84        inline scanner::token scanner::get()
85        {
86                token rv = cur;
87                next();
88                return rv;
89        }
90
91        inline std::string scanner::peekValue() const
92        {
93                return strval;
94        }
95
96        inline std::string scanner::peekFileName() const
97        {
98                return fname;
99        }
100
101        inline size_t scanner::peekLineNo() const
102        {
103                return lineno;
104        }
105
106}
107
108#endif /* GUARD_TLATE_SCANNER_HH */
Note: See TracBrowser for help on using the browser.