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.
8 #include "CharStream.h"
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 {
17 /// The data being scanned.
21 /// 0..n-1 index into string of next char </summary>
25 /// What is name or source of this char stream?
30 #if __cplusplus >= 201703L
31 ANTLRInputStream(const std::string_view &input);
34 ANTLRInputStream(const std::string &input);
35 ANTLRInputStream(const char *data, size_t length);
36 ANTLRInputStream(std::istream &stream);
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);
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
46 virtual void consume() override;
47 virtual size_t LA(ssize_t i) override;
48 virtual size_t LT(ssize_t i);
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).
55 virtual size_t index() override;
56 virtual size_t size() override;
59 /// mark/release do nothing; we have entire buffer </summary>
60 virtual ssize_t mark() override;
61 virtual void release(ssize_t marker) override;
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
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;
73 void InitializeInstanceFields();