|  | reflex::AbstractLexer< M > Class Template Reference updated Sun May 12 2024 by Robert van Engelen |

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Classes | Public Member Functions | Protected Attributes | List of all members
reflex::AbstractLexer< M > Class Template Reference

The abstract lexer class template that is the abstract root class of all reflex-generated scanners. More...

`#include <abslexer.h>`

Inheritance diagram for reflex::AbstractLexer< M >:
[legend]
Collaboration diagram for reflex::AbstractLexer< M >:
[legend]

## Classes
class | Matcher
| Extend matcher class M with a member pointing to the instantiating lexer class. More...

## Public Member Functions
| AbstractLexer (const Input &input, std::ostream &os)
| Construct abstract lexer to scan an input character sequence and echo the text matches to output. More...
virtual | ~AbstractLexer ()
| Delete lexer and its current matcher with its associated input. More...
virtual void | set_debug (int flag)
| Set debug flag value. More...
virtual int | debug () const
| Get debug flag value. More...
void | perf_report ()
| Dummy performance reporter, to prevent link errors when reflex option -p is omitted. More...
virtual int | wrap ()
| The default wrap operation at EOF: do not wrap input. More...
template<typename I >
AbstractLexer & | in (const I &input)
| Reset the matcher and start scanning from the given input character sequence I. More...
AbstractLexer & | in (const char *b, size_t n)
| Reset the matcher and start scanning from the given byte sequence. More...
Input & | in ()
| Returns the current input character sequence that is being scanned. More...
Input & | stdinit ()
| Returns the current input character sequence that is being scanned, if none assign stdin. More...
Input & | nostdinit ()
| Returns the current input character sequence that is being scanned, if none assign std::cin. More...
AbstractLexer & | buffer (char *base, size_t size)
| Reset the matcher and start scanning the given buffer containing 0-terminated character data (data may be modified). More...
AbstractLexer & | out (std::ostream &os)
| Set the current output to the given output stream to echo text matches to. More...
std::ostream & | out () const
| Returns the current output stream used to echo text matches to. More...
std::ostream *& | os ()
| Returns pointer to the current output stream used to echo text matches to. More...
bool | has_matcher () const
| Returns true if a matcher was assigned to this lexer for scanning. More...
AbstractLexer & | matcher (Matcher *matcher)
| Set the matcher (and its current state) for scanning. More...
Matcher & | matcher () const
| Returns a reference to the current matcher. More...
Matcher * | ptr_matcher () const
| Returns a pointer to the current matcher, NULL if none was set. More...
virtual Matcher * | new_matcher (const Input &input=Input(), const char *opt=NULL)
| Returns a new copy of the matcher for the given input. More...
void | del_matcher (Matcher *matcher)
| Delete a matcher. More...
void | push_matcher (Matcher *matcher)
| Push the current matcher on the stack and use the given matcher for scanning. More...
bool | pop_matcher ()
| Pop matcher from the stack and continue scanning where it left off, delete the current matcher. More...
void | echo () const
| Echo the matched text to the current output. More...
const char * | text () const
| Returns string with the text matched. More...
std::string | str () const
| Returns string with a copy of the text matched. More...
std::wstring | wstr () const
| Returns wide string with a copy of the text matched. More...
int | chr () const
| Returns the first 8-bit character of the text matched. More...
int | wchr () const
| Returns the first wide character of the text matched. More...
size_t | size () const
| Returns the matched text size in number of bytes. More...
size_t | wsize () const
| Returns the matched text size in number of (wide) characters. More...
size_t | lineno () const
| Returns the line number of matched text. More...
void | lineno (size_t n)
| Set or change the starting line number of the last match. More...
size_t | lines () const
| Returns the number of lines that the match spans. More...
size_t | lineno_end () const
| Returns the ending line number of matched text. More...
size_t | columno () const
| Returns the starting column number of matched text, taking tab spacing into account and counting wide characters as one character each. More...
size_t | columns () const
| Returns the number of columns of the last line (or the single line of matched text) in the matched text, taking tab spacing into account and counting wide characters as one character each. More...
size_t | columno_end () const
| Returns the ending column number of matched text, taking tab spacing into account and counting wide characters as one character each. More...
AbstractLexer & | start (int state)
| Transition to the given start condition state. More...
int | start () const
| Returns the current start condition state. More...
void | push_state (int state)
| Push the current start condition state on the stack and transition to the given start condition state. More...
void | pop_state ()
| Pop the stack start condition state and transition to that state. More...
int | top_state () const
| Returns the stack top start condition state or 0 (INITIAL) if the stack is empty. More...
bool | states_empty () const
| Returns true if the condition state stack is empty. More...
virtual void | lexer_error (const char *message=NULL)
| Lexer exceptions. More...

## Protected Attributes
Input | in_
| the input character sequence to scan More...
std::ostream * | os_
| the output stream to echo text matches to More...
char * | base_
| the buffer to scan in place, if non-NULL More...
size_t | size_
| the size of the buffer to scan in place, if nonzero More...
Matcher * | matcher_
| the matcher used for scanning More...
int | start_
| the current start condition state More...
int | debug_
| 1 if -d (–debug) 0 otherwise: More...
std::stack< Matcher * > | stack_
| a stack of pointers to matchers More...
std::stack< int > | state_
| a stack of start condition states More...

## Detailed Description

### template<typename M>
class reflex::AbstractLexer< M >

The abstract lexer class template that is the abstract root class of all reflex-generated scanners.

Template Parameters

  <M> | matcher class derived from reflex::AbstractMatcher

## Constructor & Destructor Documentation

template<typename M >

reflex::AbstractLexer< M >::AbstractLexer | ( | const Input & | input,
|  | std::ostream & | os
| ) |  |
| inline

Construct abstract lexer to scan an input character sequence and echo the text matches to output.

Parameters

  input | reflex::Input character sequence to read from
  os | echo the text matches to this std::ostream or to std::cout

template<typename M >

virtual reflex::AbstractLexer< M >::~AbstractLexer | ( |  | ) |
| inline virtual

Delete lexer and its current matcher with its associated input.

## Member Function Documentation

template<typename M >

AbstractLexer& reflex::AbstractLexer< M >::buffer | ( | char * | base,
|  | size_t | size
| ) |  |
| inline

Reset the matcher and start scanning the given buffer containing 0-terminated character data (data may be modified).

Returns
  reference to *this

Parameters

  base | base of the buffer containing 0-terminated character data
  size | nonzero size of the buffer

template<typename M >

int reflex::AbstractLexer< M >::chr | ( |  | ) | const
| inline

Returns the first 8-bit character of the text matched.

Returns
  8-bit char

template<typename M >

size_t reflex::AbstractLexer< M >::columno | ( |  | ) | const
| inline

Returns the starting column number of matched text, taking tab spacing into account and counting wide characters as one character each.

Returns
  column number

template<typename M >

size_t reflex::AbstractLexer< M >::columno_end | ( |  | ) | const
| inline

Returns the ending column number of matched text, taking tab spacing into account and counting wide characters as one character each.

Returns
  column number

template<typename M >

size_t reflex::AbstractLexer< M >::columns | ( |  | ) | const
| inline

Returns the number of columns of the last line (or the single line of matched text) in the matched text, taking tab spacing into account and counting wide characters as one character each.

Returns
  number of columns

template<typename M >

virtual int reflex::AbstractLexer< M >::debug | ( |  | ) | const
| inline virtual

Get debug flag value.

Returns
  debug flag value

template<typename M >

void reflex::AbstractLexer< M >::del_matcher | ( | Matcher * | matcher | ) |
| inline

Delete a matcher.

template<typename M >

void reflex::AbstractLexer< M >::echo | ( |  | ) | const
| inline

Echo the matched text to the current output.

template<typename M >

bool reflex::AbstractLexer< M >::has_matcher | ( |  | ) | const
| inline

Returns true if a matcher was assigned to this lexer for scanning.

Returns
  true if a matcher was assigned

template<typename M >
template<typename I >

AbstractLexer& reflex::AbstractLexer< M >::in | ( | const I & | input | ) |
| inline

Reset the matcher and start scanning from the given input character sequence I.

Returns
  reference to *this

Parameters

  input | a character sequence to scan, e.g. reflex::Input, char*, wchar_t*, std::string, std::wstring, FILE*, std::istream

template<typename M >

AbstractLexer& reflex::AbstractLexer< M >::in | ( | const char * | b,
|  | size_t | n
| ) |  |
| inline

Reset the matcher and start scanning from the given byte sequence.

Returns
  reference to *this

Parameters

  b | the byte sequence to scan
  n | length of the byte sequence to scan

template<typename M >

Input& reflex::AbstractLexer< M >::in | ( |  | ) |
| inline

Returns the current input character sequence that is being scanned.

Returns
  reference to the current reflex::Input object

template<typename M >

virtual void reflex::AbstractLexer< M >::lexer_error | ( | const char * | message = `NULL` | ) |
| inline virtual

Lexer exceptions.

template<typename M >

size_t reflex::AbstractLexer< M >::lineno | ( |  | ) | const
| inline

Returns the line number of matched text.

Returns
  line number

template<typename M >

void reflex::AbstractLexer< M >::lineno | ( | size_t | n | ) |
| inline

Set or change the starting line number of the last match.

template<typename M >

size_t reflex::AbstractLexer< M >::lineno_end | ( |  | ) | const
| inline

Returns the ending line number of matched text.

Returns
  line number

template<typename M >

size_t reflex::AbstractLexer< M >::lines | ( |  | ) | const
| inline

Returns the number of lines that the match spans.

Returns
  number of lines

template<typename M >

AbstractLexer& reflex::AbstractLexer< M >::matcher | ( | Matcher * | matcher | ) |
| inline

Set the matcher (and its current state) for scanning.

Returns
  reference to *this

Parameters

  matcher | points to a matcher object

template<typename M >

Matcher& reflex::AbstractLexer< M >::matcher | ( |  | ) | const
| inline

Returns a reference to the current matcher.

Returns
  reference to the current matcher

template<typename M >

virtual Matcher* reflex::AbstractLexer< M >::new_matcher | ( | const Input & | input = `Input()`,
|  | const char * | opt = `NULL`
| ) |  |
| inline virtual

Returns a new copy of the matcher for the given input.

Returns
  pointer to new reflex::AbstractLexer::Matcher

Parameters

  input | reflex::Input character sequence to match
  opt | options, if any

template<typename M >

Input& reflex::AbstractLexer< M >::nostdinit | ( |  | ) |
| inline

Returns the current input character sequence that is being scanned, if none assign std::cin.

Returns
  reference to the current reflex::Input object with input assigned

template<typename M >

std::ostream*& reflex::AbstractLexer< M >::os | ( |  | ) |
| inline

Returns pointer to the current output stream used to echo text matches to.

Returns
  pointer to the current std::ostream object

template<typename M >

AbstractLexer& reflex::AbstractLexer< M >::out | ( | std::ostream & | os | ) |
| inline

Set the current output to the given output stream to echo text matches to.

Returns
  reference to *this

Parameters

  os | output stream to echo text matches to

template<typename M >

std::ostream& reflex::AbstractLexer< M >::out | ( |  | ) | const
| inline

Returns the current output stream used to echo text matches to.

Returns
  reference to the current std::ostream object

template<typename M >

void reflex::AbstractLexer< M >::perf_report | ( |  | ) |
| inline

Dummy performance reporter, to prevent link errors when reflex option -p is omitted.

template<typename M >

bool reflex::AbstractLexer< M >::pop_matcher | ( |  | ) |
| inline

Pop matcher from the stack and continue scanning where it left off, delete the current matcher.

template<typename M >

void reflex::AbstractLexer< M >::pop_state | ( |  | ) |
| inline

Pop the stack start condition state and transition to that state.

template<typename M >

Matcher* reflex::AbstractLexer< M >::ptr_matcher | ( |  | ) | const
| inline

Returns a pointer to the current matcher, NULL if none was set.

Returns
  pointer to the current matcher or NULL if no matcher was set

template<typename M >

void reflex::AbstractLexer< M >::push_matcher | ( | Matcher * | matcher | ) |
| inline

Push the current matcher on the stack and use the given matcher for scanning.

Parameters

  matcher | points to a matcher object

template<typename M >

void reflex::AbstractLexer< M >::push_state | ( | int | state | ) |
| inline

Push the current start condition state on the stack and transition to the given start condition state.

Parameters

  state | start condition state to transition to

template<typename M >

virtual void reflex::AbstractLexer< M >::set_debug | ( | int | flag | ) |
| inline virtual

Set debug flag value.

Parameters

  flag | 0 or 1 (false or true)

template<typename M >

size_t reflex::AbstractLexer< M >::size | ( |  | ) | const
| inline

Returns the matched text size in number of bytes.

Returns
  size of the matched text

template<typename M >

AbstractLexer& reflex::AbstractLexer< M >::start | ( | int | state | ) |
| inline

Transition to the given start condition state.

Returns
  reference to *this

Parameters

  state | start condition state to transition to

template<typename M >

int reflex::AbstractLexer< M >::start | ( |  | ) | const
| inline

Returns the current start condition state.

Returns
  start condition (integer)

template<typename M >

bool reflex::AbstractLexer< M >::states_empty | ( |  | ) | const
| inline

Returns true if the condition state stack is empty.

Returns
  true if the stack is empty, false otherwise

template<typename M >

Input& reflex::AbstractLexer< M >::stdinit | ( |  | ) |
| inline

Returns the current input character sequence that is being scanned, if none assign stdin.

Returns
  reference to the current reflex::Input object with input assigned

template<typename M >

std::string reflex::AbstractLexer< M >::str | ( |  | ) | const
| inline

Returns string with a copy of the text matched.

Returns
  matched text

template<typename M >

const char* reflex::AbstractLexer< M >::text | ( |  | ) | const
| inline

Returns string with the text matched.

Returns
  matched text

template<typename M >

int reflex::AbstractLexer< M >::top_state | ( |  | ) | const
| inline

Returns the stack top start condition state or 0 (INITIAL) if the stack is empty.

Returns
  start condition (integer)

template<typename M >

int reflex::AbstractLexer< M >::wchr | ( |  | ) | const
| inline

Returns the first wide character of the text matched.

Returns
  wide char (UTF-8 converted to Unicode)

template<typename M >

virtual int reflex::AbstractLexer< M >::wrap | ( |  | ) |
| inline virtual

The default wrap operation at EOF: do not wrap input.

Returns
  1 (override to return 0 to indicate that new input is available after this invocation so that wrap after EOF is OK)

template<typename M >

size_t reflex::AbstractLexer< M >::wsize | ( |  | ) | const
| inline

Returns the matched text size in number of (wide) characters.

Returns
  number of (wide) characters matched

template<typename M >

std::wstring reflex::AbstractLexer< M >::wstr | ( |  | ) | const
| inline

Returns wide string with a copy of the text matched.

Returns
  matched text

## Member Data Documentation

template<typename M >

char* reflex::AbstractLexer< M >::base_
| protected

the buffer to scan in place, if non-NULL

template<typename M >

int reflex::AbstractLexer< M >::debug_
| protected

1 if -d (–debug) 0 otherwise:

template<typename M >

Input reflex::AbstractLexer< M >::in_
| protected

the input character sequence to scan

template<typename M >

Matcher* reflex::AbstractLexer< M >::matcher_
| protected

the matcher used for scanning

template<typename M >

std::ostream* reflex::AbstractLexer< M >::os_
| protected

the output stream to echo text matches to

template<typename M >

size_t reflex::AbstractLexer< M >::size_
| protected

the size of the buffer to scan in place, if nonzero

template<typename M >

std::stack<Matcher*> reflex::AbstractLexer< M >::stack_
| protected

a stack of pointers to matchers

template<typename M >

int reflex::AbstractLexer< M >::start_
| protected

the current start condition state

template<typename M >

std::stack<int> reflex::AbstractLexer< M >::state_
| protected

a stack of start condition states

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

- abslexer.h