X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/9f94b672a5dc32da5ad01742bd4e976315a30d9c..c6ad2948bb98d42f8e0883ef82cd14cd2d5eda60:/antlr4-cpp-runtime-4.9.2-source/runtime/src/ListTokenSource.h
diff --git a/antlr4-cpp-runtime-4.9.2-source/runtime/src/ListTokenSource.h b/antlr4-cpp-runtime-4.9.2-source/runtime/src/ListTokenSource.h
new file mode 100644
index 0000000..70cba93
--- /dev/null
+++ b/antlr4-cpp-runtime-4.9.2-source/runtime/src/ListTokenSource.h
@@ -0,0 +1,88 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "TokenSource.h"
+#include "CommonTokenFactory.h"
+
+namespace antlr4 {
+
+ /// Provides an implementation of as a wrapper around a list
+ /// of objects.
+ ///
+ /// If the final token in the list is an token, it will be used
+ /// as the EOF token for every call to after the end of the
+ /// list is reached. Otherwise, an EOF token will be created.
+ class ANTLR4CPP_PUBLIC ListTokenSource : public TokenSource {
+ protected:
+ // This list will be emptied token by token as we call nextToken().
+ // Token streams can be used to buffer tokens for a while.
+ std::vector> tokens;
+
+ private:
+ ///
+ /// The name of the input source. If this value is {@code null}, a call to
+ /// should return the source name used to create the
+ /// the next token in (or the previous token if the end of
+ /// the input has been reached).
+ ///
+ const std::string sourceName;
+
+ protected:
+ /// The index into of token to return by the next call to
+ /// . The end of the input is indicated by this value
+ /// being greater than or equal to the number of items in .
+ size_t i;
+
+ private:
+ /// This is the backing field for and
+ /// .
+ TokenFactory *_factory = CommonTokenFactory::DEFAULT.get();
+
+ public:
+ /// Constructs a new instance from the specified
+ /// collection of objects.
+ ///
+ /// The collection of objects to provide as a
+ /// .
+ /// if {@code tokens} is {@code null}
+ ListTokenSource(std::vector> tokens);
+ ListTokenSource(const ListTokenSource& other) = delete;
+
+ ListTokenSource& operator = (const ListTokenSource& other) = delete;
+
+ ///
+ /// Constructs a new instance from the specified
+ /// collection of objects and source name.
+ ///
+ /// The collection of objects to provide as a
+ /// .
+ /// The name of the . If this value is
+ /// {@code null}, will attempt to infer the name from
+ /// the next (or the previous token if the end of the input has
+ /// been reached).
+ ///
+ /// if {@code tokens} is {@code null}
+ ListTokenSource(std::vector> tokens_, const std::string &sourceName_);
+
+ virtual size_t getCharPositionInLine() override;
+ virtual std::unique_ptr nextToken() override;
+ virtual size_t getLine() const override;
+ virtual CharStream* getInputStream() override;
+ virtual std::string getSourceName() override;
+
+ template
+ void setTokenFactory(TokenFactory *factory) {
+ this->_factory = factory;
+ }
+
+ virtual TokenFactory* getTokenFactory() override;
+
+ private:
+ void InitializeInstanceFields();
+ };
+
+} // namespace antlr4