Tinkering with gperf options

This commit is contained in:
2025-08-17 10:23:10 -04:00
parent ce9d7db277
commit 6775276e73
2 changed files with 11 additions and 9 deletions

View File

@@ -1,5 +1,8 @@
#pragma once #pragma once
#include "json_tokens.hpp"
#include <string_view>
enum class JsonTokenType { enum class JsonTokenType {
Unknown = 0, Unknown = 0,
Preconditions = 1, Preconditions = 1,
@@ -20,14 +23,11 @@ enum class JsonTokenType {
RangeDelete = 16 RangeDelete = 16
}; };
#include "json_tokens.hpp"
#include <string_view>
inline JsonTokenType get_json_token_type(std::string_view str) { inline JsonTokenType get_json_token_type(std::string_view str) {
const JsonToken *token = const JsonToken *token =
Perfect_Hash::lookup_json_token(str.data(), str.size()); Perfect_Hash::lookup_json_token(str.data(), str.size());
if (token && token->name[0] != '\0') { // Check that we got a valid token if (token) {
return static_cast<JsonTokenType>(token->token_id); return static_cast<JsonTokenType>(token->token_id);
} }
return JsonTokenType::Unknown; return JsonTokenType::Unknown;
} }

View File

@@ -3,11 +3,13 @@
%} %}
%define hash-function-name hash_json_token %define hash-function-name hash_json_token
%define lookup-function-name lookup_json_token %define lookup-function-name lookup_json_token
%language=C++
%global-table
%struct-type
%readonly-tables
%compare-lengths %compare-lengths
%global-table
%language=C++
%null-strings
%readonly-tables
%struct-type
%switch=1
struct JsonToken { struct JsonToken {
const char* name; const char* name;