Reflex Class Reference

updated Mon Apr 10 2017 by Robert van Engelen
 
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:
Collaboration graph
[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, LibraryLibraryMap
 Dictionary of regex libraries. More...
 
typedef std::vector< CodeCodes
 Collection of ordered lines of code. More...
 
typedef std::vector< RuleRules
 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< StartStarts
 Set of start conditions. More...
 
typedef std::map< Start, CodesCodesMap
 Map of start conditions to lines of code. More...
 
typedef std::map< Start, RulesRulesMap
 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...
 
Librarylibrary
 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_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...
 
std::istream * in
 input stream with 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_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 &regex)
 Write regex string to lex.yy.cpp. More...
 
void stats ()
 Display usage report. 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 as (size_t &pos, const char *s)
 Advance pos to match case-insensitive string s followed by whitespace, return true if OK. More...
 
bool ws (size_t &pos)
 Advance pos over whitespace, returns true if OK. More...
 
bool eq (size_t &pos)
 Advance pos over '=' and whitespace, 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_topcode ()
 Check if current line starts a block of top code. More...
 
bool is_classcode ()
 Check if current line starts a block of class code. More...
 
bool is_initcode ()
 Check if current line starts a block of init code. More...
 
std::string get_name (size_t &pos)
 Advance pos over name (letters, digits, hyphen/underscore, or any non-ASCII character), 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...
 
std::string get_regex (size_t &pos)
 Get regex string, converted to a format understood by the selected regex engine library. More...
 
Starts get_starts (size_t &pos)
 Get start conditions <start1,start2,...> of a rule. More...
 
std::string get_code (size_t &pos)
 Get line(s) of code, %{ %}, %top{ %}, %class{ %}, and %init{ %}. 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 string s followed by whitespace, return true if OK.

bool Reflex::eq ( size_t &  pos)
private

Advance pos over '=' and whitespace, 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::get_code ( size_t &  pos)
private

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

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, hyphen/underscore, or any non-ASCII character), return name.

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

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

std::string Reflex::get_regex ( size_t &  pos)
private

Get regex string, 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.

Reflex::Starts Reflex::get_starts ( size_t &  pos)
private

Get start conditions <start1,start2,...> of a rule.

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::is_classcode ( )
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_initcode ( )
private

Check if current line starts a block of init code.

bool Reflex::is_topcode ( )
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.

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)
inlineprivate
bool Reflex::skip_comment ( size_t &  pos)
private

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

void Reflex::stats ( )
private

Display usage report.

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_lexer ( )
private

Write lexer code and lex() method code.

void Reflex::write_main ( )
private

Write main() to lex.yy.cpp.

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 &  regex)
private

Write regex string to lex.yy.cpp.

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_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 OK.

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

std::istream* Reflex::in
protected

input stream with 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_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: