summaryrefslogtreecommitdiff
path: root/Source/cmVisualStudioSlnParser.h
blob: 8939ab55a106d0406bd8ecdee6a28ad67b0d9245 (plain)
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
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
#ifndef cmVisualStudioSlnParser_h
#define cmVisualStudioSlnParser_h

#include <cmConfigure.h>

#include "cmStandardIncludes.h"

#include <bitset>

class cmSlnData;

class cmVisualStudioSlnParser
{
public:
  enum ParseResult
  {
    ResultOK = 0,

    ResultInternalError = -1,
    ResultExternalError = 1,

    ResultErrorOpeningInput = ResultExternalError,
    ResultErrorReadingInput,
    ResultErrorInputStructure,
    ResultErrorInputData,

    ResultErrorBadInternalState = ResultInternalError,
    ResultErrorUnsupportedDataGroup = ResultInternalError - 1
  };

  enum DataGroup
  {
    DataGroupProjectsBit,
    DataGroupProjectDependenciesBit,
    DataGroupSolutionConfigurationsBit,
    DataGroupProjectConfigurationsBit,
    DataGroupSolutionFiltersBit,
    DataGroupGenericGlobalSectionsBit,
    DataGroupCount
  };

  typedef std::bitset<DataGroupCount> DataGroupSet;

  static const DataGroupSet DataGroupProjects;
  static const DataGroupSet DataGroupProjectDependencies;
  static const DataGroupSet DataGroupSolutionConfigurations;
  static const DataGroupSet DataGroupProjectConfigurations;
  static const DataGroupSet DataGroupSolutionFilters;
  static const DataGroupSet DataGroupGenericGlobalSections;
  static const DataGroupSet DataGroupAll;

  bool Parse(std::istream& input, cmSlnData& output,
             DataGroupSet dataGroups = DataGroupAll);

  bool ParseFile(const std::string& file, cmSlnData& output,
                 DataGroupSet dataGroups = DataGroupAll);

  ParseResult GetParseResult() const;

  size_t GetParseResultLine() const;

  bool GetParseHadBOM() const;

protected:
  class State;
  friend class State;
  class ParsedLine;

  struct ResultData
  {
    ParseResult Result;
    size_t ResultLine;
    bool HadBOM;

    ResultData();
    void Clear();
    void SetError(ParseResult error, size_t line);
  } LastResult;

  bool IsDataGroupSetSupported(DataGroupSet dataGroups) const;

  bool ParseImpl(std::istream& input, cmSlnData& output, State& state);

  bool ParseBOM(std::istream& input, std::string& line, State& state);

  bool ParseMultiValueTag(const std::string& line, ParsedLine& parsedLine,
                          State& state);

  bool ParseSingleValueTag(const std::string& line, ParsedLine& parsedLine,
                           State& state);

  bool ParseKeyValuePair(const std::string& line, ParsedLine& parsedLine,
                         State& state);

  bool ParseTag(const std::string& fullTag, ParsedLine& parsedLine,
                State& state);

  bool ParseValue(const std::string& value, ParsedLine& parsedLine);
};

#endif