bin/hh-json: Add transformations
@@ -16,6 +16,7 @@ hh_parse --full-fidelity-text-json $@ |
(. == [] or . == {}) or
type == "object" and
(
+ .kind == "markup_section" or
.kind == "whitespace" or
.kind == "end_of_file" or
.kind == "end_of_line" or
@@ -28,15 +29,59 @@ hh_parse --full-fidelity-text-json $@ |
)
);
- # Replace name token objects with the string name itself.
- def name:
+ # Transform/replace some objects with a simplified version.
+ def transform:
+
+ # {
+ # "kind": "token",
+ # "token": {
+ # "kind": "final",
+ # "text": "final"
+ # }
+ # }
+
if type == "object" and
- .kind == "token" and (
- .token.kind == "name" or
+ .kind == "token" and
.token.kind == .token.text
- )
- then
- .token.text
+
+ then .token.text
+
+ # {
+ # "kind": "token",
+ # "token": {
+ # "kind": "XHP_class_name",
+ # "text": ":head"
+ # }
+ # }
+
+ elif type == "object" and
+ .kind == "token" and
+ has("token") and
+ (.token | keys) == ["kind", "text"]
+
+ then {(.token.kind): .token.text}
+
+ # {
+ # "kind": "list_item",
+ # "list_item": {
+ # "kind": "...",
+ # }
+ # }
+
+ elif type == "object" and .kind == "list_item" and has("list_item")
+ then .list_item
+
+
+ # "...": {
+ # "kind": "list",
+ # "elements": [
+ # {}
+ # ]
+ # }
+
+ elif type == "object" and .kind == "list" and has("elements")
+ then .elements
+
else .
end;
@@ -44,12 +89,12 @@ hh_parse --full-fidelity-text-json $@ |
if type == "object" then
# Remove keys with low-value values.
- with_entries(select(.value | trivia | not)) | map_values(name)
+ with_entries(select(.value | trivia | not)) | map_values(transform)
elif type == "array" then
# Remove low-value array elements.
- map(select(trivia | not))
+ map(select(trivia | not)) | map(transform)
else .
end
