blob: 51e85ca2f8a76f49e06497442ac2efe2385068ac [file] [log] [blame]
Ethan Nicholasca82a922017-09-07 09:39:50 -04001/*
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_DFA
9#define SKSL_DFA
10
11#include <string>
12#include <vector>
13
14/**
15 * Tables representing a deterministic finite automaton for matching regular expressions.
16 */
17struct DFA {
18 DFA(std::vector<std::vector<int>> transitions, std::vector<int> accepts)
19 : fTransitions(transitions)
20 , fAccepts(accepts) {}
21
22 static constexpr char END_CHAR = 126;
23
24 // one row per character, one column per state
25 std::vector<std::vector<int>> fTransitions;
26
27 // contains, for each state, the token id we should report when matching ends in that state (-1
28 // for no match)
29 std::vector<int> fAccepts;
30};
31
32#endif