-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiny_preproc.h
More file actions
37 lines (33 loc) · 934 Bytes
/
tiny_preproc.h
File metadata and controls
37 lines (33 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (C) 2019 smiley3 <ml.smiley3@gmail.com>
// SPDX-License-Identifier: GPL-2.0-or-later
#include <string>
#include <fstream>
#include <streambuf>
#include <map>
// ASCII codes allowed in var names
bool IS_ASCII_LETTER(char c)
{
// underscore and numbers
if (c == 95 || (c < 58 && c > 47))
return true;
if (c > 90)
c -= 32;
if (c < 65 || c > 90)
return false;
return true;
}
std::string openFile(const std::string& fileName)
{
std::ifstream ifs(fileName);
std::string content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
return content;
}
class CTinyPreprocessor
{
public:
std::string Preprocess(const std::string& code);
void AddDefines(const std::string& macroName, const std::string& macroValue);
private:
std::map<std::string, std::string> defines;
bool ExpandMacros(const std::string& word, std::string& out);
};