A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
emit_json.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef A11_FLOW_EMIT_JSON_H_
18#define A11_FLOW_EMIT_JSON_H_
19
20#include <string>
21#include <string_view>
22
23#include <absl/types/span.h>
24#include <nlohmann/json_fwd.hpp>
25
26#include "a11/flow/complete.h"
27#include "a11/flow/diagnostic.h"
28#include "a11/flow/format.h"
29#include "a11/flow/parser.h"
30#include "a11/flow/plan.h"
31#include "a11/flow/syntax.h"
32
33namespace a11::flow {
34
36inline constexpr std::string_view kDiagnosticsFormat = "flow.diagnostics/v1";
37inline constexpr std::string_view kCodesFormat = "flow.codes/v1";
38inline constexpr std::string_view kSyntaxFormat = "flow.syntax/v1";
39inline constexpr std::string_view kTokensFormat = "flow.tokens/v1";
40inline constexpr std::string_view kVocabularyFormat = "flow.vocabulary/v1";
41inline constexpr std::string_view kFormatFormat = "flow.format/v1";
42
44nlohmann::json DiagnosticToJsonValue(const Diagnostic& diagnostic);
45
47Diagnostic DiagnosticFromJsonValue(const nlohmann::json& value);
48
50nlohmann::json DiagnosticsToJsonValue(std::string_view source,
51 absl::Span<const Diagnostic> diagnostics);
52
54std::string DiagnosticsToJson(std::string_view source,
55 absl::Span<const Diagnostic> diagnostics);
56
58nlohmann::json CodesToJsonValue();
59
61nlohmann::json VocabularyToJsonValue();
62
64nlohmann::json DiagnosticsToSarifValue(
65 std::string_view source, absl::Span<const Diagnostic> diagnostics);
66
68std::string DiagnosticsToSarif(std::string_view source,
69 absl::Span<const Diagnostic> diagnostics);
70
73nlohmann::json NodeToJsonValue(const syntax::Node& node);
74
76nlohmann::json ConstantToJsonValue(const syntax::Constant& constant);
77
79nlohmann::json SyntaxToJsonValue(std::string_view source,
80 const ParseResult& result);
81
83std::string SyntaxToJson(std::string_view source, const ParseResult& result);
84
87nlohmann::json TokensToJsonValue(std::string_view source_name,
88 std::string_view source);
89
91std::string TokensToJson(std::string_view source_name, std::string_view source);
92
94nlohmann::json FormatToJsonValue(const FormatResult& result);
95
97nlohmann::json CompletionsToJsonValue(const CompleteResult& result);
98
100nlohmann::json PlanToJsonValue(std::string_view source_name,
101 const Program& program);
102
105nlohmann::json DtoToJsonValue(const DtoPlan& dto,
106 const Program* absl_nullable program = nullptr);
107
109std::string PlanToJson(std::string_view source_name, const Program& program);
110
113std::string DiagnosticToText(std::string_view source,
114 const Diagnostic& diagnostic);
115
116} // namespace a11::flow
117
118#endif // A11_FLOW_EMIT_JSON_H_
a11::Promise< a11::Unit > result
Definition async_node.cc:56
std::string value
Definition discover.cc:100
bool dto
Definition format.cc:1378
Definition catalogue.cc:29
constexpr std::string_view kDiagnosticsFormat
Envelope format identifiers. Readers ignore unknown fields in a version.
Definition emit_json.h:36
Diagnostic DiagnosticFromJsonValue(const nlohmann::json &value)
Reads a diagnostic, ignoring unknown fields and defaulting missing ones.
Definition emit_json.cc:717
nlohmann::json PlanToJsonValue(std::string_view source_name, const Program &program)
The flow.plan/v1 envelope for resolved flows.
Definition emit_json.cc:1336
nlohmann::json CodesToJsonValue()
The published code table, as flow.codes/v1.
Definition emit_json.cc:825
nlohmann::json TokensToJsonValue(std::string_view source_name, std::string_view source)
The flow.tokens/v1 envelope, with token kinds and semantic classes.
Definition emit_json.cc:1070
nlohmann::json NodeToJsonValue(const syntax::Node &node)
A syntax node and its subtree.
Definition emit_json.cc:1022
nlohmann::json DiagnosticToJsonValue(const Diagnostic &diagnostic)
One diagnostic, as it appears in the envelope.
Definition emit_json.cc:671
std::string PlanToJson(std::string_view source_name, const Program &program)
The envelope, serialised with a trailing newline and two-space indent.
Definition emit_json.cc:1423
std::string SyntaxToJson(std::string_view source, const ParseResult &result)
The envelope, serialised with a trailing newline and two-space indent.
Definition emit_json.cc:1066
std::string DiagnosticToText(std::string_view source, const Diagnostic &diagnostic)
path:line:column: severity: message [code] on one line.
Definition emit_json.cc:1427
std::string DiagnosticsToJson(std::string_view source, absl::Span< const Diagnostic > diagnostics)
The envelope, serialised with a trailing newline and two-space indent.
Definition emit_json.cc:819
constexpr std::string_view kCodesFormat
Definition emit_json.h:37
nlohmann::json DiagnosticsToSarifValue(std::string_view source, absl::Span< const Diagnostic > diagnostics)
A SARIF 2.1.0 log for one file, with rule metadata from [KnownCodes].
Definition emit_json.cc:919
nlohmann::json CompletionsToJsonValue(const CompleteResult &result)
The flow.completions/v1 envelope: what may be written at an offset.
Definition emit_json.cc:1133
nlohmann::json SyntaxToJsonValue(std::string_view source, const ParseResult &result)
The flow.syntax/v1 envelope, including partial trees and diagnostics.
Definition emit_json.cc:1026
constexpr std::string_view kVocabularyFormat
Definition emit_json.h:40
nlohmann::json FormatToJsonValue(const FormatResult &result)
The flow.format/v1 envelope: the formatted text, and what it took.
Definition emit_json.cc:1116
nlohmann::json DiagnosticsToJsonValue(std::string_view source, absl::Span< const Diagnostic > diagnostics)
The flow.diagnostics/v1 envelope, with source and severity counts.
Definition emit_json.cc:784
nlohmann::json DtoToJsonValue(const DtoPlan &dto, const Program *absl_nullable program)
A resolved shape.
Definition emit_json.cc:1390
nlohmann::json ConstantToJsonValue(const syntax::Constant &constant)
A constant as the syntax format writes it.
Definition emit_json.cc:986
std::string TokensToJson(std::string_view source_name, std::string_view source)
The envelope, serialised with a trailing newline and two-space indent.
Definition emit_json.cc:1111
std::string DiagnosticsToSarif(std::string_view source, absl::Span< const Diagnostic > diagnostics)
The SARIF log, serialised with a trailing newline.
Definition emit_json.cc:980
constexpr std::string_view kFormatFormat
Definition emit_json.h:41
constexpr std::string_view kTokensFormat
Definition emit_json.h:39
nlohmann::json VocabularyToJsonValue()
The language word sets as flow.vocabulary/v1.
Definition emit_json.cc:836
constexpr std::string_view kSyntaxFormat
Definition emit_json.h:38
graph::RefId node
Graph ref for this result, or [graph::kNone] without a resolved ref.
Definition resolve.cc:809
What may be written at an offset, and the word already typed there.
Definition complete.h:97
Flow problem rendered by the CLI, JSON and SARIF writers, and editors.
Definition diagnostic.h:99
One compiled struct: a shape a port may be typed with.
Definition plan.h:87
Formatted source, edits, and diagnostics.
Definition format.h:44
The flows a file declares, and everything wrong with it.
Definition parser.h:34
Every flow and shape one source file declares.
Definition plan.h:200
A literal or folded literal expression, including nested lists and objects.
Definition syntax.h:62
Base of every syntax node: what it is, and where it started.
Definition syntax.h:179