Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
system_parsers.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//bertini2/io/parsers.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//bertini2/io/parsing/system_parsers.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with bertini2/io/parsing/system_parsers.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22
28
29#pragma once
30
31
32
33
35
36
37
38namespace bertini {
39 namespace parsing {
40
41 namespace classic {
42
43
44
46 template <typename Iterator>
47 static bool parse(Iterator first, Iterator last, System& sys)
48 {
49 using boost::spirit::qi::double_;
50 using boost::spirit::qi::_1;
51 using boost::spirit::qi::phrase_parse;
52 using boost::spirit::ascii::space;
53 using boost::phoenix::ref;
54
56
57 System s{};
58 bool r = phrase_parse(first, last,
59 S,
60 space,
61 s);
62
63 if (!r || first != last) // fail if we did not get a full match
64 return false;
65
66 // every definition has now filled its function box: emit the bare entries.
68 sys = s;
69 return r;
70 }
71
72 } // re: namespace classic
73
74 }// re: namespace parsing
75
76 inline
77 System::System(std::string const& input)
78 {
79 System sys;
80
82
83 // Treat the input as UTF-8; drop a leading BOM so it is not seen as a
84 // stray leading character by the grammar.
85 std::string cleaned = input;
87 // comments first (a commented-out INPUT or END; must not fool the unwrapping), then
88 // accept a full Bertini 1 classic file (CONFIG/INPUT wrappers), not just the bare
89 // INPUT-section body that the grammar reads -- see #407 and #396
92
93 std::string::const_iterator iter = cleaned.begin();
94 std::string::const_iterator end = cleaned.end();
95
96 bool s = phrase_parse(iter, end, S,boost::spirit::ascii::space, sys);
97
98 if (!s || iter!=end)
99 {
100 std::string remaining(iter, end);
101 if (remaining.size() > 60)
102 remaining = remaining.substr(0, 60) + "...";
103 if (remaining.empty())
104 remaining = "<end of input>";
105 throw std::runtime_error(
106 "[SystemParser] parser did not consume entire input; "
107 "unparsed remainder: \"" + remaining + "\"");
108 }
109
110 // every definition has now filled its function box: emit the bare entries.
112
113 using std::swap;
114 swap(sys,*this);
115 }
116
117}// re: namespace bertini
The fundamental polynomial system class for Bertini2.
Definition system.hpp:106
friend void swap(System &a, System &b)
The free swap function for systems.
System()
The default constructor for a system.
Definition system.hpp:117
Definition classic_utilities.hpp:41
void StripUTF8BOM(std::string &s)
Strip a leading UTF-8 byte-order mark (EF BB BF) from s in place, if present.
Definition qi_files.hpp:74
void StripClassicComments(std::string &s)
Remove Bertini 1 comments from s in place: everything from a % to the end of its line.
Definition qi_files.hpp:91
void StripClassicFileWrappers(std::string &s)
Unwrap a Bertini 1 classic input FILE down to the declarations the grammar reads.
Definition qi_files.hpp:125
bool parse(Iterator first, Iterator last, std::shared_ptr< bertini::node::Node > &func)
Parse a function expression from the iterator range into a node tree.
Definition function_parsers.hpp:46
Definition classic_utilities.hpp:40
Definition algorithm_builder.hpp:36
Qi Parser object for parsing text into the System class.
Definition system_rules.hpp:79
void EmitDeclaredFunctions(System &s) const
Emit the collected declared functions/constants/parameters to the System.
Definition system_rules.hpp:428
Provides the parsing rules for systems in bertini2.