Bond 0.9
C++ Bond Runtime Library API Documentation
Loading...
Searching...
No Matches
Bond::Lexer Class Reference

A lexer for the Bond scripting language. More...

#include <bond/compiler/lexer.h>

Public Member Functions

 Lexer (Allocator &allocator, CompilerErrorBuffer &errorBuffer)
 Constructs a Lexer object. More...
 
 Lexer (const Lexer &other)=delete
 
Lexeroperator= (const Lexer &other)=delete
 
TokenCollectionHandle Lex (const char *fileName, const char *text, size_t length)
 Scans the given string of Bond source and breaks it up into a sequence of Tokens. More...
 
TokenCollectionHandle Lex (const char *fileName, InputStream &stream)
 Scans the given string of Bond source and breaks it up into a sequence of Tokens. More...
 
const CompilerErrorBufferGetErrorBuffer () const
 Returns the buffer where error messages are pushed. More...
 

Detailed Description

A lexer for the Bond scripting language.

The Lexer tokenizes Bond source code passed in as a C-style string. Its output is a TokenCollection that can be used as input to a Parser. A single Lexer can be used to tokenize many strings of Bond source code; each invocation generates a new TokenCollection.

When writing a tool that requires a compiler front end, the interactions between the front end components, namely a Lexer, a Parser and a SemanticAnalyzer, can be managed by a FrontEnd.

See also
CompilerErrorBuffer, FrontEnd, Parser, TokenCollection

Constructor & Destructor Documentation

◆ Lexer() [1/2]

Bond::Lexer::Lexer ( Allocator allocator,
CompilerErrorBuffer errorBuffer 
)
inline

Constructs a Lexer object.

Parameters
allocatorThe memory allocator from which TokenCollections are allocated.
errorBufferBuffer where error messages are pushed when invalid tokens are encountered.

◆ Lexer() [2/2]

Bond::Lexer::Lexer ( const Lexer other)
delete

Member Function Documentation

◆ GetErrorBuffer()

const CompilerErrorBuffer & Bond::Lexer::GetErrorBuffer ( ) const
inline

Returns the buffer where error messages are pushed.

◆ Lex() [1/2]

TokenCollectionHandle Bond::Lexer::Lex ( const char *  fileName,
const char *  text,
size_t  length 
)

Scans the given string of Bond source and breaks it up into a sequence of Tokens.

Parameters
fileNameName to associate with the string of Bond source code, ideally the name of the file from which the code was loaded. The name will be accessible via the generated Tokens, so that other tools, such as a Parser or SemanticAnalyzer can generate meaningful error messages. The name is not copied so the given pointer must remain valid for the lifetime of the generated TokenCollection.
textThe Bond source code text to be tokenized. The tokens contain a copy of the original source code, so the given pointer does not need to remain valid once this function returns.
lengthThe number of characters in the Bond source code. Required since the source code may contain null characters and may not be null terminated.
Returns
A TokenCollectionHandle, which is an owning pointer to a dynamically allocated TokenCollection. The TokenCollection is automatically destroyed when the handle is destroyed.

◆ Lex() [2/2]

TokenCollectionHandle Bond::Lexer::Lex ( const char *  fileName,
InputStream stream 
)

Scans the given string of Bond source and breaks it up into a sequence of Tokens.

Parameters
fileNameName to associate with the string of Bond source code, ideally the name of the file from which the code was loaded. The name will be accessible via the generated Tokens, so that other tools, such as a Parser or SemanticAnalyzer can generate meaningful error messages. The name is not copied so the given pointer must remain valid for the lifetime of the generated TokenCollection.
streamThe stream of Bond source code text to be tokenized.
Returns
A TokenCollectionHandle, which is an owning pointer to a dynamically allocated TokenCollection. The TokenCollection is automatically destroyed when the handle is destroyed.

◆ operator=()

Lexer & Bond::Lexer::operator= ( const Lexer other)
delete

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