| #include <string> |
| 6 | #include <string_view> |
| 7 | #include <unordered_map> |
| 8 | #include <vector> |
| 9 |
| 10 | class SyntaxHighlighter; |
| 11 |
| 12 | namespace prisma_android { |
| 13 |
| 14 | // One instance is used serially. PrismaHighlighter.java enforces this. |
| 15 | class Engine final { |
| 16 | public: |
| 17 | explicit Engine(std::string_view grammars); |
| 18 | ~Engine(); |
| 19 |
| 20 | Engine(const Engine&) = delete; |
| 21 | Engine& operator=(const Engine&) = delete; |
| 22 |
| 23 | // Each record is [UTF-16 start, exclusive end, type ID, alias ID, parent index]. |
| 24 | // Syntax nodes are emitted in preorder. Parent ranges may contain children. |
| 25 | // Name IDs reference tokenNames(); zero is the empty name, root parent is -1. |
| 26 | std::vector<int32_t> highlight(std::u16string_view text, std::u16string_view language); |
| 27 | std::vector<std::string> languages() const; |
| 28 | const std::vector<std::string>& tokenNames() const { return tokenNames_; } |
| 29 |
| 30 | private: |
| 31 | std::unique_ptr<SyntaxHighlighter> highlighter_; |
| 32 | std::vector<std::string> tokenNames_; |
| 33 | std::unordered_map<std::string, int32_t> tokenNameIds_; |
| 34 | }; |
| 35 |
| 36 | } // namespace prisma_android |
| 37 |