Ethan Nicholas | ca82a92 | 2017-09-07 09:39:50 -0400 | [diff] [blame^] | 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_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 | */ |
| 17 | struct 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 |