/proc/self/cwd/external/antlr4-cpp-runtime~/runtime/src/ANTLRInputStream.h
Line | Count | Source |
1 | | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. |
2 | | * Use of this file is governed by the BSD 3-clause license that |
3 | | * can be found in the LICENSE.txt file in the project root. |
4 | | */ |
5 | | |
6 | | #pragma once |
7 | | |
8 | | #include <string_view> |
9 | | |
10 | | #include "CharStream.h" |
11 | | |
12 | | namespace antlr4 { |
13 | | |
14 | | // Vacuum all input from a stream and then treat it |
15 | | // like a string. Can also pass in a string or char[] to use. |
16 | | // Input is expected to be encoded in UTF-8 and converted to UTF-32 internally. |
17 | | class ANTLR4CPP_PUBLIC ANTLRInputStream : public CharStream { |
18 | | protected: |
19 | | /// The data being scanned. |
20 | | // UTF-32 |
21 | | std::u32string _data; |
22 | | |
23 | | /// 0..n-1 index into string of next char </summary> |
24 | | size_t p; |
25 | | |
26 | | public: |
27 | | /// What is name or source of this char stream? |
28 | | std::string name; |
29 | | |
30 | | ANTLRInputStream(); |
31 | | |
32 | | ANTLRInputStream(std::string_view input); |
33 | | |
34 | | ANTLRInputStream(const char *data, size_t length); |
35 | | ANTLRInputStream(std::istream &stream); |
36 | | |
37 | | virtual void load(const std::string &input, bool lenient); |
38 | | virtual void load(const char *data, size_t length, bool lenient); |
39 | | virtual void load(std::istream &stream, bool lenient); |
40 | | |
41 | 0 | virtual void load(const std::string &input) { load(input, false); } |
42 | 0 | virtual void load(const char *data, size_t length) { load(data, length, false); } |
43 | 0 | virtual void load(std::istream &stream) { load(stream, false); } |
44 | | |
45 | | /// Reset the stream so that it's in the same state it was |
46 | | /// when the object was created *except* the data array is not |
47 | | /// touched. |
48 | | virtual void reset(); |
49 | | virtual void consume() override; |
50 | | virtual size_t LA(ssize_t i) override; |
51 | | virtual size_t LT(ssize_t i); |
52 | | |
53 | | /// <summary> |
54 | | /// Return the current input symbol index 0..n where n indicates the |
55 | | /// last symbol has been read. The index is the index of char to |
56 | | /// be returned from LA(1). |
57 | | /// </summary> |
58 | | virtual size_t index() override; |
59 | | virtual size_t size() override; |
60 | | |
61 | | /// <summary> |
62 | | /// mark/release do nothing; we have entire buffer </summary> |
63 | | virtual ssize_t mark() override; |
64 | | virtual void release(ssize_t marker) override; |
65 | | |
66 | | /// <summary> |
67 | | /// consume() ahead until p==index; can't just set p=index as we must |
68 | | /// update line and charPositionInLine. If we seek backwards, just set p |
69 | | /// </summary> |
70 | | virtual void seek(size_t index) override; |
71 | | virtual std::string getText(const misc::Interval &interval) override; |
72 | | virtual std::string getSourceName() const override; |
73 | | virtual std::string toString() const override; |
74 | | |
75 | | private: |
76 | | void InitializeInstanceFields(); |
77 | | }; |
78 | | |
79 | | } // namespace antlr4 |