]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/ANTLRInputStream.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / ANTLRInputStream.h
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 "CharStream.h"
9
10 namespace antlr4 {
11
12   // Vacuum all input from a stream and then treat it
13   // like a string. Can also pass in a string or char[] to use.
14   // Input is expected to be encoded in UTF-8 and converted to UTF-32 internally.
15   class ANTLR4CPP_PUBLIC ANTLRInputStream : public CharStream {
16   protected:
17     /// The data being scanned.
18     // UTF-32
19     UTF32String _data;
20
21     /// 0..n-1 index into string of next char </summary>
22     size_t p;
23
24   public:
25     /// What is name or source of this char stream?
26     std::string name;
27
28     ANTLRInputStream();
29     
30 #if __cplusplus >= 201703L
31     ANTLRInputStream(const std::string_view &input);
32 #endif
33     
34     ANTLRInputStream(const std::string &input);
35     ANTLRInputStream(const char *data, size_t length);
36     ANTLRInputStream(std::istream &stream);
37
38     virtual void load(const std::string &input);
39     virtual void load(const char *data, size_t length);
40     virtual void load(std::istream &stream);
41
42     /// Reset the stream so that it's in the same state it was
43     /// when the object was created *except* the data array is not
44     /// touched.
45     virtual void reset();
46     virtual void consume() override;
47     virtual size_t LA(ssize_t i) override;
48     virtual size_t LT(ssize_t i);
49
50     /// <summary>
51     /// Return the current input symbol index 0..n where n indicates the
52     ///  last symbol has been read.  The index is the index of char to
53     ///  be returned from LA(1).
54     /// </summary>
55     virtual size_t index() override;
56     virtual size_t size() override;
57
58     /// <summary>
59     /// mark/release do nothing; we have entire buffer </summary>
60     virtual ssize_t mark() override;
61     virtual void release(ssize_t marker) override;
62
63     /// <summary>
64     /// consume() ahead until p==index; can't just set p=index as we must
65     ///  update line and charPositionInLine. If we seek backwards, just set p
66     /// </summary>
67     virtual void seek(size_t index) override;
68     virtual std::string getText(const misc::Interval &interval) override;
69     virtual std::string getSourceName() const override;
70     virtual std::string toString() const override;
71
72   private:
73     void InitializeInstanceFields();
74   };
75
76 } // namespace antlr4