17#ifndef A11_FLOW_SYNTAX_H_
18#define A11_FLOW_SYNTAX_H_
29#include <absl/time/time.h>
69 [[nodiscard]]
bool Empty()
const {
return text.empty(); }
99 std::vector<std::pair<std::string, Constant>>
pairs;
110 [[nodiscard]]
double AsDouble()
const;
139 [[nodiscard]] std::string
ToString()
const;
228 if (
node ==
nullptr ||
node->kind != T::kNodeKind) {
233 return static_cast<const T*
>(
node);
238 if (
node ==
nullptr ||
node->kind != T::kNodeKind) {
243 return static_cast<T*
>(
node);
247bool IsAnyOf(
const Node*
node, std::initializer_list<NodeKind> kinds);
284 std::vector<std::pair<std::string, NodePtr>>
pairs;
459 std::vector<std::pair<std::string, NodePtr>>
headers;
522 static const Word kNone;
669 static const Word kNone;
776 std::vector<PortDeclarationPtr>
ports;
858 const std::function<
void(
const Node&)>& visit);
873 const std::function<
void(
const Node&)>& visit);
std::string value
Definition discover.cc:114
Location LocationOf(const Token &token)
The location a token occupies.
Definition syntax.cc:29
std::string_view PortDirectionName(PortDirection direction)
"inputs" or "outputs".
Definition syntax.cc:229
std::unique_ptr< DtoDeclaration > DtoDeclarationPtr
Definition syntax.h:835
std::optional< Constant > ConstantValue(const Node *node)
The constant node folds to, or nullopt where it is not one all the way down.
Definition syntax.cc:251
void VisitSubtree(const Node &node, const std::function< void(const Node &)> &visit)
Every node of the subtree rooted at node, node itself included.
Definition syntax.cc:546
std::unique_ptr< Pipeline > PipelinePtr
Definition syntax.h:436
std::unique_ptr< FlowDeclaration > FlowDeclarationPtr
Definition syntax.h:781
void VisitChildren(const Node &node, const std::function< void(const Node &)> &visit)
Every node node directly holds, in the order they were written.
Definition syntax.cc:306
std::unique_ptr< CallModifiers > CallModifiersPtr
Definition syntax.h:465
bool IsAnyOf(const Node *node, std::initializer_list< NodeKind > kinds)
Whether a node is one of the kinds given.
Definition syntax.cc:222
std::unique_ptr< HeaderDeclaration > HeaderDeclarationPtr
Definition syntax.h:755
PortDirection
Which side of the descriptor a port lands on, spelled as the plan spells it.
Definition syntax.h:728
std::unique_ptr< PortDeclaration > PortDeclarationPtr
Definition syntax.h:744
std::unique_ptr< Stage > StagePtr
Definition syntax.h:428
std::optional< std::string > DottedName(const Node *node)
a11.sdk.AudioBuffer for a chain of plain names, or nullopt.
Definition syntax.cc:558
std::string_view ConstantKindName(Constant::Kind kind)
The spelling of a constant's kind in the output formats.
Definition syntax.cc:87
std::unique_ptr< CallExpression > CallExpressionPtr
Definition syntax.h:484
std::unique_ptr< Node > NodePtr
Definition syntax.h:211
std::unique_ptr< FieldDeclaration > FieldDeclarationPtr
Definition syntax.h:821
const T * As(const Node *node)
node as a T, or nullptr if it is something else.
Definition syntax.h:227
NodeKind
What a node is. One per construct, mirroring a11/flow/syntax.py.
Definition syntax.h:143
@ kError
Something the parser could not read.
std::string_view NodeKindName(NodeKind kind)
The name of a node kind in the output formats, in kebab case.
Definition syntax.cc:124
StageArgument
What a stage takes after its name.
Definition vocabulary.h:51
@ kNone
Nothing: | collect, | count.
absl::Duration Duration
A11 duration; an alias of absl::Duration (nanosecond-aware).
Definition time.h:40
graph::RefId node
The graph ref this answer corresponds to, when a graph is being built.
Definition resolve.cc:698
One token: what it is, where it is, and what it holds.
Definition token.h:87
abort node [code] [message] – end a node with a failure.
Definition syntax.h:629
NodePtr message
Definition syntax.h:632
std::vector< Word > after
Definition syntax.h:633
NodePtr target
Definition syntax.h:630
NodePtr code
Definition syntax.h:631
advance name – rebind a let value to the next value of its stream.
Definition syntax.h:542
Word name
Definition syntax.h:543
base.name – a call's port, or a key of a value.
Definition syntax.h:305
NodePtr base
Definition syntax.h:306
std::string name
Definition syntax.h:307
left op right for and or == != < <= > >= in + -.
Definition syntax.h:352
NodePtr left
Definition syntax.h:354
std::string op
Definition syntax.h:353
NodePtr right
Definition syntax.h:355
name = ... – a step the rest of the flow can refer to.
Definition syntax.h:489
Word name
Definition syntax.h:490
NodePtr value
Definition syntax.h:491
[try] { ... } – a block of statements that runs as one thing.
Definition syntax.h:534
bool tolerant
Definition syntax.h:535
std::vector< NodePtr > body
Definition syntax.h:536
name(arg, ...) – one of the language's fixed functions.
Definition syntax.h:317
std::vector< NodePtr > args
Definition syntax.h:319
std::string name
Definition syntax.h:318
One argument: the port named, where it was named, and what feeds it.
Definition syntax.h:470
Word port
Definition syntax.h:471
PipelinePtr pipeline
Definition syntax.h:472
run/call action(port: pipeline, ...) and its modifiers.
Definition syntax.h:468
std::string mode
The verb written: "run" for the handler registered here, "call" for the stream this flow is attached ...
Definition syntax.h:478
std::vector< Argument > args
Definition syntax.h:479
std::string action
Definition syntax.h:475
bool tolerant
Definition syntax.h:481
CallModifiersPtr modifiers
Definition syntax.h:480
The tee/via/timeout/after/with/id/forward tail of a call.
Definition syntax.h:454
std::vector< Word > after
Definition syntax.h:458
std::vector< std::string > forward
Header names, or * patterns, that forward headers names.
Definition syntax.h:462
bool tee
Definition syntax.h:455
NodePtr action_id
Definition syntax.h:460
Word node_map
Definition syntax.h:456
std::vector< std::pair< std::string, NodePtr > > headers
Definition syntax.h:459
std::optional< absl::Duration > timeout
Definition syntax.h:457
A call whose outputs nobody names (they are drained for it).
Definition syntax.h:547
CallExpressionPtr call
Definition syntax.h:548
cancel name – ask a called action to stop, cooperatively.
Definition syntax.h:619
Word name
Definition syntax.h:620
std::vector< Word > after
Definition syntax.h:621
name <- pipeline – what the next pass of a repeat carries.
Definition syntax.h:692
PipelinePtr pipeline
Definition syntax.h:694
Word name
Definition syntax.h:693
A value the language can write out in full: what a literal is, and what folding a literal expression ...
Definition syntax.h:80
std::vector< std::pair< std::string, Constant > > pairs
Definition syntax.h:99
static Constant Null()
Definition syntax.h:101
std::vector< Constant > items
Definition syntax.h:98
Kind
Definition syntax.h:81
double AsDouble() const
The number this holds, whichever way it was written.
Definition syntax.cc:74
static Constant Double(double value)
Definition syntax.cc:53
double number
Definition syntax.h:95
static Constant Bool(bool value)
Definition syntax.cc:38
static Constant String(std::string value)
Definition syntax.cc:60
absl::Duration duration
Definition syntax.h:97
std::string text
Definition syntax.h:96
static Constant Integer(long long value)
Definition syntax.cc:45
Kind kind
Definition syntax.h:92
long long integer
Definition syntax.h:94
_ – the destination that keeps nothing.
Definition syntax.h:297
drain target – hold until a node's writers are done and its buffer has landed.
Definition syntax.h:613
std::vector< Word > after
Definition syntax.h:615
NodePtr target
Definition syntax.h:614
One struct name { ... } declaration: a shape a port may be typed with.
Definition syntax.h:829
std::vector< FieldDeclarationPtr > fields
Definition syntax.h:832
Word name
Definition syntax.h:830
std::string description
Definition syntax.h:831
A place the parser wanted a value and did not find one.
Definition syntax.h:252
std::string expected
What was expected there, for a formatter deciding to leave it alone.
Definition syntax.h:254
fail [code] [message] – end the flow with a status.
Definition syntax.h:637
NodePtr message
Definition syntax.h:639
std::vector< Word > after
Definition syntax.h:640
NodePtr code
Definition syntax.h:638
One name: type [modifiers] ["description"] field of a struct.
Definition syntax.h:799
bool unique
unique: no two items of a list are equal.
Definition syntax.h:806
Constant default_value
default ..: what a value that was not given is.
Definition syntax.h:816
bool required
Whether a value has to be given.
Definition syntax.h:804
bool has_pattern
Definition syntax.h:811
bool has_enumeration
Definition syntax.h:814
std::string pattern
matching "...": the pattern every value has to match, unanchored, as JSONSchema's pattern is.
Definition syntax.h:810
std::string description
Definition syntax.h:818
FieldRange range
Definition syntax.h:807
std::vector< Constant > enumeration
one of [..]: the only values allowed.
Definition syntax.h:813
Word name
Definition syntax.h:800
bool has_default
Definition syntax.h:817
TypeExpression type
Definition syntax.h:801
A bound on a field: 1..200, 1.., ..200.
Definition syntax.h:789
Constant maximum
Definition syntax.h:793
bool Empty() const
Definition syntax.h:795
bool has_minimum
Definition syntax.h:790
bool has_maximum
Definition syntax.h:791
Constant minimum
Definition syntax.h:792
One flow name { ... } declaration, or the one flow { ... } entry point.
Definition syntax.h:758
std::string description
Definition syntax.h:775
std::vector< PortDeclarationPtr > ports
Definition syntax.h:776
std::vector< HeaderDeclarationPtr > headers
Definition syntax.h:777
std::vector< NodePtr > body
Definition syntax.h:778
bool entry
Whether this is the file's entry point: flow { ... }, with no name.
Definition syntax.h:774
Word name
Definition syntax.h:759
for name[, name...] in pipeline [parallel n] { ... }.
Definition syntax.h:655
const Word & variable() const
The first name, which is the whole value where there is only one.
Definition syntax.h:668
PipelinePtr pipeline
Definition syntax.h:657
std::vector< Word > variables
Definition syntax.h:656
int parallel
Definition syntax.h:658
std::vector< NodePtr > body
Definition syntax.h:659
std::vector< Word > after
What has to have finished before the loop starts.
Definition syntax.h:665
if expr { ... } else { ... }.
Definition syntax.h:704
NodePtr condition
Definition syntax.h:705
std::vector< NodePtr > else_body
Definition syntax.h:707
std::vector< NodePtr > then_body
Definition syntax.h:706
base[i] – an element of a list, or a key of an object.
Definition syntax.h:311
NodePtr base
Definition syntax.h:312
NodePtr index
Definition syntax.h:313
it – the value a where/map/group stage is looking at.
Definition syntax.h:288
let name = pipeline – one value, read from a stream and given a name.
Definition syntax.h:509
PipelinePtr pipeline
Definition syntax.h:518
const Word & name() const
The first name, which is the whole value where there is only one.
Definition syntax.h:521
std::vector< Word > names
One name is the value; several take it apart – let name, age = user by field, let first,...
Definition syntax.h:517
[a, ...rest, c]. An item may be a [Spread].
Definition syntax.h:273
std::vector< NodePtr > items
Definition syntax.h:274
A number, string, boolean, null or duration written out.
Definition syntax.h:258
Constant value
Definition syntax.h:259
Where a piece of syntax starts, reduced to what every reader of it needs.
Definition syntax.h:49
size_t end
Definition syntax.h:51
int line
Definition syntax.h:52
size_t start
Definition syntax.h:50
int column
Definition syntax.h:53
What a log or logf was written with, wherever it was written.
Definition syntax.h:367
bool has_format
Whether a format was written at all, which tells logf "" from log.
Definition syntax.h:374
std::vector< NodePtr > arguments
What to log, or what fills the format. it is bound inside a stage.
Definition syntax.h:376
Word level
The level as written, or empty for the default.
Definition syntax.h:370
std::string format
logf's format, with escapes resolved. Empty for a log.
Definition syntax.h:372
log [level] [what] / logf [level] "format" [args] – write to the flow's own log.
Definition syntax.h:645
std::vector< Word > after
Definition syntax.h:647
LogTail tail
Definition syntax.h:646
A bare name: a port, a call, a loop variable, a header alias.
Definition syntax.h:300
std::string name
Definition syntax.h:301
node(id) [in map] – a node of this flow's own.
Definition syntax.h:720
Word node_map
Definition syntax.h:722
NodePtr id
Definition syntax.h:721
Gives each construct its kind without every constructor restating it.
Definition syntax.h:215
NodeOf()
Definition syntax.h:218
static constexpr NodeKind kNodeKind
Definition syntax.h:216
Base of every syntax node: what it is, and where it started.
Definition syntax.h:204
NodeKind kind
Definition syntax.h:207
Location location
Definition syntax.h:208
nodes name [{ ... }] – declare a temporary node map.
Definition syntax.h:711
bool has_body
Whether a block was written, which is what tells nodes x {} – every call inside it placed in the map ...
Definition syntax.h:716
std::vector< NodePtr > body
Definition syntax.h:713
Word name
Definition syntax.h:712
{ "key": expr, ...rest }.
Definition syntax.h:283
std::vector< std::pair< std::string, NodePtr > > pairs
Definition syntax.h:284
status subject – the status of a call, a node, or a barrier.
Definition syntax.h:442
NodePtr subject
Definition syntax.h:443
pipeline -> target, target – write a stream into one or more nodes.
Definition syntax.h:552
std::vector< NodePtr > targets
Definition syntax.h:554
std::vector< Word > after
Definition syntax.h:555
bool tolerant
try source -> dest: a failure arriving from the source, or refused by the destination,...
Definition syntax.h:565
PipelinePtr pipeline
Definition syntax.h:553
(stream | stage ...) used where a value is expected.
Definition syntax.h:447
PipelinePtr pipeline
Definition syntax.h:448
A source expression and the stages its values pass through.
Definition syntax.h:431
std::vector< StagePtr > stages
Definition syntax.h:433
NodePtr source
Definition syntax.h:432
in/out name: type [stream] [required].
Definition syntax.h:734
Word name
Definition syntax.h:735
bool required
Definition syntax.h:740
std::string description
Definition syntax.h:741
TypeExpression type
Definition syntax.h:737
PortDirection direction
Definition syntax.h:736
bool unary
Whether the port carries one value. Most do, so it is the default.
Definition syntax.h:739
repeat [name = expr] [max n] { ... }.
Definition syntax.h:675
std::vector< Word > after
What has to have finished before the loop starts. See ForEach::after.
Definition syntax.h:688
std::optional< int > max_iterations
max n, where one was written.
Definition syntax.h:685
std::vector< NodePtr > body
Definition syntax.h:686
Word variable
Empty where the repeat carries nothing.
Definition syntax.h:677
NodePtr start
Definition syntax.h:678
The one reference changed by a counted skip.
Definition syntax.h:569
Word call
Definition syntax.h:571
std::vector< Word > outputs
Definition syntax.h:572
PipelinePtr pipeline
Definition syntax.h:570
skip n reference – discard the first n values for every reader.
Definition syntax.h:578
std::optional< long long > count
Definition syntax.h:581
std::vector< SkipTarget > targets
Definition syntax.h:579
std::vector< Word > after
Definition syntax.h:580
...expr – everything expr holds, in the literal being written.
Definition syntax.h:268
NodePtr value
Definition syntax.h:269
One | name arg stage of a pipeline.
Definition syntax.h:385
LogTail log
kLog/kLogFormat: what was written after the stage name.
Definition syntax.h:425
bool descending
kSortKey: whether desc was written.
Definition syntax.h:401
std::string name
Definition syntax.h:386
std::string text
kString/kOptionalString: the text, with escapes resolved.
Definition syntax.h:392
double number
kNumber: the count, and whether it was written as a whole number.
Definition syntax.h:389
bool is_integer
Definition syntax.h:390
vocabulary::StageArgument takes
Definition syntax.h:387
int parallel
parallel n: how many values this stage may be working on at once.
Definition syntax.h:416
NodePtr failures
into ref: where a tolerated failure goes, as a status record.
Definition syntax.h:413
absl::Duration duration
kDuration: how long timeout waits, or pace spaces values out by.
Definition syntax.h:399
bool ordered
Whether the values leave in the order they arrived.
Definition syntax.h:422
NodePtr argument
kExpression/kOptionalExpression: the expression, with it bound.
Definition syntax.h:397
Word carried
Definition syntax.h:406
Constant start
kFold: the literal to start from and the name bound to what the last value produced.
Definition syntax.h:405
bool tolerant
try map ...: a value this stage cannot do is dropped rather than ending the pipeline.
Definition syntax.h:410
The type of a port, or of a value being made one: string, list[a11.NodeFragment], "audio/wav".
Definition syntax.h:126
bool sugared
Whether a list[T] was written T[].
Definition syntax.h:136
bool quoted
Definition syntax.h:130
Location location
Definition syntax.h:127
std::string ToString() const
The type as it would be written, which is what a message quotes.
Definition syntax.cc:109
std::vector< TypeExpression > parameters
Definition syntax.h:129
std::string name
Definition syntax.h:128
Tag{...} or expr as Tag – a value made into a type's value.
Definition syntax.h:340
NodePtr value
Definition syntax.h:342
TypeExpression type
Definition syntax.h:341
not operand.
Definition syntax.h:346
std::string op
Definition syntax.h:347
NodePtr operand
Definition syntax.h:348
until expr / while expr – when a repeat stops.
Definition syntax.h:698
NodePtr condition
Definition syntax.h:699
bool stop_when
Definition syntax.h:700
wait subject – hold until a call, or a node this flow writes, is finished.
Definition syntax.h:593
bool race
Whether the first to finish is enough.
Definition syntax.h:598
std::vector< Word > after
Definition syntax.h:600
std::optional< absl::Duration > timeout
Definition syntax.h:599
std::vector< NodePtr > targets
wait first of a, b -> n: where the winner's number goes.
Definition syntax.h:608
std::vector< NodePtr > subjects
Definition syntax.h:595
NodePtr subject
Definition syntax.h:594
A name as written, and where it was written.
Definition syntax.h:65
Location location
Definition syntax.h:67
bool Empty() const
Definition syntax.h:69
std::string text
Definition syntax.h:66
Several streams read as one: zip(a, b, c), interleave(a, b, c).
Definition syntax.h:334
std::string name
Definition syntax.h:335
std::vector< NodePtr > sources
Definition syntax.h:336