Team Ai
Apppublic

Xenobd/whisper.cpp

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
grammar-parser.h30 linesDownload Raw Back to examples
1// Implements a parser for an extended Backus-Naur form (BNF), producing the2// binary context-free grammar format specified by whisper.h. Supports character3// ranges, grouping, and repetition operators. As an example, a grammar for4// arithmetic might look like:5//6// root  ::= expr7// expr  ::= term ([-+*/] term)*8// term  ::= num | "(" space expr ")" space9// num   ::= [0-9]+ space10// space ::= [ \t\n]*11 12#pragma once13#include "whisper.h"14#include <vector>15#include <map>16#include <cstdint>17#include <string>18 19namespace grammar_parser {20    struct parse_state {21        std::map<std::string, uint32_t>                   symbol_ids;22        std::vector<std::vector<whisper_grammar_element>> rules;23 24        std::vector<const whisper_grammar_element *>      c_rules() const;25    };26 27    parse_state parse(const char * src);28    void print_grammar(FILE * file, const parse_state & state);29}30