Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
LhaParser.h
Go to the documentation of this file.
1#ifndef HYPERISO_LHA_READER_H
2#define HYPERISO_LHA_READER_H
3
4#include <string>
5#include <map>
6#include <memory>
7#include <filesystem>
8#include <climits>
9#include <regex>
10#include <fstream>
11#include <sstream>
12#include <vector>
13#include <algorithm>
14#include <unordered_set>
15#include <iomanip>
16
17#include "Include.h"
18#include "LhaBlockPrototype.h"
19#include "IParser.h"
20#include "lha_blocks.h"
21#include "lha_elements.h"
22#include "Logger.h"
23#include "DBNode.h"
24
47enum class TokenType {
48 FLOAT,
49 INTEGER,
50 BLOCK,
51 DECAY,
52 NEWLINE,
53 SKIP,
54 COMMENT,
55 WORD,
56 OTHER
57};
58
78const std::regex analyzer_rx(
79 R"x(((?:[+-])?(?:\d+\.\d*|\.\d+)(?:[eEdD][+-]\d+)?|(\d+(?:[eEdD][+-]\d+)?))|(?:[+-]?\d+(?!\.))|(block)|(decay)|(\n)|([ \t]+)|(#.*)|([\w\=\.]+)|([^#]*))x",
80 std::regex_constants::icase
81);
82
92struct Token {
94 std::string value;
95 int row;
96 int col;
97};
98
113class LhaParser : public IParser {
114private:
115 std::unordered_set<Prototype> blockPrototypes;
126 void fill_prototypes(std::string_view lha_path);
127
139 std::vector<Token> tokenize(const std::string& src) const;
140
155 std::map<BlockName, std::vector<std::vector<std::string>>> parse_tokens(std::vector<Token> tokens, bool comments = false) const;
156
171 void addBlock(std::map<BlockName, std::shared_ptr<LhaBlock>>& blocks, const BlockName& id, const std::vector<std::vector<std::string>>& lines) const;
172
184 Prototype findPrototype(BlockName name) const;
185
198 std::shared_ptr<DBNode> toDBNode(std::map<BlockName, std::shared_ptr<LhaBlock>> blocks) const;
199
200public:
213 std::shared_ptr<DBNode> readFromFile(const std::string& input_file) const override;
214
229 std::shared_ptr<DBNode> parse(const std::string& src) const override;
230
241 void writeToFile(const std::string& filename, const std::shared_ptr<DBNode>& root) const;
242
254 void set_prototypes(const std::unordered_set<Prototype>& prototypes);
255};
256
257#endif // HYPERISO_LHA_READER_H
Hierarchical key–value tree with JSON/YAML serialization.
Abstract interface for (de)serializing data as DBNode trees.
const std::regex analyzer_rx(R"x(((?:[+-])?(?:\d+\.\d*|\.\d+)(?:[eEdD][+-]\d+)?|(\d+(?:[eEdD][+-]\d+)?))|(?:[+-]?\d+(?!\.))|(block)|(decay)|(\n)|([ \t]+)|(#.*)|([\w\=\.]+)|([^#]*))x", std::regex_constants::icase)
TokenType
Token categories used during LHA lexical analysis.
Definition LhaParser.h:47
Block identifier with alias support.
Definition BlockName.h:59
Abstract base class for data parsers.
Definition IParser.h:30
Parser for LHA/FLHA files, producing blocks and a DBNode representation.
Definition LhaParser.h:113
std::shared_ptr< DBNode > readFromFile(const std::string &input_file) const override
Parses an LHA/FLHA file from disk and returns its DBNode representation.
void writeToFile(const std::string &filename, const std::shared_ptr< DBNode > &root) const
Serializes a DBNode structure back to an LHA-like file.
std::shared_ptr< DBNode > parse(const std::string &src) const override
Parses LHA/FLHA content from an in-memory string.
void set_prototypes(const std::unordered_set< Prototype > &prototypes)
Sets the set of block prototypes used by the parser.
Representation of a single LHA/FLHA block and its entries.
Represents the structure of an LHA block, specifying columns for values, scales, and renormalization ...
Single lexical token produced from an LHA file.
Definition LhaParser.h:92
std::string value
Definition LhaParser.h:94
int row
Definition LhaParser.h:95
TokenType type
Definition LhaParser.h:93
int col
Definition LhaParser.h:96