A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
a11::flow::pattern Namespace Reference

Classes

struct  Capture
 What one hole took: a view into the subject that was matched. More...
 
struct  Compiled
 A pattern, or what is wrong with the text it was written as. More...
 
struct  Hole
 One capture position in a pattern. More...
 
struct  Pattern
 A compiled pattern: literals and holes, in the order they were written. More...
 

Enumerations

enum class  HoleType {
  kString , kInt , kNumber , kBool ,
  kWord , kLine , kRest , kDuration ,
  kTime , kJson
}
 The pattern language match reads: literal text and named holes. More...
 

Functions

std::string_view HoleTypeName (HoleType type)
 
std::optional< HoleType > HoleTypeFromName (std::string_view name)
 The type that name spells, or nothing where it is not one of them.
 
Compiled Compile (std::string_view text)
 Compile a pattern, saying what is wrong rather than throwing.
 
std::optional< std::vector< Capture > > Match (const Pattern &pattern, std::string_view subject)
 Match pattern anywhere in subject, taking the earliest fit.
 

Enumeration Type Documentation

◆ HoleType

enum class a11::flow::pattern::HoleType
strong

The pattern language match reads: literal text and named holes.

Why not a regular expression. A flow is text somebody writes in the moment, often a model, and the thing being written is almost always "this line, with these bits pulled out of it". Regex answers that with name.*=.*(?<name>[^ ]+)\s+age.*=.*(?<age>\d+), which is unreadable at a glance and wrong in three ways before it is right. The same intent here is name={name} age={age:int}, and there is nothing to escape.

In the pattern Means
literal text matches itself
a run of whitespace matches any run of whitespace, at least one
{name} captures up to whatever literal follows, as little as it can
{name:int} and reads it as an integer
{} captures without a name, read as it[0], it[1], ...
{{, }} a literal brace

The pattern searches: it matches anywhere in the value, so match("age={age:int}", line) works on a longer line without leading and trailing wildcards. A hole captures at least one character and does not cross a line break unless its type says to.

This half knows nothing about [Value]: it compiles a pattern, says what its holes are called, and hands back the text each one took. Reading that text as a number, an instant or a duration is the value layer's job, and keeping the split is what lets the resolver ask a pattern for its field names without the runtime being linked in. What a hole reads its text as, and how much of it a hole may take.

Enumerator
kString 

Anything up to the next literal, on one line. The default.

kInt 

A whole number, with an optional sign.

kNumber 

A number, with an optional sign and fraction.

kBool 

true or false, in either case.

kWord 

A run of anything that is not whitespace.

kLine 

The rest of the line.

kRest 

Everything left, line breaks and all. Only as the last piece.

kDuration 

Text to be read as a duration: 250ms, 1m30s.

kTime 

Text to be read as an instant: RFC 3339, or a bare date.

kJson 

Text to be read as JSON.

Function Documentation

◆ Compile()

Compiled a11::flow::pattern::Compile ( std::string_view  text)

Compile a pattern, saying what is wrong rather than throwing.

◆ HoleTypeFromName()

std::optional< HoleType > a11::flow::pattern::HoleTypeFromName ( std::string_view  name)

The type that name spells, or nothing where it is not one of them.

◆ HoleTypeName()

std::string_view a11::flow::pattern::HoleTypeName ( HoleType  type)

◆ Match()

std::optional< std::vector< Capture > > a11::flow::pattern::Match ( const Pattern &  pattern,
std::string_view  subject 
)

Match pattern anywhere in subject, taking the earliest fit.

Nothing when it does not fit at all, which is how a stage knows to drop the value and a function knows to answer null.