|  | Reflex Class Reference updated Sat Oct 7 2023 by Robert van Engelen |

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | Protected Attributes | Private Member Functions | List of all members
Reflex Class Reference

RE/flex scanner generator class, a variation of the classic "lex" tool to generate scanners. More...

`#include <reflex.h>`

Collaboration diagram for Reflex:
[legend]

## Classes

struct | Code
| Line of code fragment in lex specifications. More...
struct | Library
| A library entry to describe regex library properties. More...
struct | Rule
| A regex pattern and action pair that forms a rule. More...

## Public Types

typedef std::map< std::string, Library > | LibraryMap
| Dictionary of regex libraries. More...
typedef std::vector< Code > | Codes
| Collection of ordered lines of code. More...
typedef std::vector< Rule > | Rules
| Collection of ordered rules. More...
typedef std::vector< std::string > | Strings
| Collection of ordered strings. More...
typedef std::map< std::string, std::string > | StringMap
| Dictionary (std::string) More...
typedef std::map< std::string, const char * > | Dictionary
| Dictionary (const char*) More...
typedef size_t | Start
| Start condition state type. More...
typedef std::set< Start > | Starts
| Set of start conditions. More...
typedef std::map< Start, Codes > | CodesMap
| Map of start conditions to lines of code. More...
typedef std::map< Start, Rules > | RulesMap
| Map of start conditions to rules. More...

## Public Member Functions

void | main (int argc, char **argv)
| Main program. More...

## Protected Attributes

StringMap | options
| maps option name (from the options_table) to its option value More...
LibraryMap | libraries
| maps regex library name ("reflex", "boost", etc) to library info More...
Library * | library
| the regex library selected More...
Strings | conditions
| "INITIAL" start condition etc. defined with x name More...
Strings | patterns
| regex patterns for each start condition More...
Starts | inclusive
| inclusive start conditions More...
StringMap | definitions
| map of {name} to regex More...
RulesMap | rules
| <Start_i>regex_j action for Start i Rule j More...
Codes | section_top
| top{ user code %} in section 1 container More...
Codes | section_class
| class{ class code %} in section 1 container More...
Codes | section_init
| init{ init code %} in section 1 container More...
Codes | section_begin
| begin{ begin scanning code %} in section 1 container More...
Codes | section_1
| %{ user code %} in section 1 container More...
CodesMap | section_2
| lexer user code in section 2 container More...
Codes | section_3
| main user code in section 3 container More...
std::string | infile
| input file name More...
reflex::BufferedInput | in
| input lex spec More...
std::ostream * | out
| output stream More...
std::string | line
| current line read from input More...
size_t | lineno
| current line number at input More...
size_t | linelen
| current line length More...
bool | color_term
| terminal supports colors More...

## Private Member Functions

void | init (int argc, char **argv)
| Reflex initialization. More...
void | version ()
| Display version information and exit. More...
void | help (const char *message=NULL, const char *arg=NULL)
| Display help information with an optional diagnostic message and exit. More...
void | set_library ()
| Set/reset regex library matcher. More...
void | parse ()
| Parse lex specification input. More...
void | parse_section_1 ()
| Parse section 1 of a lex specification. More...
void | parse_section_2 ()
| Parse section 2 of a lex specification. More...
void | parse_section_3 ()
| Parse section 3 of a lex specification. More...
void | include (const std::string &filename)
| Parse the specified %include file. More...
void | write ()
| Write lex.yy.cpp. More...
void | write_banner (const char *title)
| Write a banner in lex.yy.cpp. More...
void | write_prelude ()
| Write the prelude to lex.yy.cpp. More...
void | write_defines ()
| Write Flex-compatible #defines to lex.yy.cpp. More...
void | write_class ()
| Write the lexer class to lex.yy.cpp. More...
void | write_section_top ()
| Write %top code to lex.yy.cpp. More...
void | write_section_class ()
| Write %class code to lex.yy.cpp. More...
void | write_section_init ()
| Write %init code to lex.yy.cpp. More...
void | write_section_begin ()
| Write %begin code to lex.yy.cpp. More...
void | write_perf_report ()
| Write perf_report code to lex.yy.cpp. More...
void | write_section_1 ()
| Write section 1 user-defined code to lex.yy.cpp. More...
void | write_section_3 ()
| Write section 3 user-defined code to lex.yy.cpp. More...
void | write_code (const Codes &codes)
| Write lines of code to lex.yy.cpp annotated with line source info. More...
void | write_code (const Code &code)
| Write a line(s) of code to lex.yy.cpp annotated with line source info. More...
void | write_lexer ()
| Write lexer code and lex() method code. More...
void | write_main ()
| Write main() to lex.yy.cpp. More...
void | write_regex (const std::string *condition, const std::string &regex)
| Write regex string to lex.yy.cpp by escaping \ and ", prevent trigraphs, very long strings are represented by character arrays. More...
void | write_namespace_open ()
| Write namespace openings NAME {. More...
void | write_namespace_close ()
| Write namespace closing scope } // NAME. More...
void | write_namespace_scope ()
| Write namespace scope NAME :: More...
void | undot_namespace (std::string &s)
| Replace all . by :: in namespace name. More...
void | write_final ()
| Finalize and display usage report. More...
void | write_regexp_file ()
| Save file with regex patterns when option –regexp-file is specified. More...
void | write_header_file ()
| Save header file when option –header-file is specified. More...
bool | get_line ()
| Fetch next line from the input, return true if ok. More...
bool | skip_comment (size_t &pos)
| Advance pos over white space and comments, return true if ok. More...
bool | is (const char *s)
| Match case-insensitive string s while ignoring the rest of the line, return true if OK. More...
bool | ins (const char *s)
| Match case-insensitive string s at any indent while ignoring the rest of the line, return true if OK. More...
bool | br (size_t pos, const char *s=NULL)
| Match s then look for a '{' at the end of the line (skipping whitespace) and return true, false otherwise (pos is unchanged) More...
bool | as (size_t &pos, const char *s)
| Advance pos to match case-insensitive initial part of the string s followed by white space, return true if OK. More...
bool | ws (size_t &pos)
| Advance pos over whitespace, returns true if whitespace was found. More...
bool | eq (size_t &pos)
| Advance pos over '=' and whitespace when present, return true if OK. More...
bool | nl (size_t &pos)
| Advance pos to end of line while skipping whitespace, return true if end of line. More...
bool | is_code ()
| Check if current line starts a block of code or a comment. More...
bool | is_top_code ()
| Check if current line starts a block of top code. More...
bool | is_class_code ()
| Check if current line starts a block of class code. More...
bool | is_init_code ()
| Check if current line starts a block of init code. More...
bool | is_begin_code ()
| Check if current line starts a block of begin code. More...
std::string | get_name (size_t &pos)
| Advance pos over name (letters, digits, ., -, _ or any non-ASCII character > U+007F), return name. More...
std::string | get_option (size_t &pos)
| Advance pos over option name (letters, digits, +/hyphen/underscore), return name. More...
std::string | get_start (size_t &pos)
| Advance pos over start condition name (an ASCII C++ identifier or C++11 Unicode identifier), return name. More...
std::string | get_string (size_t &pos)
| Advance pos over quoted string, return string. More...
bool | get_pattern (size_t &pos, std::string &pattern, std::string &regex)
| Get pattern and its regex form converted to a format understood by the selected regex engine library. More...
std::string | get_namespace (size_t &pos)
| Advance pos over option name or namespace (letters, digits, ::, ., -, _ or any non-ASCII character > U+007F), return name. More...
std::string | get_code (size_t &pos)
| Get line(s) of code, %{ %}, %top, %class, %init, and %begin. More...
std::string | escape_bs (const std::string &s)
| Returns string with all \ replaced by \ to stringify file paths. More...
std::string | upper_name (const std::string &s)
| Returns string in upper case as a name, replacing non-alphanum by underscore. More...
std::string | param_args (const std::string &s)
| Extract a list of argument names from function parameters. More...
bool | get_starts (size_t &pos, Starts &starts)
| Add start conditions <start1,start2,...> or subtract them with <-start1,-start2,...> More...
void | abort (const char *message, const char *arg=NULL)
| Abort with an error message. More...
void | error (const char *message, const char *arg=NULL, size_t at_lineno=0)
| Report an error and exit. More...
void | warning (const char *message, const char *arg=NULL, size_t at_lineno=0)
| Report a warning. More...
const char * | SGR (const char *code)

## Detailed Description

RE/flex scanner generator class, a variation of the classic "lex" tool to generate scanners.

More info TODO

The Lex specification file extension is `.l`, but also `.lex`, `.ll`, `.l++`, `.lxx`, and `.lpp` are in use.

## Member Typedef Documentation

typedef std::vector<Code> Reflex::Codes

Collection of ordered lines of code.

typedef std::map<Start,Codes> Reflex::CodesMap

Map of start conditions to lines of code.

typedef std::map<std::string,const char*> Reflex::Dictionary

Dictionary (const char*)

typedef std::map<std::string,Library> Reflex::LibraryMap

Dictionary of regex libraries.

typedef std::vector<Rule> Reflex::Rules

Collection of ordered rules.

typedef std::map<Start,Rules> Reflex::RulesMap

Map of start conditions to rules.

typedef size_t Reflex::Start

Start condition state type.

typedef std::set<Start> Reflex::Starts

Set of start conditions.

typedef std::map<std::string,std::string> Reflex::StringMap

Dictionary (std::string)

typedef std::vector<std::string> Reflex::Strings

Collection of ordered strings.

## Member Function Documentation

void Reflex::abort | ( | const char * | message,
|  | const char * | arg = `NULL`
| ) |  |

private

Abort with an error message.

bool Reflex::as | ( | size_t & | pos,
|  | const char * | s
| ) |  |

private

Advance pos to match case-insensitive initial part of the string s followed by white space, return true if OK.

bool Reflex::br | ( | size_t | pos,
|  | const char * | s = `NULL`
| ) |  |

private

Match s then look for a '{' at the end of the line (skipping whitespace) and return true, false otherwise (pos is unchanged)

bool Reflex::eq | ( | size_t & | pos | ) |

private

Advance pos over '=' and whitespace when present, return true if OK.

void Reflex::error | ( | const char * | message,
|  | const char * | arg = `NULL`,
|  | size_t | at_lineno = `0`
| ) |  |

private

Report an error and exit.

std::string Reflex::escape_bs | ( | const std::string & | s | ) |

private

Returns string with all \ replaced by \ to stringify file paths.

std::string Reflex::get_code | ( | size_t & | pos | ) |

private

Get line(s) of code, %{ %}, %top, %class, %init, and %begin.

bool Reflex::get_line | ( |  | ) |

private

Fetch next line from the input, return true if ok.

std::string Reflex::get_name | ( | size_t & | pos | ) |

private

Advance pos over name (letters, digits, ., -, _ or any non-ASCII character > U+007F), return name.

std::string Reflex::get_namespace | ( | size_t & | pos | ) |

private

Advance pos over option name or namespace (letters, digits, ::, ., -, _ or any non-ASCII character > U+007F), return name.

std::string Reflex::get_option | ( | size_t & | pos | ) |

private

Advance pos over option name (letters, digits, +/hyphen/underscore), return name.

bool Reflex::get_pattern | ( | size_t & | pos,
|  | std::string & | pattern,
|  | std::string & | regex
| ) |  |

private

Get pattern and its regex form converted to a format understood by the selected regex engine library.

std::string Reflex::get_start | ( | size_t & | pos | ) |

private

Advance pos over start condition name (an ASCII C++ identifier or C++11 Unicode identifier), return name.

bool Reflex::get_starts | ( | size_t & | pos,
|  | Starts & | starts
| ) |  |

private

Add start conditions <start1,start2,...> or subtract them with <-start1,-start2,...>

std::string Reflex::get_string | ( | size_t & | pos | ) |

private

Advance pos over quoted string, return string.

void Reflex::help | ( | const char * | message = `NULL`,
|  | const char * | arg = `NULL`
| ) |  |

private

Display help information with an optional diagnostic message and exit.

void Reflex::include | ( | const std::string & | filename | ) |

private

Parse the specified %include file.

void Reflex::init | ( | int | argc,
|  | char ** | argv
| ) |  |

private

Reflex initialization.

bool Reflex::ins | ( | const char * | s | ) |

private

Match case-insensitive string s at any indent while ignoring the rest of the line, return true if OK.

bool Reflex::is | ( | const char * | s | ) |

private

Match case-insensitive string s while ignoring the rest of the line, return true if OK.

bool Reflex::is_begin_code | ( |  | ) |

private

Check if current line starts a block of begin code.

bool Reflex::is_class_code | ( |  | ) |

private

Check if current line starts a block of class code.

bool Reflex::is_code | ( |  | ) |

private

Check if current line starts a block of code or a comment.

bool Reflex::is_init_code | ( |  | ) |

private

Check if current line starts a block of init code.

bool Reflex::is_top_code | ( |  | ) |

private

Check if current line starts a block of top code.

void Reflex::main | ( | int | argc,
|  | char ** | argv
| ) |  |

Main program.

bool Reflex::nl | ( | size_t & | pos | ) |

private

Advance pos to end of line while skipping whitespace, return true if end of line.

std::string Reflex::param_args | ( | const std::string & | s | ) |

private

Extract a list of argument names from function parameters.

void Reflex::parse | ( |  | ) |

private

Parse lex specification input.

void Reflex::parse_section_1 | ( |  | ) |

private

Parse section 1 of a lex specification.

void Reflex::parse_section_2 | ( |  | ) |

private

Parse section 2 of a lex specification.

void Reflex::parse_section_3 | ( |  | ) |

private

Parse section 3 of a lex specification.

void Reflex::set_library | ( |  | ) |

private

Set/reset regex library matcher.

const char* Reflex::SGR | ( | const char * | code | ) |

inline private

bool Reflex::skip_comment | ( | size_t & | pos | ) |

private

Advance pos over white space and comments, return true if ok.

void Reflex::undot_namespace | ( | std::string & | s | ) |

private

Replace all . by :: in namespace name.

std::string Reflex::upper_name | ( | const std::string & | s | ) |

private

Returns string in upper case as a name, replacing non-alphanum by underscore.

void Reflex::version | ( |  | ) |

private

Display version information and exit.

void Reflex::warning | ( | const char * | message,
|  | const char * | arg = `NULL`,
|  | size_t | at_lineno = `0`
| ) |  |

private

Report a warning.

void Reflex::write | ( |  | ) |

private

Write lex.yy.cpp.

void Reflex::write_banner | ( | const char * | title | ) |

private

Write a banner in lex.yy.cpp.

void Reflex::write_class | ( |  | ) |

private

Write the lexer class to lex.yy.cpp.

void Reflex::write_code | ( | const Codes & | codes | ) |

private

Write lines of code to lex.yy.cpp annotated with line source info.

void Reflex::write_code | ( | const Code & | code | ) |

private

Write a line(s) of code to lex.yy.cpp annotated with line source info.

void Reflex::write_defines | ( |  | ) |

private

Write Flex-compatible #defines to lex.yy.cpp.

void Reflex::write_final | ( |  | ) |

private

Finalize and display usage report.

void Reflex::write_header_file | ( |  | ) |

private

Save header file when option –header-file is specified.

void Reflex::write_lexer | ( |  | ) |

private

Write lexer code and lex() method code.

void Reflex::write_main | ( |  | ) |

private

Write main() to lex.yy.cpp.

void Reflex::write_namespace_close | ( |  | ) |

private

Write namespace closing scope } // NAME.

void Reflex::write_namespace_open | ( |  | ) |

private

Write namespace openings NAME {.

void Reflex::write_namespace_scope | ( |  | ) |

private

Write namespace scope NAME ::

void Reflex::write_perf_report | ( |  | ) |

private

Write perf_report code to lex.yy.cpp.

void Reflex::write_prelude | ( |  | ) |

private

Write the prelude to lex.yy.cpp.

void Reflex::write_regex | ( | const std::string * | condition,
|  | const std::string & | regex
| ) |  |

private

Write regex string to lex.yy.cpp by escaping \ and ", prevent trigraphs, very long strings are represented by character arrays.

void Reflex::write_regexp_file | ( |  | ) |

private

Save file with regex patterns when option –regexp-file is specified.

void Reflex::write_section_1 | ( |  | ) |

private

Write section 1 user-defined code to lex.yy.cpp.

void Reflex::write_section_3 | ( |  | ) |

private

Write section 3 user-defined code to lex.yy.cpp.

void Reflex::write_section_begin | ( |  | ) |

private

Write %begin code to lex.yy.cpp.

void Reflex::write_section_class | ( |  | ) |

private

Write %class code to lex.yy.cpp.

void Reflex::write_section_init | ( |  | ) |

private

Write %init code to lex.yy.cpp.

void Reflex::write_section_top | ( |  | ) |

private

Write %top code to lex.yy.cpp.

bool Reflex::ws | ( | size_t & | pos | ) |

private

Advance pos over whitespace, returns true if whitespace was found.

## Member Data Documentation

bool Reflex::color_term

protected

terminal supports colors

Strings Reflex::conditions

protected

"INITIAL" start condition etc. defined with x name

StringMap Reflex::definitions

protected

map of {name} to regex

reflex::BufferedInput Reflex::in

protected

input lex spec

Starts Reflex::inclusive

protected

inclusive start conditions

std::string Reflex::infile

protected

input file name

LibraryMap Reflex::libraries

protected

maps regex library name ("reflex", "boost", etc) to library info

Library* Reflex::library

protected

the regex library selected

std::string Reflex::line

protected

current line read from input

size_t Reflex::linelen

protected

current line length

size_t Reflex::lineno

protected

current line number at input

StringMap Reflex::options

protected

maps option name (from the options_table) to its option value

std::ostream* Reflex::out

protected

output stream

Strings Reflex::patterns

protected

regex patterns for each start condition

RulesMap Reflex::rules

protected

<Start_i>regex_j action for Start i Rule j

Codes Reflex::section_1

protected

%{ user code %} in section 1 container

CodesMap Reflex::section_2

protected

lexer user code in section 2 container

Codes Reflex::section_3

protected

main user code in section 3 container

Codes Reflex::section_begin

protected

begin{ begin scanning code %} in section 1 container

Codes Reflex::section_class

protected

class{ class code %} in section 1 container

Codes Reflex::section_init

protected

init{ init code %} in section 1 container

Codes Reflex::section_top

protected

top{ user code %} in section 1 container

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

- reflex.h
- reflex.cpp