17#ifndef A11_FLOW_SYNTAX_H_
18#define A11_FLOW_SYNTAX_H_
29#include <absl/status/statusor.h>
30#include <absl/time/time.h>
57 [[nodiscard]]
bool Empty()
const {
return text.empty(); }
81 std::vector<std::pair<std::string, Constant>>
pairs;
92 [[nodiscard]]
double AsDouble()
const;
114 [[nodiscard]] std::string
ToString()
const;
117 absl::StatusOr<std::string>
ToSource()
const;
202 if (
node ==
nullptr ||
node->kind != T::kNodeKind) {
207 return static_cast<const T*
>(
node);
212 if (
node ==
nullptr ||
node->kind != T::kNodeKind) {
217 return static_cast<T*
>(
node);
221bool IsAnyOf(
const Node*
node, std::initializer_list<NodeKind> kinds);
249 std::vector<std::pair<std::string, NodePtr>>
pairs;
330 std::optional<TypeExpression>
type;
412 std::vector<std::pair<std::string, NodePtr>>
headers;
457 std::optional<TypeExpression>
type;
707 std::vector<PortDeclarationPtr>
ports;
711 std::vector<std::unique_ptr<DtoDeclaration>>
structs;
775 const std::function<
void(
const Node&)>& visit);
780 const std::function<
void(
const Node&)>& visit);
std::string value
Definition discover.cc:100
constexpr size_t kNone
Sentinel for an absent graph ID.
Definition graph.h:45
Location LocationOf(const Token &token)
The location a token occupies.
Definition syntax.cc:34
std::string_view PortDirectionName(PortDirection direction)
"inputs" or "outputs".
Definition syntax.cc:311
std::unique_ptr< DtoDeclaration > DtoDeclarationPtr
Definition syntax.h:764
std::optional< Constant > ConstantValue(const Node *node)
Folds a literal expression, or returns nullopt for runtime values.
Definition syntax.cc:377
std::string SourceTypeName(std::string_view name)
A port or cast type, such as string, list[a11.NodeFragment], or "audio/wav".
Definition syntax.cc:141
std::string SourceFunctionName(std::string_view name)
Definition syntax.cc:133
void VisitSubtree(const Node &node, const std::function< void(const Node &)> &visit)
Visits a subtree iteratively, starting with node.
Definition syntax.cc:734
std::unique_ptr< Pipeline > PipelinePtr
Definition syntax.h:380
bool IsPureLiteralExpression(const Node &node)
Whether a bounded expression contains only literal data and pure operators.
Definition syntax.cc:333
std::unique_ptr< FlowDeclaration > FlowDeclarationPtr
Definition syntax.h:715
void VisitChildren(const Node &node, const std::function< void(const Node &)> &visit)
Visits direct child nodes in source order.
Definition syntax.cc:432
std::unique_ptr< CallModifiers > CallModifiersPtr
Definition syntax.h:419
bool IsAnyOf(const Node *node, std::initializer_list< NodeKind > kinds)
Whether a node is one of the kinds given.
Definition syntax.cc:304
std::unique_ptr< HeaderDeclaration > HeaderDeclarationPtr
Definition syntax.h:651
PortDirection
Which side of the descriptor a port lands on, spelled as the plan spells it.
Definition syntax.h:624
std::unique_ptr< PortDeclaration > PortDeclarationPtr
Definition syntax.h:640
std::unique_ptr< Stage > StagePtr
Definition syntax.h:372
std::optional< std::string > DottedName(const Node *node)
Returns a dotted Name/Attr chain, or nullopt for other nodes.
Definition syntax.cc:746
std::string_view ConstantKindName(Constant::Kind kind)
The spelling of a constant's kind in the output formats.
Definition syntax.cc:92
void VisitMutableSubtree(Node &node, const std::function< void(Node &)> &visit)
Walk an exclusively owned syntax tree for native linking/editing.
Definition syntax.cc:764
std::unique_ptr< CallExpression > CallExpressionPtr
Definition syntax.h:448
std::unique_ptr< Node > NodePtr
Definition syntax.h:189
std::unique_ptr< FieldDeclaration > FieldDeclarationPtr
Definition syntax.h:750
const T * As(const Node *node)
Returns node as T, or null when its kind differs.
Definition syntax.h:201
NodeKind
Syntax node kinds, one per construct.
Definition syntax.h:121
@ kError
A syntax error retained in the recovering parser's tree.
std::string_view NodeKindName(NodeKind kind)
The name of a node kind in the output formats, in kebab case.
Definition syntax.cc:208
std::string ActionSource(std::string_view name)
Definition syntax.cc:118
std::string RuntimeActionName(std::string_view name)
Definition syntax.cc:114
StageArgument
What a stage takes after its name.
Definition vocabulary.h:43
@ kNone
Nothing: | collect, | count.
absl::Duration Duration
A11 duration; an alias of absl::Duration (nanosecond-aware).
Definition time.h:40
graph::RefId node
Graph ref for this result, or [graph::kNone] without a resolved ref.
Definition resolve.cc:809
One token: what it is, where it is, and what it holds.
Definition token.h:104
abort node [code] [message] – end a node with a failure.
Definition syntax.h:528
NodePtr message
Definition syntax.h:531
std::vector< Word > after
Definition syntax.h:532
NodePtr target
Definition syntax.h:529
NodePtr code
Definition syntax.h:530
id subject – the identity assigned to a run or call.
Definition syntax.h:388
NodePtr subject
Definition syntax.h:389
base.name – a call's port, or a key of a value.
Definition syntax.h:264
NodePtr base
Definition syntax.h:265
std::string name
Definition syntax.h:266
bool optional
Definition syntax.h:267
left op right for and or == != < <= > >= in + -.
Definition syntax.h:303
NodePtr left
Definition syntax.h:305
std::string op
Definition syntax.h:304
NodePtr right
Definition syntax.h:306
name = ... – a step the rest of the flow can refer to.
Definition syntax.h:453
Word name
Definition syntax.h:454
std::vector< Word > names
Definition syntax.h:455
std::optional< TypeExpression > type
Definition syntax.h:457
NodePtr value
Definition syntax.h:456
[try] { ... } groups concurrent statements into one outcome.
Definition syntax.h:462
bool tolerant
Definition syntax.h:463
std::vector< Word > after
Definition syntax.h:464
std::vector< NodePtr > body
Definition syntax.h:465
name(arg, ...) – one of the language's fixed functions.
Definition syntax.h:278
std::vector< NodePtr > args
Definition syntax.h:280
std::string name
Definition syntax.h:279
One argument: the port named, where it was named, and what feeds it.
Definition syntax.h:424
Word port
Definition syntax.h:425
PipelinePtr pipeline
Definition syntax.h:426
Location location
Definition syntax.h:439
NodePtr index
Definition syntax.h:441
std::string member
Definition syntax.h:440
run/call action(port: pipeline, ...) and its modifiers.
Definition syntax.h:422
std::string mode
The verb written: "run" for the handler registered here, "call" for the stream this flow is attached ...
Definition syntax.h:433
std::vector< Argument > args
Definition syntax.h:434
Location action_location
Definition syntax.h:430
std::string action
Definition syntax.h:429
bool tolerant
Definition syntax.h:436
CallModifiersPtr modifiers
Definition syntax.h:435
bool invalid_target
Definition syntax.h:444
std::vector< TargetSuffix > target_suffixes
Definition syntax.h:445
The tee/via/timeout/after/with/id/id-into/forward tail.
Definition syntax.h:403
std::vector< Word > after
Definition syntax.h:411
NodePtr id_into
Definition syntax.h:414
std::vector< std::string > forward
Header names, or * patterns, that forward headers names.
Definition syntax.h:416
NodePtr timeout_expression
Definition syntax.h:410
NodePtr deadline
Definition syntax.h:409
bool tee
Definition syntax.h:406
NodePtr action_id
Definition syntax.h:413
Word node_map
Definition syntax.h:407
std::vector< Location > clause_locations
Modifier keyword positions, in source order.
Definition syntax.h:405
std::vector< std::pair< std::string, NodePtr > > headers
Definition syntax.h:412
std::optional< absl::Duration > timeout
Definition syntax.h:408
A call statement whose unnamed outputs are drained.
Definition syntax.h:469
CallExpressionPtr call
Definition syntax.h:470
cancel name – ask a called action to stop, cooperatively.
Definition syntax.h:522
Word name
Definition syntax.h:523
std::vector< Word > after
Definition syntax.h:524
name <- pipeline – what the next pass of a repeat carries.
Definition syntax.h:587
PipelinePtr pipeline
Definition syntax.h:589
Word name
Definition syntax.h:588
close target – hold until a node's writers are done and its buffer has landed.
Definition syntax.h:516
NodePtr target
Definition syntax.h:517
std::vector< Word > after
Definition syntax.h:518
A literal or folded literal expression, including nested lists and objects.
Definition syntax.h:62
std::vector< std::pair< std::string, Constant > > pairs
Definition syntax.h:81
static Constant Null()
Definition syntax.h:83
std::vector< Constant > items
Definition syntax.h:80
Kind
Definition syntax.h:63
double AsDouble() const
The number this holds, whichever way it was written.
Definition syntax.cc:79
static Constant Double(double value)
Definition syntax.cc:58
double number
Definition syntax.h:77
static Constant Bool(bool value)
Definition syntax.cc:43
static Constant String(std::string value)
Definition syntax.cc:65
absl::Duration duration
Definition syntax.h:79
std::string text
Definition syntax.h:78
static Constant Integer(long long value)
Definition syntax.cc:50
Kind kind
Definition syntax.h:74
long long integer
Definition syntax.h:76
_, a pipe destination that discards its input.
Definition syntax.h:256
One struct name { ... } declaration: a shape a port may be typed with.
Definition syntax.h:755
std::vector< FieldDeclarationPtr > fields
Definition syntax.h:761
std::string std::string scope
Definition syntax.h:758
bool exported
Definition syntax.h:759
Word name
Definition syntax.h:756
std::string description
Definition syntax.h:760
A place the parser wanted a value and did not find one.
Definition syntax.h:226
std::string expected
What was expected there, for a formatter deciding to leave it alone.
Definition syntax.h:228
A public alias of an existing namespace member.
Definition syntax.h:684
Word alias
Definition syntax.h:686
Word symbol
Definition syntax.h:685
std::string scope
Definition syntax.h:687
Location extent
Definition syntax.h:688
fail [code] [message] – end the flow with a status.
Definition syntax.h:536
NodePtr message
Definition syntax.h:538
std::vector< Word > after
Definition syntax.h:539
NodePtr code
Definition syntax.h:537
One name: type [modifiers] ["description"] field of a struct.
Definition syntax.h:729
bool unique
unique: no two items of a list are equal.
Definition syntax.h:735
Constant default_value
default ..: what a value that was not given is.
Definition syntax.h:745
bool required
Whether the value must be supplied; optional fields may be absent.
Definition syntax.h:733
bool has_pattern
Definition syntax.h:740
bool has_enumeration
Definition syntax.h:743
std::string pattern
matching "...": the pattern every value has to match, unanchored, as JSONSchema's pattern is.
Definition syntax.h:739
std::string description
Definition syntax.h:747
FieldRange range
Definition syntax.h:736
std::vector< Constant > enumeration
one of [..]: the only values allowed.
Definition syntax.h:742
Word name
Definition syntax.h:730
bool has_default
Definition syntax.h:746
TypeExpression type
Definition syntax.h:731
A field bound such as 1..200, 1.., or ..200.
Definition syntax.h:719
Constant maximum
Definition syntax.h:723
bool Empty() const
Definition syntax.h:725
bool has_minimum
Definition syntax.h:720
bool has_maximum
Definition syntax.h:721
Constant minimum
Definition syntax.h:722
One flow name { ... } declaration, or the one flow { ... } entry point.
Definition syntax.h:694
std::string description
Definition syntax.h:706
std::vector< PortDeclarationPtr > ports
Definition syntax.h:707
std::vector< std::unique_ptr< DtoDeclaration > > structs
Definition syntax.h:711
std::vector< HeaderDeclarationPtr > headers
Definition syntax.h:708
bool interface_only
Definition syntax.h:702
std::vector< NodePtr > body
Definition syntax.h:712
bool exported
Definition syntax.h:704
std::string std::string scope
Definition syntax.h:698
std::vector< Import > imports
Definition syntax.h:709
bool entry
Whether this is the unnamed flow { ... } entry point.
Definition syntax.h:701
bool registerable
Definition syntax.h:705
Word name
Definition syntax.h:695
bool imported
Definition syntax.h:703
std::string binding_name
Definition syntax.h:696
std::vector< std::unique_ptr< FlowDeclaration > > declarations
Definition syntax.h:710
for name[, name...] in pipeline [parallel n] { ... }.
Definition syntax.h:553
const Word & variable() const
The first name, which is the whole value where there is only one.
Definition syntax.h:566
PipelinePtr pipeline
Definition syntax.h:555
NodePtr termination
Optional postcondition, evaluated after a complete pass.
Definition syntax.h:561
std::vector< Word > variables
Definition syntax.h:554
int parallel
Definition syntax.h:556
NodePtr parallel_expression
A nonliteral concurrency count, evaluated once before iteration.
Definition syntax.h:558
std::vector< NodePtr > body
Definition syntax.h:559
std::vector< Word > after
Dependencies that finish before the loop starts.
Definition syntax.h:563
if expr { ... } else { ... }.
Definition syntax.h:599
NodePtr condition
Definition syntax.h:602
Location binding_scope
Definition syntax.h:601
std::vector< NodePtr > else_body
Definition syntax.h:604
std::vector< NodePtr > then_body
Definition syntax.h:603
Word binding
Definition syntax.h:600
A source module bound to a namespace or selected local symbols.
Definition syntax.h:660
Location source_location
Definition syntax.h:665
bool explicit_alias
Definition syntax.h:664
bool namespace_source
Definition syntax.h:663
Location extent
Definition syntax.h:672
bool selective
Definition syntax.h:667
std::string source
Definition syntax.h:661
bool exported
Definition syntax.h:666
std::vector< ImportedSymbol > symbols
Definition syntax.h:669
Location location
Definition syntax.h:671
Word alias
Definition syntax.h:670
size_t selection_start
Definition syntax.h:668
std::string scope
Definition syntax.h:662
Word name
Definition syntax.h:654
Word alias
Definition syntax.h:655
bool explicit_alias
Definition syntax.h:656
base[i] – an element of a list, or a key of an object.
Definition syntax.h:271
NodePtr base
Definition syntax.h:272
bool optional
Definition syntax.h:274
NodePtr index
Definition syntax.h:273
it – the value a where/map/group stage is looking at.
Definition syntax.h:253
[a, ...rest, c]. An item may be a [Spread].
Definition syntax.h:242
std::vector< NodePtr > items
Definition syntax.h:243
A number, string, boolean, null or duration written out.
Definition syntax.h:232
Constant value
Definition syntax.h:233
The start token's byte span, line, and code-point column.
Definition syntax.h:39
size_t end
Definition syntax.h:41
int line
Definition syntax.h:42
size_t start
Definition syntax.h:40
int column
Definition syntax.h:43
Arguments shared by log and logf statements and stages.
Definition syntax.h:313
bool has_format
Whether a format was written at all, which tells logf "" from log.
Definition syntax.h:320
std::vector< NodePtr > arguments
What to log, or what fills the format. it is bound inside a stage.
Definition syntax.h:322
Word level
The level as written, or empty for the default.
Definition syntax.h:316
std::string format
logf's format, with escapes resolved. Empty for a log.
Definition syntax.h:318
log [level] [what] / logf [level] "format" [args] – write to the flow's own log.
Definition syntax.h:544
std::vector< Word > after
Definition syntax.h:546
LogTail tail
Definition syntax.h:545
A namespace contribution in one source document.
Definition syntax.h:676
bool exported
Definition syntax.h:679
Word name
Definition syntax.h:677
Location extent
Definition syntax.h:680
bool interface_only
Definition syntax.h:678
A bare name: a port, a call, a loop variable, a header alias.
Definition syntax.h:259
std::string name
Definition syntax.h:260
node(id) [in map] – a node of this flow's own.
Definition syntax.h:616
Word node_map
Definition syntax.h:618
NodePtr id
Definition syntax.h:617
Assigns a fixed kind to each syntax node type.
Definition syntax.h:193
NodeOf()
Definition syntax.h:196
static constexpr NodeKind kNodeKind
Definition syntax.h:194
Base of every syntax node: what it is, and where it started.
Definition syntax.h:179
NodeKind kind
Definition syntax.h:182
std::vector< Location > groups
Definition syntax.h:186
Location extent
Full source extent and transparent grouping, for native edits.
Definition syntax.h:185
Location location
Definition syntax.h:183
nodes name [{ ... }] – declare a temporary node map.
Definition syntax.h:608
bool has_body
Whether a node-map block was written, including an empty block.
Definition syntax.h:612
std::vector< NodePtr > body
Definition syntax.h:610
Word name
Definition syntax.h:609
{ "key": expr, ...rest }.
Definition syntax.h:248
std::vector< std::pair< std::string, NodePtr > > pairs
Definition syntax.h:249
status subject; reading it waits for the subject to finish.
Definition syntax.h:383
NodePtr subject
Definition syntax.h:384
pipeline -> target, target – write a stream into one or more nodes.
Definition syntax.h:474
std::vector< NodePtr > targets
Definition syntax.h:476
std::vector< Word > after
Definition syntax.h:477
bool tolerant
try source -> dest: capture a source or destination failure as a value.
Definition syntax.h:479
PipelinePtr pipeline
Definition syntax.h:475
(stream | stage ...) used where a value is expected.
Definition syntax.h:393
bool take
Explicit extraction, with absence on EOF only when optional.
Definition syntax.h:396
bool optional
Definition syntax.h:397
PipelinePtr pipeline
Definition syntax.h:394
A source expression and the stages its values pass through.
Definition syntax.h:375
std::vector< StagePtr > stages
Definition syntax.h:377
NodePtr source
Definition syntax.h:376
in/out name: type [stream] [required].
Definition syntax.h:630
Word name
Definition syntax.h:631
bool required
Definition syntax.h:636
std::string description
Definition syntax.h:637
TypeExpression type
Definition syntax.h:633
PortDirection direction
Definition syntax.h:632
bool unary
Whether the port carries one value. Most do, so it is the default.
Definition syntax.h:635
repeat [name = expr] [max n] { ... }.
Definition syntax.h:573
std::vector< Word > after
What has to have finished before the loop starts. See ForEach::after.
Definition syntax.h:583
std::optional< int > max_iterations
Optional max n bound; absent for a condition-only loop.
Definition syntax.h:578
std::vector< NodePtr > body
Definition syntax.h:579
NodePtr termination
Optional postcondition, resolved in the iteration scope.
Definition syntax.h:581
Word variable
Empty where the repeat carries nothing.
Definition syntax.h:575
NodePtr start
Definition syntax.h:576
The one reference changed by a counted skip.
Definition syntax.h:483
Word call
Definition syntax.h:485
std::vector< Word > outputs
Definition syntax.h:486
PipelinePtr pipeline
Definition syntax.h:484
skip n reference – discard the first n values for every reader.
Definition syntax.h:492
std::optional< long long > count
Definition syntax.h:495
std::vector< SkipTarget > targets
Definition syntax.h:493
std::vector< Word > after
Definition syntax.h:494
...expr in a list or object literal.
Definition syntax.h:237
NodePtr value
Definition syntax.h:238
One | name arg stage of a pipeline.
Definition syntax.h:327
LogTail log
kLog/kLogFormat: what was written after the stage name.
Definition syntax.h:369
bool descending
kSortKey: whether desc was written.
Definition syntax.h:346
std::string name
Definition syntax.h:328
NodePtr parallel_expression
A nonliteral concurrency count, evaluated once when the stage starts.
Definition syntax.h:359
std::string text
kString/kOptionalString: the text, with escapes resolved.
Definition syntax.h:336
double number
kNumber: a constant count, when the argument folds to an integer.
Definition syntax.h:332
bool is_integer
Definition syntax.h:334
NodePtr context_after
Definition syntax.h:362
std::optional< TypeExpression > type
Definition syntax.h:330
vocabulary::StageArgument takes
Definition syntax.h:329
NodePtr context_base
Definition syntax.h:364
int parallel
parallel n: maximum concurrent values; one is the default.
Definition syntax.h:357
long long integer
Definition syntax.h:333
bool context_numbered
Definition syntax.h:363
NodePtr failures
failures into ref: where a tolerated failure goes.
Definition syntax.h:355
absl::Duration duration
kDuration: how long timeout waits, or pace spaces values out by.
Definition syntax.h:344
bool ordered
Whether output preserves input order; unordered clears this flag.
Definition syntax.h:366
NodePtr argument
kExpression/kOptionalExpression: the expression, with it bound.
Definition syntax.h:342
Word carried
Definition syntax.h:349
Constant start
kFold: the initial literal and carried name.
Definition syntax.h:348
bool tolerant
try map ...: tolerate an item's evaluation failure; context may retain the item.
Definition syntax.h:352
NodePtr context_before
context: surrounding item counts, evaluated once outside it.
Definition syntax.h:361
bool sugared
Whether list[T] used the T[] spelling, retained by the formatter.
Definition syntax.h:111
bool quoted
Definition syntax.h:109
Location location
Definition syntax.h:106
std::string ToString() const
The type as it would be written, which is what a message quotes.
Definition syntax.cc:160
std::vector< TypeExpression > parameters
Definition syntax.h:108
absl::StatusOr< std::string > ToSource() const
Emit a bounded type expression, preserving quoted representations.
Definition syntax.cc:175
std::string name
Definition syntax.h:107
Tag{...} or expr as Tag – a value made into a type's value.
Definition syntax.h:291
NodePtr value
Definition syntax.h:293
TypeExpression type
Definition syntax.h:292
not operand.
Definition syntax.h:297
std::string op
Definition syntax.h:298
NodePtr operand
Definition syntax.h:299
until expr / while expr – when a repeat stops.
Definition syntax.h:593
NodePtr condition
Definition syntax.h:594
bool stop_when
Definition syntax.h:595
Wait for one subject, the first of several, or all of several.
Definition syntax.h:500
bool race
Whether the first plural subject to finish satisfies the wait.
Definition syntax.h:505
bool scope_barrier
Definition syntax.h:501
std::vector< Word > after
Definition syntax.h:509
std::optional< absl::Duration > timeout
Definition syntax.h:506
NodePtr deadline
Definition syntax.h:507
std::vector< NodePtr > targets
Destinations for the winning subject's zero-based index.
Definition syntax.h:511
NodePtr timeout_expression
Definition syntax.h:508
std::vector< NodePtr > subjects
Definition syntax.h:503
NodePtr subject
Definition syntax.h:502
Location location
Definition syntax.h:54
bool Empty() const
Definition syntax.h:57
std::shared_ptr< Node > expression
Definition syntax.h:55
std::string text
Definition syntax.h:53
zip or interleave over stream sources.
Definition syntax.h:285
std::string name
Definition syntax.h:286
std::vector< NodePtr > sources
Definition syntax.h:287