Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
canonical_decoding.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//canonical_decoding.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//canonical_decoding.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 canonical_decoding.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
39
40#pragma once
41
42#include <cstddef>
43#include <memory>
44#include <string>
45#include <string_view>
46#include <vector>
47
49
50namespace bertini {
51namespace node {
52
63{
64public:
66 explicit DecodingCursor(std::string const& text) : text_(text), pos_(0) {}
67
69 bool AtEnd() const { return pos_ >= text_.size(); }
70
72 std::size_t Offset() const { return pos_; }
73
75 char Peek() const;
76
78 void Expect(char c);
79
81 void Expect(std::string_view lit);
82
84 bool TryConsume(char c);
85
88
90 std::string ReadWord();
91
93 std::string ReadNetstring();
94
96 unsigned long long ReadUnsigned();
97
99 long long ReadInt();
100
102 [[noreturn]] void Fail(std::string const& what) const;
103
104private:
105 std::string const& text_;
106 std::size_t pos_;
107};
108
118{
120 std::vector<std::shared_ptr<Node>> by_index;
121};
122
134std::shared_ptr<Node> DecodeCanonical(DecodingCursor& cursor, DecodingContext& ctx);
135
144std::shared_ptr<Node> DecodeCanonicalTree(std::string const& text);
145
146} // namespace node
147} // namespace bertini
A read position over one canonical-encoding text, with the small lexical helpers the grammar needs (l...
Definition canonical_decoding.hpp:63
DecodingCursor(std::string const &text)
Start reading text from its first byte.
Definition canonical_decoding.hpp:66
std::string ReadNetstring()
Read a netstring name: <byte-length>:<bytes>.
bool TryConsume(char c)
Consume c if it is next; report whether it was.
void Expect(std::string_view lit)
Consume exactly the literal lit, or throw.
void SkipWhitespace()
Skip any run of spaces and newlines.
bool AtEnd() const
Whether every byte has been consumed.
Definition canonical_decoding.hpp:69
void Fail(std::string const &what) const
Throw std::runtime_error describing what at the current position.
void Expect(char c)
Consume exactly the character c, or throw.
std::size_t Offset() const
The byte offset of the next unread character.
Definition canonical_decoding.hpp:72
char Peek() const
The next unread character (throws at end of text).
unsigned long long ReadUnsigned()
Read a non-negative decimal integer.
long long ReadInt()
Read a decimal integer with an optional sign.
std::string ReadWord()
Read a maximal run of characters that are not whitespace or a parenthesis.
Definition canonical.hpp:56
std::shared_ptr< Node > DecodeCanonical(DecodingCursor &cursor, DecodingContext &ctx)
Decode one node (and everything under it) from the cursor's position.
std::shared_ptr< Node > DecodeCanonicalTree(std::string const &text)
Decode a whole tree from its canonical encoding text (fresh context).
Definition algorithm_builder.hpp:36
Defines the abstract Node base class.
The back-reference table of one decoding pass: the nodes in first-encounter order,...
Definition canonical_decoding.hpp:118
std::vector< std::shared_ptr< Node > > by_index
The node numbered by each index, in encounter order.
Definition canonical_decoding.hpp:120