@@ -12,10 +12,39 @@ static auto step_name(const sourcemeta::blaze::Instruction &instruction)
1212 instruction.type )];
1313}
1414
15+ static auto try_vocabulary (
16+ const std::optional<
17+ std::reference_wrapper<const sourcemeta::core::SchemaFrame>> &frame,
18+ const sourcemeta::core::WeakPointer &evaluate_path,
19+ const sourcemeta::core::SchemaWalker &walker,
20+ const sourcemeta::core::SchemaResolver &resolver,
21+ const std::string &keyword_location)
22+ -> std::pair<bool, std::optional<std::string>> {
23+ if (!frame.has_value () || evaluate_path.empty () ||
24+ !evaluate_path.back ().is_property ()) {
25+ return {false , std::nullopt };
26+ }
27+
28+ const auto entry{frame.value ().get ().traverse (keyword_location)};
29+ if (!entry.has_value ()) {
30+ return {false , std::nullopt };
31+ }
32+
33+ const auto vocabularies{
34+ frame.value ().get ().vocabularies (entry.value ().get (), resolver)};
35+ const auto result{walker (evaluate_path.back ().to_property (), vocabularies)};
36+ return {true , result.vocabulary };
37+ }
38+
1539namespace sourcemeta ::blaze {
1640
17- TraceOutput::TraceOutput (const sourcemeta::core::WeakPointer &base)
18- : base_{base} {}
41+ TraceOutput::TraceOutput (
42+ const sourcemeta::core::SchemaWalker &walker,
43+ const sourcemeta::core::SchemaResolver &resolver,
44+ const sourcemeta::core::WeakPointer &base,
45+ const std::optional<
46+ std::reference_wrapper<const sourcemeta::core::SchemaFrame>> &frame)
47+ : walker_{walker}, resolver_{resolver}, base_{base}, frame_{frame} {}
1948
2049auto TraceOutput::begin () const -> const_iterator {
2150 return this ->output .begin ();
@@ -38,27 +67,34 @@ auto TraceOutput::operator()(
3867 const auto short_step_name{step_name (step)};
3968 auto effective_evaluate_path{evaluate_path.resolve_from (this ->base_ )};
4069
70+ // Attempt to get vocabulary information if we can get it
71+ auto vocabulary{try_vocabulary (this ->frame_ , evaluate_path, this ->walker_ ,
72+ this ->resolver_ , step.keyword_location )};
73+
4174 if (is_annotation (step.type )) {
4275 if (type == EvaluationType::Pre) {
4376 return ;
4477 } else {
45- this ->output .push_back ({EntryType::Annotation, short_step_name,
46- instance_location,
47- std::move (effective_evaluate_path),
48- step. keyword_location , annotation });
78+ this ->output .push_back (
79+ {EntryType::Annotation, short_step_name, instance_location,
80+ std::move (effective_evaluate_path), step. keyword_location ,
81+ annotation, std::move (vocabulary) });
4982 }
5083 } else if (type == EvaluationType::Pre) {
5184 this ->output .push_back ({EntryType::Push, short_step_name, instance_location,
5285 std::move (effective_evaluate_path),
53- step.keyword_location , std::nullopt });
86+ step.keyword_location , std::nullopt ,
87+ std::move (vocabulary)});
5488 } else if (result) {
5589 this ->output .push_back ({EntryType::Pass, short_step_name, instance_location,
5690 std::move (effective_evaluate_path),
57- step.keyword_location , std::nullopt });
91+ step.keyword_location , std::nullopt ,
92+ std::move (vocabulary)});
5893 } else {
5994 this ->output .push_back ({EntryType::Fail, short_step_name, instance_location,
6095 std::move (effective_evaluate_path),
61- step.keyword_location , std::nullopt });
96+ step.keyword_location , std::nullopt ,
97+ std::move (vocabulary)});
6298 }
6399}
64100
0 commit comments