Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
RegexNode Struct Reference

#include <RegexNode.h>

Classes

union  Payload
 

Public Types

enum  Kind {
  kChar_Kind , kCharset_Kind , kConcat_Kind , kDot_Kind ,
  kOr_Kind , kPlus_Kind , kRange_Kind , kQuestion_Kind ,
  kStar_Kind
}
 

Public Member Functions

 RegexNode (Kind kind)
 
 RegexNode (Kind kind, char payload)
 
 RegexNode (Kind kind, const char *children)
 
 RegexNode (Kind kind, RegexNode child)
 
 RegexNode (Kind kind, RegexNode child1, RegexNode child2)
 
std::vector< intcreateStates (NFA *nfa, const std::vector< int > &accept) const
 
std::string description () const
 

Public Attributes

Kind fKind
 
union RegexNode::Payload fPayload
 
std::vector< RegexNodefChildren
 

Detailed Description

Represents a node in the parse tree of a regular expression.

Definition at line 20 of file RegexNode.h.

Member Enumeration Documentation

◆ Kind

Enumerator
kChar_Kind 
kCharset_Kind 
kConcat_Kind 
kDot_Kind 
kOr_Kind 
kPlus_Kind 
kRange_Kind 
kQuestion_Kind 
kStar_Kind 

Definition at line 21 of file RegexNode.h.

21 {
31 };
@ kStar_Kind
Definition: RegexNode.h:30
@ kChar_Kind
Definition: RegexNode.h:22
@ kDot_Kind
Definition: RegexNode.h:25
@ kOr_Kind
Definition: RegexNode.h:26
@ kRange_Kind
Definition: RegexNode.h:28
@ kQuestion_Kind
Definition: RegexNode.h:29
@ kPlus_Kind
Definition: RegexNode.h:27
@ kConcat_Kind
Definition: RegexNode.h:24
@ kCharset_Kind
Definition: RegexNode.h:23

Constructor & Destructor Documentation

◆ RegexNode() [1/5]

RegexNode::RegexNode ( Kind  kind)
inline

Definition at line 33 of file RegexNode.h.

34 : fKind(kind) {}
Kind fKind
Definition: RegexNode.h:69

◆ RegexNode() [2/5]

RegexNode::RegexNode ( Kind  kind,
char  payload 
)
inline

Definition at line 36 of file RegexNode.h.

37 : fKind(kind) {
38 fPayload.fChar = payload;
39 }
union RegexNode::Payload fPayload

◆ RegexNode() [3/5]

RegexNode::RegexNode ( Kind  kind,
const char *  children 
)
inline

Definition at line 41 of file RegexNode.h.

42 : fKind(kind) {
43 fPayload.fBool = false;
44 while (*children != '\0') {
45 fChildren.emplace_back(kChar_Kind, *children);
46 ++children;
47 }
48 }
std::vector< RegexNode > fChildren
Definition: RegexNode.h:76

◆ RegexNode() [4/5]

RegexNode::RegexNode ( Kind  kind,
RegexNode  child 
)
inline

Definition at line 50 of file RegexNode.h.

51 : fKind(kind) {
52 fChildren.push_back(std::move(child));
53 }

◆ RegexNode() [5/5]

RegexNode::RegexNode ( Kind  kind,
RegexNode  child1,
RegexNode  child2 
)
inline

Definition at line 55 of file RegexNode.h.

56 : fKind(kind) {
57 fChildren.push_back(std::move(child1));
58 fChildren.push_back(std::move(child2));
59 }

Member Function Documentation

◆ createStates()

std::vector< int > RegexNode::createStates ( NFA nfa,
const std::vector< int > &  accept 
) const

Creates NFA states for this node, with a successful match against this node resulting in a transition to all of the states in the accept vector.

Definition at line 16 of file RegexNode.cpp.

16 {
17 std::vector<int> result;
18 switch (fKind) {
19 case kChar_Kind:
20 result.push_back(nfa->addState(NFAState(fPayload.fChar, accept)));
21 break;
22 case kCharset_Kind: {
23 std::vector<bool> chars;
24 for (const RegexNode& child : fChildren) {
25 if (child.fKind == kChar_Kind) {
26 while (chars.size() <= (size_t) child.fPayload.fChar) {
27 chars.push_back(false);
28 }
29 chars[child.fPayload.fChar] = true;
30 } else {
31 SkASSERT(child.fKind == kRange_Kind);
32 while (chars.size() <= (size_t) child.fChildren[1].fPayload.fChar) {
33 chars.push_back(false);
34 }
35 for (char c = child.fChildren[0].fPayload.fChar;
36 c <= child.fChildren[1].fPayload.fChar;
37 ++c) {
38 chars[c] = true;
39 }
40 }
41 }
42 result.push_back(nfa->addState(NFAState(fPayload.fBool, chars, accept)));
43 break;
44 }
45 case kConcat_Kind: {
46 std::vector<int> right = fChildren[1].createStates(nfa, accept);
47 result = fChildren[0].createStates(nfa, right);
48 break;
49 }
50 case kDot_Kind:
51 result.push_back(nfa->addState(NFAState(NFAState::kDot_Kind, accept)));
52 break;
53 case kOr_Kind: {
54 std::vector<int> states = fChildren[0].createStates(nfa, accept);
55 result.insert(result.end(), states.begin(), states.end());
56 states = fChildren[1].createStates(nfa, accept);
57 result.insert(result.end(), states.begin(), states.end());
58 break;
59 }
60 case kPlus_Kind: {
61 std::vector<int> next = accept;
62 std::vector<int> placeholder;
63 int id = nfa->addState(NFAState(placeholder));
64 next.push_back(id);
65 result = fChildren[0].createStates(nfa, next);
66 nfa->fStates[id] = NFAState(result);
67 break;
68 }
69 case kQuestion_Kind:
70 result = fChildren[0].createStates(nfa, accept);
71 result.insert(result.end(), accept.begin(), accept.end());
72 break;
73 case kRange_Kind:
75 case kStar_Kind: {
76 std::vector<int> next = accept;
77 std::vector<int> placeholder;
78 int id = nfa->addState(NFAState(placeholder));
79 next.push_back(id);
80 result = fChildren[0].createStates(nfa, next);
81 result.insert(result.end(), accept.begin(), accept.end());
82 nfa->fStates[id] = NFAState(result);
83 break;
84 }
85 }
86 return result;
87}
static float next(float f)
#define SkUNREACHABLE
Definition: SkAssert.h:135
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool right(const SkPoint &p0, const SkPoint &p1)
GAsyncResult * result
@ kDot_Kind
Definition: NFAState.h:24
int addState(NFAState s)
Definition: NFA.h:39
std::vector< NFAState > fStates
Definition: NFA.h:53
const uintptr_t id

◆ description()

std::string RegexNode::description ( ) const

Member Data Documentation

◆ fChildren

std::vector<RegexNode> RegexNode::fChildren

Definition at line 76 of file RegexNode.h.

◆ fKind

Kind RegexNode::fKind

Definition at line 69 of file RegexNode.h.

◆ fPayload

union RegexNode::Payload RegexNode::fPayload

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