ROSE  0.9.10.44
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
Sawyer::Document::Markup::Function Class Referenceabstract

Description

Base class for markup functions.

Definition at line 71 of file DocumentMarkup.h.

#include <DocumentMarkup.h>

Inheritance diagram for Sawyer::Document::Markup::Function:
Inheritance graph
[legend]
Collaboration diagram for Sawyer::Document::Markup::Function:
Collaboration graph
[legend]

Public Types

typedef SharedPointer< FunctionPtr
 Reference-counting pointer to markup function. More...
 

Public Member Functions

const std::string & name () const
 Function name. More...
 
bool isMacro () const
 Whether declaration is for a macro. More...
 
Ptr arg (const std::string &name)
 Declare a required argument. More...
 
Ptr arg (const std::string &name, const std::string &dflt)
 Declare an optional argument. More...
 
Ptr ellipsis (size_t n=(size_t)(-1))
 Declare additional arguments. More...
 
size_t nRequiredArgs () const
 Number of required arguments. More...
 
size_t nOptionalArgs () const
 Number of optional arguments. More...
 
size_t nAdditionalArgs () const
 Max number of additional arguments. More...
 
size_t maxArgs () const
 Max number of actual arguments possible. More...
 
void validateArgs (std::vector< std::string > &actuals, TokenStream &) const
 Check and adjust actual arguments. More...
 
virtual std::string eval (const Grammar &, const std::vector< std::string > &actuals)=0
 How to evaluate this function or macro. More...
 
- Public Member Functions inherited from Sawyer::SharedObject
 SharedObject ()
 Default constructor. More...
 
 SharedObject (const SharedObject &)
 Copy constructor. More...
 
virtual ~SharedObject ()
 Virtual destructor. More...
 
SharedObjectoperator= (const SharedObject &)
 Assignment. More...
 
- Public Member Functions inherited from Sawyer::SharedFromThis< Function >
SharedPointer< FunctionsharedFromThis ()
 Create a shared pointer from this. More...
 
SharedPointer< const FunctionsharedFromThis () const
 Create a shared pointer from this. More...
 

Protected Member Functions

 Function (const std::string &name, bool evalArgs=true)
 

Member Typedef Documentation

Reference-counting pointer to markup function.

Definition at line 74 of file DocumentMarkup.h.

Member Function Documentation

const std::string& Sawyer::Document::Markup::Function::name ( ) const

Function name.

The name does not include the "@" character.

bool Sawyer::Document::Markup::Function::isMacro ( ) const

Whether declaration is for a macro.

A macro differs from a function in only one regard: its arguments are not evaluated before invoking the macro.

Ptr Sawyer::Document::Markup::Function::arg ( const std::string &  name)

Declare a required argument.

Required arguments must come before optional arguments.

Ptr Sawyer::Document::Markup::Function::arg ( const std::string &  name,
const std::string &  dflt 
)

Declare an optional argument.

Optional arguments have a default value that will be passed as the actual argument if that actual argument isn't present at the call site. Optional arguments must come after all required arguments. For example, if a function declares one required argument and one optional argument with the default value "xxx", then if the function is called as "@foo{aaa}{bbb}" then "bbb" is passed as the actual argument, and if called as "@foo{aaa}" with no second argument then "xxx" is passed as the actual argument.

Ptr Sawyer::Document::Markup::Function::ellipsis ( size_t  n = (size_t)(-1))

Declare additional arguments.

A function can take up to n additional arguments. If these arguments are present at the call site then they're passed to the function, otherwise the function's actual argument list is shorter.

size_t Sawyer::Document::Markup::Function::nRequiredArgs ( ) const

Number of required arguments.

size_t Sawyer::Document::Markup::Function::nOptionalArgs ( ) const

Number of optional arguments.

If an optional argument is not present at the call site, then an actual argument is created with the declared default value and passed to the function. Optional arguments are different than "additioanl" arguments.

size_t Sawyer::Document::Markup::Function::nAdditionalArgs ( ) const

Max number of additional arguments.

This is the maximum number of additional arguments which, if present at the call site, are passed to the function and which if not present are not passed. This is different than optional arguments.

size_t Sawyer::Document::Markup::Function::maxArgs ( ) const

Max number of actual arguments possible.

void Sawyer::Document::Markup::Function::validateArgs ( std::vector< std::string > &  actuals,
TokenStream  
) const

Check and adjust actual arguments.

Checks that the actual argument list has enough values to satisfy the functions required arguments, then adds any default values necessary to pad out the optional arguments. Throws an exception if there is not the right number of arguments. The token stream is only for error location information.

virtual std::string Sawyer::Document::Markup::Function::eval ( const Grammar ,
const std::vector< std::string > &  actuals 
)
pure virtual

The documentation for this class was generated from the following file: