17#ifndef A11_FLOW_PATTERN_H_
18#define A11_FLOW_PATTERN_H_
112 [[nodiscard]]
bool AllNamed()
const;
123 [[nodiscard]]
bool ok()
const {
return error.empty(); }
138std::optional<std::vector<Capture>>
Match(
const Pattern& pattern,
std::optional< std::string > text
The text, where the value is a string literal or a name bound to one.
Definition discover.cc:612
std::optional< std::vector< Capture > > Match(const Pattern &pattern, std::string_view subject)
Match pattern anywhere in subject, taking the earliest fit.
Definition pattern.cc:443
Compiled Compile(std::string_view text)
Compile a pattern, saying what is wrong rather than throwing.
Definition pattern.cc:333
std::optional< HoleType > HoleTypeFromName(std::string_view name)
The type that name spells, or nothing where it is not one of them.
Definition pattern.cc:309
HoleType
The pattern language match reads: literal text and named holes.
Definition pattern.h:59
@ kBool
true or false, in either case.
@ kString
Anything up to the next literal, on one line. The default.
@ kJson
Text to be read as JSON.
@ kInt
A whole number, with an optional sign.
@ kWord
A run of anything that is not whitespace.
@ kTime
Text to be read as an instant: RFC 3339, or a bare date.
@ kNumber
A number, with an optional sign and fraction.
@ kDuration
Text to be read as a duration: 250ms, 1m30s.
@ kRest
Everything left, line breaks and all. Only as the last piece.
@ kLine
The rest of the line.
std::string_view HoleTypeName(HoleType type)
Definition pattern.cc:283
std::string subject
What to call it in the message: ‘'Source’, orthe pattern`.
Definition resolve.cc:3580
What one hole took: a view into the subject that was matched.
Definition pattern.h:130
std::string_view text
Definition pattern.h:131
A pattern, or what is wrong with the text it was written as.
Definition pattern.h:116
size_t column
Where the problem is, counting characters from the start of the pattern.
Definition pattern.h:121
bool ok() const
Definition pattern.h:123
std::string error
Empty when it compiled. Otherwise what is wrong, as a sentence.
Definition pattern.h:119
Pattern pattern
Definition pattern.h:117
One capture position in a pattern.
Definition pattern.h:88
HoleType type
Definition pattern.h:91
std::string name
The field it fills. Empty for {}, which is read by position.
Definition pattern.h:90
size_t position
Which hole this is, counting from zero, which is what {} is read by.
Definition pattern.h:93
Hole hole
Definition pattern.h:103
std::string literal
The literal's text. A run of whitespace in it matches any run.
Definition pattern.h:102
bool is_hole
A hole when true, and otherwise a literal to match.
Definition pattern.h:100
A compiled pattern: literals and holes, in the order they were written.
Definition pattern.h:97
bool AllNamed() const
Whether every hole has a name, which is what makes the result a record with fields rather than one re...
Definition pattern.cc:324
std::vector< Hole > holes
Every hole, in order. What a shape is built from.
Definition pattern.h:108
std::vector< Piece > pieces
Definition pattern.h:106