Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
RegexNode.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SKSL_REGEXNODE
9#define SKSL_REGEXNODE
10
11#include <string>
12#include <utility>
13#include <vector>
14
15struct NFA;
16
17/**
18 * Represents a node in the parse tree of a regular expression.
19 */
20struct RegexNode {
32
34 : fKind(kind) {}
35
36 RegexNode(Kind kind, char payload)
37 : fKind(kind) {
38 fPayload.fChar = payload;
39 }
40
41 RegexNode(Kind kind, const char* children)
42 : fKind(kind) {
43 fPayload.fBool = false;
44 while (*children != '\0') {
45 fChildren.emplace_back(kChar_Kind, *children);
46 ++children;
47 }
48 }
49
51 : fKind(kind) {
52 fChildren.push_back(std::move(child));
53 }
54
55 RegexNode(Kind kind, RegexNode child1, RegexNode child2)
56 : fKind(kind) {
57 fChildren.push_back(std::move(child1));
58 fChildren.push_back(std::move(child2));
59 }
60
61 /**
62 * Creates NFA states for this node, with a successful match against this node resulting in a
63 * transition to all of the states in the accept vector.
64 */
65 std::vector<int> createStates(NFA* nfa, const std::vector<int>& accept) const;
66
67 std::string description() const;
68
70
71 union Payload {
72 char fChar;
73 bool fBool;
75
76 std::vector<RegexNode> fChildren;
77};
78
79#endif
Definition NFA.h:22
union RegexNode::Payload fPayload
std::string description() const
Kind fKind
Definition RegexNode.h:69
RegexNode(Kind kind, char payload)
Definition RegexNode.h:36
RegexNode(Kind kind, const char *children)
Definition RegexNode.h:41
RegexNode(Kind kind)
Definition RegexNode.h:33
std::vector< int > createStates(NFA *nfa, const std::vector< int > &accept) const
Definition RegexNode.cpp:16
std::vector< RegexNode > fChildren
Definition RegexNode.h:76
@ kRange_Kind
Definition RegexNode.h:28
@ kQuestion_Kind
Definition RegexNode.h:29
@ kConcat_Kind
Definition RegexNode.h:24
@ kCharset_Kind
Definition RegexNode.h:23
RegexNode(Kind kind, RegexNode child1, RegexNode child2)
Definition RegexNode.h:55
RegexNode(Kind kind, RegexNode child)
Definition RegexNode.h:50