Pattern class holds a regex pattern and its compiled FSM opcode table or code for the reflex::Matcher engine. More...
#include <pattern.h>
Classes | |
struct | Error |
Throwable error structure reflex::Pattern::Error. More... | |
struct | Option |
Global modifier modes, syntax flags, and compiler options. More... | |
struct | Position |
Finite state machine construction position information. More... | |
struct | State |
Finite state machine. More... | |
Public Types | |
enum | Const { IMAX = 0xffff } |
Common constants. More... | |
typedef uint16_t | Index |
index into opcodes array Pattern::opc_ and subpattern indexing More... | |
typedef uint32_t | Opcode |
32 bit opcode word More... | |
typedef void(* | FSM) (class Matcher &) |
Public Member Functions | |
Pattern (const char *regex, const char *options=NULL) throw (Error) | |
Construct a pattern object given a regex string. More... | |
Pattern (const char *regex, const std::string &options) throw (Error) | |
Construct a pattern object given a regex string. More... | |
Pattern (const std::string ®ex, const char *options=NULL) throw (Error) | |
Construct a pattern object given a regex string. More... | |
Pattern (const std::string ®ex, const std::string &options) throw (Error) | |
Construct a pattern object given a regex string. More... | |
Pattern (const Opcode *code) throw (Error) | |
Construct a pattern object given an opcode table. More... | |
Pattern (FSM fsm) throw (Error) | |
Construct a pattern object given a function pointer to FSM code. More... | |
virtual | ~Pattern (void) |
Destructor, deletes internal code array when owned and allocated. More... | |
Index | size (void) const |
Number of subpatterns of this pattern object. More... | |
const std::string | operator[] (Index choice) const |
Get subpattern of this pattern object. More... | |
bool | reachable (Index choice) const |
Check is subpattern is reachable by a match. More... | |
size_t | nodes (void) const |
Get the number of finite state machine nodes (vertices). More... | |
size_t | edges (void) const |
Get the number of finite state machine edges (transitions on input characters). More... | |
size_t | words (void) const |
Get the code size in number of words. More... | |
Protected Member Functions | |
virtual void | error (enum Error::Code code, const char *message, size_t loc=0) const throw (Error) |
Throw an error. More... | |
Private Types | |
enum | Meta { META_MIN = 0x100, META_NWB = 0x101, META_NWE = 0x102, META_BWB = 0x103, META_EWB = 0x104, META_BWE = 0x105, META_EWE = 0x106, META_BOL = 0x107, META_EOL = 0x108, META_BOB = 0x109, META_EOB = 0x10a, META_IND = 0x10b, META_DED = 0x10c, META_MAX } |
Meta characters. More... | |
typedef unsigned int | Char |
typedef ORanges< Char > | Chars |
represent (wide) char set as a set of ranges More... | |
typedef size_t | Location |
typedef ORanges< Location > | Ranges |
typedef std::set< Location > | Set |
typedef std::map< int, Ranges > | Map |
typedef std::set< Position > | Positions |
typedef std::map< Position, Positions > | Follow |
typedef std::pair< Chars, Positions > | Move |
typedef std::list< Move > | Moves |
Private Member Functions | |
void | init (const char *options) throw (Error) |
Initialize the pattern at construction. More... | |
void | init_options (const char *options) |
void | parse (Positions &startpos, Follow &followpos, Map &modifiers, Map &lookahead) throw (Error) |
void | parse1 (bool begin, Location &loc, Positions &firstpos, Positions &lastpos, bool &nullable, Follow &followpos, Positions &lazypos, Map &modifiers, Ranges &lookahead, Index &iter) throw (Error) |
void | parse2 (bool begin, Location &loc, Positions &firstpos, Positions &lastpos, bool &nullable, Follow &followpos, Positions &lazypos, Map &modifiers, Ranges &lookahead, Index &iter) throw (Error) |
void | parse3 (bool begin, Location &loc, Positions &firstpos, Positions &lastpos, bool &nullable, Follow &followpos, Positions &lazypos, Map &modifiers, Ranges &lookahead, Index &iter) throw (Error) |
void | parse4 (bool begin, Location &loc, Positions &firstpos, Positions &lastpos, bool &nullable, Follow &followpos, Positions &lazypos, Map &modifiers, Ranges &lookahead, Index &iter) throw (Error) |
void | parse_esc (Location &loc) const throw (Error) |
void | compile (State &start, Follow &followpos, const Map &modifiers, const Map &lookahead) throw (Error) |
void | lazy (const Positions &lazypos, Positions &pos) const |
void | lazy (const Positions &lazypos, const Positions &pos, Positions &pos1) const |
void | greedy (Positions &pos) const |
void | trim_lazy (Positions &pos) const |
void | compile_transition (State *state, Follow &followpos, const Map &modifiers, const Map &lookahead, Moves &moves) const throw (Error) |
void | transition (Moves &moves, const Chars &chars, const Positions &follow) const |
Char | compile_esc (Location loc, Chars &chars) const throw (Error) |
void | compile_list (Location loc, Chars &chars, const Map &modifiers) const throw (Error) |
void | posix (size_t index, Chars &chars) const |
void | flip (Chars &chars) const |
void | assemble (State &start) throw (Error) |
void | compact_dfa (State &start) |
void | encode_dfa (State &start) throw (Error) |
void | gencode_dfa (const State &start) const |
void | gencode_dfa_closure (FILE *fd, const State *start, int nest) const |
void | delete_dfa (State &start) |
void | export_dfa (const State &start) const |
void | export_code (void) const |
Location | find_at (Location loc, char c) const |
Char | at (Location k) const |
bool | eq_at (Location loc, const char *s) const |
Char | escape_at (Location loc) const |
Char | escapes_at (Location loc, const char *escapes) const |
Static Private Member Functions | |
static bool | is_modified (int mode, const Map &modifiers, Location loc) |
static bool | is_meta (Char c) |
static Opcode | opcode_take (Index index) |
static Opcode | opcode_redo (void) |
static Opcode | opcode_tail (Index index) |
static Opcode | opcode_head (Index index) |
static Opcode | opcode_goto (Char lo, Char hi, Index index) |
static Opcode | opcode_halt (void) |
static bool | is_opcode_redo (Opcode opcode) |
static bool | is_opcode_take (Opcode opcode) |
static bool | is_opcode_tail (Opcode opcode) |
static bool | is_opcode_head (Opcode opcode) |
static bool | is_opcode_halt (Opcode opcode) |
static bool | is_opcode_meta (Opcode opcode) |
static bool | is_opcode_meta (Opcode opcode, Char a) |
static bool | is_opcode_match (Opcode opcode, unsigned char c) |
static Char | meta_of (Opcode opcode) |
static Char | lo_of (Opcode opcode) |
static Char | hi_of (Opcode opcode) |
static Index | index_of (Opcode opcode) |
Private Attributes | |
Option | opt_ |
pattern compiler options More... | |
std::string | rex_ |
regular expression string More... | |
std::vector< Location > | end_ |
entries point to the subpattern's ending '|' or '\0' More... | |
std::vector< bool > | acc_ |
true if subpattern n is acceptable (state is reachable) More... | |
size_t | vno_ |
number of finite state machine vertices |V| More... | |
size_t | eno_ |
number of finite state machine edges |E| More... | |
const Opcode * | opc_ |
points to the opcode table More... | |
Index | nop_ |
number of opcodes generated More... | |
FSM | fsm_ |
function pointer to FSM code More... | |
Friends | |
class | Matcher |
permit access by the reflex::Matcher engine More... | |
Pattern class holds a regex pattern and its compiled FSM opcode table or code for the reflex::Matcher engine.
More info TODO
|
private |
|
private |
represent (wide) char set as a set of ranges
|
private |
typedef void(* reflex::Pattern::FSM) (class Matcher &) |
function pointer to FSM code
typedef uint16_t reflex::Pattern::Index |
index into opcodes array Pattern::opc_ and subpattern indexing
|
private |
|
private |
|
private |
|
private |
typedef uint32_t reflex::Pattern::Opcode |
32 bit opcode word
|
private |
|
private |
|
private |
|
private |
Meta characters.
|
inlineexplicit |
Construct a pattern object given a regex string.
|
inlineexplicit |
Construct a pattern object given a regex string.
|
inlineexplicit |
Construct a pattern object given a regex string.
|
inlineexplicit |
Construct a pattern object given a regex string.
Construct a pattern object given an opcode table.
Construct a pattern object given a function pointer to FSM code.
|
inlinevirtual |
Destructor, deletes internal code array when owned and allocated.
|
private |
|
private |
|
private |
|
private |
|
private |
|
inline |
Get the number of finite state machine edges (transitions on input characters).
|
inlineprivate |
|
protectedvirtual |
Throw an error.
code | error code |
message | a human-readable error message (not NULL) |
loc | optional location of the error in regex string Pattern::rex_ |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Initialize the pattern at construction.
|
private |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
private |
|
inline |
Get the number of finite state machine nodes (vertices).
|
inlinestaticprivate |
|
inlinestaticprivate |
const std::string reflex::Pattern::operator[] | ( | Index | choice | ) | const |
Get subpattern of this pattern object.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
inline |
Check is subpattern is reachable by a match.
|
inline |
Number of subpatterns of this pattern object.
|
private |
|
private |
|
inline |
Get the code size in number of words.
|
friend |
permit access by the reflex::Matcher engine
|
private |
true if subpattern n is acceptable (state is reachable)
|
private |
entries point to the subpattern's ending '|' or '\0'
|
private |
number of finite state machine edges |E|
|
private |
function pointer to FSM code
|
private |
number of opcodes generated
|
private |
points to the opcode table
|
private |
pattern compiler options
|
private |
regular expression string
|
private |
number of finite state machine vertices |V|