ROSE 0.11.145.147
|
#include <Rosebud/Ast.h>
Public Types | |
using | Ptr = FilePtr |
Shared-ownership pointer. | |
Public Types inherited from Rosebud::Ast::Node | |
using | Ptr = NodePtr |
Public Types inherited from Sawyer::Tree::Vertex< Node > | |
using | UserBase = Node |
User's base class. | |
using | UserBasePtr = std::shared_ptr< UserBase > |
Pointer to user's base class. | |
using | TraversalEvent = Sawyer::Tree::TraversalEvent |
Alias for traversal events. | |
Public Member Functions | |
std::string | name () |
Name of the input file. | |
TokenStream & | tokenStream () |
Token stream for the file. | |
const Token | token (size_t lookAhead=0) |
Current or future token. | |
bool | matchesAny (size_t tokenPosition, const std::vector< std::string > &) |
Test whether a token matches any text. | |
bool | startsWith (const Token &, const char *) |
Test whether a token starts with a certain string. | |
std::string | content (const std::vector< Token > &, Expand) |
Input string for token list. | |
std::string | content (size_t begin, size_t end) |
Part of file. | |
void | emitContext (std::ostream &, const Token &first, const Token &locus, const Token &last) |
Emit the context for a diagnostic message. | |
std::string | lexeme (size_t position=0) |
Text associated with a token. | |
std::string | lexeme (const Token &) |
Text associated with a token. | |
bool | matches (const Token &, const char *) |
Test whether a token matches a string. | |
bool | matches (const Token &, const std::string &) |
Test whether a token matches a string. | |
bool | matches (size_t lookAhead, const char *) |
Test whether a token matches a string. | |
bool | matches (size_t lookAhead, const std::string &) |
Test whether a token matches a string. | |
bool | matches (const char *) |
Test whether a token matches a string. | |
bool | matches (const std::string &) |
Test whether a token matches a string. | |
Token | consume () |
Consume tokens. | |
void | consume (size_t n) |
Consume tokens. | |
std::string | trimmedContent (size_t begin, size_t end, Token &outputToken) |
Input string for file region. | |
std::string | trimmedContent (size_t begin, size_t end, const Token &exclude, Token &outputToken) |
Input string for file region. | |
Public Member Functions inherited from Rosebud::Ast::Node | |
template<class T > | |
std::shared_ptr< T > | findAncestor () |
Public Member Functions inherited from Sawyer::Tree::Vertex< Node > | |
UserBasePtr | pointer () |
Returns a shared pointer to this vertex. | |
std::shared_ptr< T > | isa () |
Tests whether this object is a certain type. | |
auto | traverseReverse (const Visitor &visitor) |
Traverse in reverse direction from children to parents. | |
auto | traverse (const Visitor &visitor) |
Traverse in forward direction from parents to children. | |
auto | traversePre (const Visitor &visitor) |
Pre-order forward traversal. | |
auto | traversePost (const Visitor &visitor) |
Post-order forward traversal. | |
std::shared_ptr< T > | findFirstAncestor () |
Traversal that finds the closest ancestor of type T or derived from T. | |
std::shared_ptr< T > | findLastAncestor () |
Traversal that finds the farthest ancestor of type T or derived from T. | |
std::vector< std::shared_ptr< T > > | findDescendants () |
Traversal that finds all the descendants of a particular type. | |
UserBasePtr | child (size_t i) const |
Returns the pointer for a child. | |
size_t | nChildren () const |
Returns the number of children. | |
Static Public Member Functions | |
static Ptr | instance (const std::string &name) |
Allocating constructor. | |
Public Attributes | |
EdgeVector< Class > | classes |
Non-null list of zero or more class definitions. | |
std::string | endText |
Text after the last class definition until the end of the file. | |
Token | endTextToken |
Token that encloses endText. | |
Public Attributes inherited from Sawyer::Tree::Vertex< Node > | |
ReverseEdge | parent |
Pointer to the parent in the tree. | |
Protected Member Functions | |
File (const std::string &name) | |
Constructor used only by derived classes. | |
Protected Member Functions inherited from Sawyer::Tree::Vertex< Node > | |
virtual void | destructorHelper () |
using Rosebud::Ast::File::Ptr = FilePtr |
|
static |
Allocating constructor.
The specified name must be the name of an existing text file that can be opened for reading.
TokenStream & Rosebud::Ast::File::tokenStream | ( | ) |
Token stream for the file.
These tokens are consumed by parsing, but the stream itself is left here as a data member because it still contains useful information such as the file name, the content of the file as text by which tokens can be converted to strings, and information about line and column numbers.
const Token Rosebud::Ast::File::token | ( | size_t | lookAhead = 0 | ) |
Current or future token.
Returns the current token, or one of the future tokens.
std::string Rosebud::Ast::File::lexeme | ( | size_t | position = 0 | ) |
Text associated with a token.
Returns the input text that caused the current or future token.
Attention: when testing whether a token matches some string, use one of the matching functions if possible instead of obtaining a string and comparing it to another string. The matching functions are more efficient.
std::string Rosebud::Ast::File::lexeme | ( | const Token & | ) |
Text associated with a token.
Returns the input text that caused the current or future token.
Attention: when testing whether a token matches some string, use one of the matching functions if possible instead of obtaining a string and comparing it to another string. The matching functions are more efficient.
bool Rosebud::Ast::File::matches | ( | const Token & | , |
const char * | |||
) |
Test whether a token matches a string.
Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead
> 1), or the current token (no argument, or lookAhead
== 0).
bool Rosebud::Ast::File::matches | ( | const Token & | , |
const std::string & | |||
) |
Test whether a token matches a string.
Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead
> 1), or the current token (no argument, or lookAhead
== 0).
bool Rosebud::Ast::File::matches | ( | size_t | lookAhead, |
const char * | |||
) |
Test whether a token matches a string.
Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead
> 1), or the current token (no argument, or lookAhead
== 0).
bool Rosebud::Ast::File::matches | ( | size_t | lookAhead, |
const std::string & | |||
) |
Test whether a token matches a string.
Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead
> 1), or the current token (no argument, or lookAhead
== 0).
bool Rosebud::Ast::File::matches | ( | const char * | ) |
Test whether a token matches a string.
Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead
> 1), or the current token (no argument, or lookAhead
== 0).
bool Rosebud::Ast::File::matches | ( | const std::string & | ) |
Test whether a token matches a string.
Returns true if the specified token matches a string. A token can be passed as an argument, or specified as a future token (lookAhead
> 1), or the current token (no argument, or lookAhead
== 0).
bool Rosebud::Ast::File::matchesAny | ( | size_t | tokenPosition, |
const std::vector< std::string > & | |||
) |
Test whether a token matches any text.
Returns true if the specified token matches any of the supplied strings.
bool Rosebud::Ast::File::startsWith | ( | const Token & | , |
const char * | |||
) |
Test whether a token starts with a certain string.
Returns true if the specified token begins with the specified characters.
Token Rosebud::Ast::File::consume | ( | ) |
Consume tokens.
Consume the current token, or n
tokens. This is used during parsing, so by time a backend code generator is called all the tokens have presumably been consumed and the stream is sitting at the special EOF token. Consuming the EOF token is permissible, but has no effect.
void Rosebud::Ast::File::consume | ( | size_t | n | ) |
Consume tokens.
Consume the current token, or n
tokens. This is used during parsing, so by time a backend code generator is called all the tokens have presumably been consumed and the stream is sitting at the special EOF token. Consuming the EOF token is permissible, but has no effect.
Input string for token list.
Returns a string for the specified tokens by concatenating the strings for the individual tokens. Depending on the second argument, the returned string includes either just the token text, the text between the start of the first token and the end of the last token, or the same plus the non-token text before the first token.
std::string Rosebud::Ast::File::content | ( | size_t | begin, |
size_t | end | ||
) |
Part of file.
Returns some text from the file from the starting byte offset (inclusive) to the ending byte offset (exclusive).
std::string Rosebud::Ast::File::trimmedContent | ( | size_t | begin, |
size_t | end, | ||
Token & | outputToken | ||
) |
Input string for file region.
Returns the content of the file from character position begin
(inclusive) to end
(exclusive). If the end
is less than or equal to begin
, then an empty string is returned. The text is modified by removing trailing white space from each line, replacing consecutive blank lines with a single blank line, and removing leading and trailing blank lines. If an exclude
token is specified, then its text is not included in the returned string.
std::string Rosebud::Ast::File::trimmedContent | ( | size_t | begin, |
size_t | end, | ||
const Token & | exclude, | ||
Token & | outputToken | ||
) |
Input string for file region.
Returns the content of the file from character position begin
(inclusive) to end
(exclusive). If the end
is less than or equal to begin
, then an empty string is returned. The text is modified by removing trailing white space from each line, replacing consecutive blank lines with a single blank line, and removing leading and trailing blank lines. If an exclude
token is specified, then its text is not included in the returned string.
void Rosebud::Ast::File::emitContext | ( | std::ostream & | , |
const Token & | first, | ||
const Token & | locus, | ||
const Token & | last | ||
) |
Emit the context for a diagnostic message.
The input lines corresponding to the tokens are emitted to standard error. The part of that input corresponding to the tokens is marked by underlining it, and the start of the locus
token is marked in a special way.
EdgeVector<Class> Rosebud::Ast::File::classes |
std::string Rosebud::Ast::File::endText |
Token Rosebud::Ast::File::endTextToken |