BEEP-8 Helper Lib 1.0.0
Loading...
Searching...
No Matches
tokenizer.h
Go to the documentation of this file.
1
31#include <cstr.h>
32#include <vector>
33#include <map>
34
39struct Macro{
40 const char* _key;
41 const char* _data;
42};
43
48struct MacroDict {
49 std::map< str8 , const char* , cmp_str > _dict;
50
54 void DumpAll() const;
55
62 const char* Get(const char* key) const;
63
70 MacroDict(size_t num_of_macro, const Macro* macros);
71};
72
78public:
81
85 void Clear(){
86 _lhs.clear();
87 _rhs.clear();
88 }
89};
90
105 enum State {
106 STS_LHS,
107 STS_RHS
108 };
109 std::vector< CFormula > _formulas;
110public:
118 str16 GetString(const char* lhs_, const char* def_ = "");
119
127 s32 GetNumber(const char* lhs_, s32 def_ = 0);
128
135 CTokenizer(const char* sz, const MacroDict* dict_ = nullptr);
136};
Class representing a formula with a left-hand side (LHS) and a right-hand side (RHS).
Definition tokenizer.h:77
str16 _lhs
The left-hand side of the formula.
Definition tokenizer.h:79
void Clear()
Clear the contents of the formula.
Definition tokenizer.h:85
str16 _rhs
The right-hand side of the formula.
Definition tokenizer.h:80
A tokenizer class for handling comma-separated equations.
Definition tokenizer.h:104
s32 GetNumber(const char *lhs_, s32 def_=0)
Get the right-hand side number associated with a left-hand side key.
Definition tokenizer.cpp:38
CTokenizer(const char *sz, const MacroDict *dict_=nullptr)
Constructor to initialize the tokenizer with a string of equations and an optional macro dictionary.
Definition tokenizer.cpp:49
str16 GetString(const char *lhs_, const char *def_="")
Get the right-hand side string associated with a left-hand side key.
Definition tokenizer.cpp:28
Module for managing fixed-size strings.
A dictionary for storing and retrieving macros.
Definition tokenizer.h:48
void DumpAll() const
Dump all macros to the console.
Definition tokenizer.cpp:4
MacroDict(size_t num_of_macro, const Macro *macros)
Constructor to initialize the dictionary with macros.
Definition tokenizer.cpp:22
std::map< str8, const char *, cmp_str > _dict
Internal storage for macros.
Definition tokenizer.h:49
const char * Get(const char *key) const
Get the value associated with a macro key.
Definition tokenizer.cpp:12
Structure representing a macro with a key-value pair.
Definition tokenizer.h:39
const char * _data
The value associated with the macro key.
Definition tokenizer.h:41
const char * _key
The key of the macro.
Definition tokenizer.h:40