-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmParser.h
More file actions
114 lines (101 loc) · 2.47 KB
/
cmParser.h
File metadata and controls
114 lines (101 loc) · 2.47 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Copyright (c) 2024 Yves W
* SPDX-License-Identifier: BSD-3-Clause
*
* This file is part of a project licensed under the BSD 3-Clause License.
* See the LICENSE file in the project root for full license text.
*/
#pragma once
#ifndef CMPARSER_CMPARSER_H
#define CMPARSER_CMPARSER_H
#endif // CMPARSER_CMPARSER_H
#include <algorithm>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#include "cmListFileLexer.h"
struct cmListFileArgument {
enum Delimiter {
Unquoted,
Quoted,
Bracket
};
cmListFileArgument() = default;
cmListFileArgument(std::string v, Delimiter d, long line)
: Value(std::move(v)), Delim(d), Line(line)
{
}
bool operator==(const cmListFileArgument &r) const
{
return (this->Value == r.Value) && (this->Delim == r.Delim);
}
bool operator!=(const cmListFileArgument &r) const
{
return !(*this == r);
}
std::string Value;
Delimiter Delim = Unquoted;
long Line = 0;
};
class cmListFileFunction
{
public:
cmListFileFunction(std::string name, long line, long lineEnd,
std::vector<cmListFileArgument> args)
: Impl{std::make_shared<Implementation>(std::move(name), line, lineEnd,
std::move(args))}
{
}
std::string const &OriginalName() const noexcept
{
return this->Impl->OriginalName;
}
long Line() const noexcept
{
return this->Impl->Line;
}
long LineEnd() const noexcept
{
return this->Impl->LineEnd;
}
std::vector<cmListFileArgument> const &Arguments() const noexcept
{
return this->Impl->Arguments;
}
private:
struct Implementation {
Implementation(std::string name, long line, long lineEnd,
std::vector<cmListFileArgument> args)
: OriginalName{std::move(name)}, Line{line}, LineEnd{lineEnd},
Arguments{std::move(args)}
{
}
std::string OriginalName;
long Line = 0;
long LineEnd = 0;
std::vector<cmListFileArgument> Arguments;
};
std::shared_ptr<Implementation const> Impl;
};
struct cmListFileParser {
cmListFileParser();
~cmListFileParser();
bool ParseFile(const char *filename);
bool Parse();
bool ParseFunction(const char *name, long line);
bool AddArgument(cmListFileLexer_Token *token, cmListFileArgument::Delimiter delim);
std::vector<cmListFileFunction> Functions;
const char *FileName = nullptr;
cmListFileLexer *Lexer;
std::string FunctionName;
long FunctionLine;
long FunctionLineEnd;
std::vector<cmListFileArgument> FunctionArguments;
enum {
SeparationOkay,
SeparationWarning,
SeparationError
} Separation;
};