/* 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 "Chunk.h"
namespace antlr4 {
namespace tree {
namespace pattern {
///
/// Represents a placeholder tag in a tree pattern. A tag can have any of the
/// following forms.
///
///
/// - {@code expr}: An unlabeled placeholder for a parser rule {@code expr}.
/// - {@code ID}: An unlabeled placeholder for a token of type {@code ID}.
/// - {@code e:expr}: A labeled placeholder for a parser rule {@code expr}.
/// - {@code id:ID}: A labeled placeholder for a token of type {@code ID}.
///
///
/// This class does not perform any validation on the tag or label names aside
/// from ensuring that the tag is a non-null, non-empty string.
///
class ANTLR4CPP_PUBLIC TagChunk : public Chunk {
public:
///
/// Construct a new instance of using the specified tag and
/// no label.
///
/// The tag, which should be the name of a parser rule or token
/// type.
///
/// if {@code tag} is {@code null} or
/// empty.
TagChunk(const std::string &tag);
virtual ~TagChunk();
///
/// Construct a new instance of using the specified label
/// and tag.
///
/// The label for the tag. If this is {@code null}, the
/// represents an unlabeled tag.
/// The tag, which should be the name of a parser rule or token
/// type.
///
/// if {@code tag} is {@code null} or
/// empty.
TagChunk(const std::string &label, const std::string &tag);
///
/// Get the tag for this chunk.
///
/// The tag for the chunk.
std::string getTag();
///
/// Get the label, if any, assigned to this chunk.
///
/// The label assigned to this chunk, or {@code null} if no label is
/// assigned to the chunk.
std::string getLabel();
///
/// This method returns a text representation of the tag chunk. Labeled tags
/// are returned in the form {@code label:tag}, and unlabeled tags are
/// returned as just the tag name.
///
virtual std::string toString() override;
private:
/// This is the backing field for .
const std::string _tag;
///
/// This is the backing field for .
///
const std::string _label;
};
} // namespace pattern
} // namespace tree
} // namespace antlr4