aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2020-02-09 14:50:26 -0800
committerGitHub <noreply@github.com>2020-02-09 14:50:26 -0800
commita33044c18637d3df6de93128d33dae1fb5ba575c (patch)
tree273838dd27daed933e63bc7d29a28b569557755f /toolsrc/include
parent039098c9546195a50e45c41e37d7e2b9168b4245 (diff)
downloadvcpkg-a33044c18637d3df6de93128d33dae1fb5ba575c.tar.gz
vcpkg-a33044c18637d3df6de93128d33dae1fb5ba575c.zip
[vcpkg] Track parser row/col state in Paragraph (renamed from RawParagraph) (#9987)
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/vcpkg-test/util.h12
-rw-r--r--toolsrc/include/vcpkg/binaryparagraph.h2
-rw-r--r--toolsrc/include/vcpkg/paragraphparser.h20
-rw-r--r--toolsrc/include/vcpkg/paragraphs.h8
-rw-r--r--toolsrc/include/vcpkg/parse.h33
-rw-r--r--toolsrc/include/vcpkg/sourceparagraph.h2
-rw-r--r--toolsrc/include/vcpkg/statusparagraph.h2
7 files changed, 42 insertions, 37 deletions
diff --git a/toolsrc/include/vcpkg-test/util.h b/toolsrc/include/vcpkg-test/util.h
index d8ecc51ea..c15846d05 100644
--- a/toolsrc/include/vcpkg-test/util.h
+++ b/toolsrc/include/vcpkg-test/util.h
@@ -23,6 +23,18 @@ namespace vcpkg::Test
const std::vector<std::pair<const char*, const char*>>& features = {},
const std::vector<const char*>& default_features = {});
+ inline auto test_parse_control_file(const std::vector<std::unordered_map<std::string, std::string>>& v)
+ {
+ std::vector<vcpkg::Parse::Paragraph> pghs;
+ for (auto&& p : v)
+ {
+ pghs.emplace_back();
+ for (auto&& kv : p)
+ pghs.back().emplace(kv.first, std::make_pair(kv.second, vcpkg::Parse::TextRowCol{}));
+ }
+ return vcpkg::SourceControlFile::parse_control_file("", std::move(pghs));
+ }
+
std::unique_ptr<vcpkg::StatusParagraph> make_status_pgh(const char* name,
const char* depends = "",
const char* default_features = "",
diff --git a/toolsrc/include/vcpkg/binaryparagraph.h b/toolsrc/include/vcpkg/binaryparagraph.h
index 05c42dee4..edb2b6a13 100644
--- a/toolsrc/include/vcpkg/binaryparagraph.h
+++ b/toolsrc/include/vcpkg/binaryparagraph.h
@@ -12,7 +12,7 @@ namespace vcpkg
struct BinaryParagraph
{
BinaryParagraph();
- explicit BinaryParagraph(Parse::RawParagraph fields);
+ explicit BinaryParagraph(Parse::Paragraph fields);
BinaryParagraph(const SourceParagraph& spgh,
Triplet triplet,
const std::string& abi_tag,
diff --git a/toolsrc/include/vcpkg/paragraphparser.h b/toolsrc/include/vcpkg/paragraphparser.h
index 86c3d0228..cc4637402 100644
--- a/toolsrc/include/vcpkg/paragraphparser.h
+++ b/toolsrc/include/vcpkg/paragraphparser.h
@@ -2,6 +2,7 @@
#include <vcpkg/base/expected.h>
#include <vcpkg/packagespec.h>
+#include <vcpkg/textrowcol.h>
#include <memory>
#include <string>
@@ -21,25 +22,30 @@ namespace vcpkg::Parse
template<class P>
using ParseExpected = vcpkg::ExpectedT<std::unique_ptr<P>, std::unique_ptr<ParseControlErrorInfo>>;
- using RawParagraph = std::unordered_map<std::string, std::string>;
+ using Paragraph = std::unordered_map<std::string, std::pair<std::string, TextRowCol>>;
struct ParagraphParser
{
- ParagraphParser(RawParagraph&& fields) : fields(std::move(fields)) {}
+ ParagraphParser(Paragraph&& fields) : fields(std::move(fields)) {}
void required_field(const std::string& fieldname, std::string& out);
- std::string optional_field(const std::string& fieldname) const;
+ std::string optional_field(const std::string& fieldname);
+ void required_field(const std::string& fieldname, std::pair<std::string&, TextRowCol&> out);
+ void optional_field(const std::string& fieldname, std::pair<std::string&, TextRowCol&> out);
std::unique_ptr<ParseControlErrorInfo> error_info(const std::string& name) const;
private:
- RawParagraph&& fields;
+ Paragraph&& fields;
std::vector<std::string> missing_fields;
};
ExpectedS<std::vector<std::string>> parse_default_features_list(const std::string& str,
- CStringView origin = "<unknown>");
+ CStringView origin = "<unknown>",
+ TextRowCol textrowcol = {});
ExpectedS<std::vector<ParsedQualifiedSpecifier>> parse_qualified_specifier_list(const std::string& str,
- CStringView origin = "<unknown>");
+ CStringView origin = "<unknown>",
+ TextRowCol textrowcol = {});
ExpectedS<std::vector<Dependency>> parse_dependencies_list(const std::string& str,
- CStringView origin = "<unknown>");
+ CStringView origin = "<unknown>",
+ TextRowCol textrowcol = {});
}
diff --git a/toolsrc/include/vcpkg/paragraphs.h b/toolsrc/include/vcpkg/paragraphs.h
index cffe85af7..02e87a76d 100644
--- a/toolsrc/include/vcpkg/paragraphs.h
+++ b/toolsrc/include/vcpkg/paragraphs.h
@@ -8,11 +8,11 @@
namespace vcpkg::Paragraphs
{
- using RawParagraph = Parse::RawParagraph;
+ using Paragraph = Parse::Paragraph;
- ExpectedS<RawParagraph> get_single_paragraph(const Files::Filesystem& fs, const fs::path& control_path);
- ExpectedS<std::vector<RawParagraph>> get_paragraphs(const Files::Filesystem& fs, const fs::path& control_path);
- ExpectedS<std::vector<RawParagraph>> parse_paragraphs(const std::string& str, const std::string& origin);
+ ExpectedS<Paragraph> get_single_paragraph(const Files::Filesystem& fs, const fs::path& control_path);
+ ExpectedS<std::vector<Paragraph>> get_paragraphs(const Files::Filesystem& fs, const fs::path& control_path);
+ ExpectedS<std::vector<Paragraph>> parse_paragraphs(const std::string& str, const std::string& origin);
Parse::ParseExpected<SourceControlFile> try_load_port(const Files::Filesystem& fs, const fs::path& control_path);
diff --git a/toolsrc/include/vcpkg/parse.h b/toolsrc/include/vcpkg/parse.h
index 3214305bf..539bb2ed7 100644
--- a/toolsrc/include/vcpkg/parse.h
+++ b/toolsrc/include/vcpkg/parse.h
@@ -18,14 +18,20 @@ namespace vcpkg::Parse
struct ParseError : IParseError
{
- ParseError(std::string origin, int row, int column, std::string line, std::string message)
- : origin(std::move(origin)), row(row), column(column), line(std::move(line)), message(std::move(message))
+ ParseError(std::string origin, int row, int column, int caret_col, std::string line, std::string message)
+ : origin(std::move(origin))
+ , row(row)
+ , column(column)
+ , caret_col(caret_col)
+ , line(std::move(line))
+ , message(std::move(message))
{
}
const std::string origin;
const int row;
const int column;
+ const int caret_col;
const std::string line;
const std::string message;
@@ -105,27 +111,8 @@ namespace vcpkg::Parse
const char* it() const { return m_it; }
char cur() const { return *m_it; }
SourceLoc cur_loc() const { return {m_it, row, column}; }
- char next()
- {
- char ch = *m_it;
- // See https://www.gnu.org/prep/standards/standards.html#Errors
- if (ch == '\t')
- column = (column + 7) / 8 * 8 + 1; // round to next 8-width tab stop
- else if (ch == '\n')
- {
- row++;
- column = 1;
- }
- else if (ch == '\0')
- {
- return '\0';
- }
- else
- {
- ++column;
- }
- return *++m_it;
- }
+ TextRowCol cur_rowcol() const { return {row, column}; }
+ char next();
bool at_eof() const { return *m_it == 0; }
void add_error(std::string message) { add_error(std::move(message), cur_loc()); }
diff --git a/toolsrc/include/vcpkg/sourceparagraph.h b/toolsrc/include/vcpkg/sourceparagraph.h
index bdb75fc58..08c306abf 100644
--- a/toolsrc/include/vcpkg/sourceparagraph.h
+++ b/toolsrc/include/vcpkg/sourceparagraph.h
@@ -70,7 +70,7 @@ namespace vcpkg
}
static Parse::ParseExpected<SourceControlFile> parse_control_file(
- const fs::path& path_to_control, std::vector<Parse::RawParagraph>&& control_paragraphs);
+ const fs::path& path_to_control, std::vector<Parse::Paragraph>&& control_paragraphs);
std::unique_ptr<SourceParagraph> core_paragraph;
std::vector<std::unique_ptr<FeatureParagraph>> feature_paragraphs;
diff --git a/toolsrc/include/vcpkg/statusparagraph.h b/toolsrc/include/vcpkg/statusparagraph.h
index ec850607d..2c6d34865 100644
--- a/toolsrc/include/vcpkg/statusparagraph.h
+++ b/toolsrc/include/vcpkg/statusparagraph.h
@@ -30,7 +30,7 @@ namespace vcpkg
struct StatusParagraph
{
StatusParagraph() noexcept;
- explicit StatusParagraph(Parse::RawParagraph&& fields);
+ explicit StatusParagraph(Parse::Paragraph&& fields);
bool is_installed() const { return want == Want::INSTALL && state == InstallState::INSTALLED; }