-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from wader/format-simplify-torepr
format: Simplify torepr, no need for _f function
- Loading branch information
Showing
5 changed files
with
51 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
def _asn1_ber_torepr: | ||
def _f: | ||
if .class == "universal" then | ||
if .tag | . == "sequence" or . == "set" then | ||
.constructed | map(_f) | ||
else .value | tovalue | ||
end | ||
else .constructed | map(_f) | ||
end; | ||
_f; | ||
if .class == "universal" then | ||
if .tag | . == "sequence" or . == "set" then | ||
.constructed | map(_asn1_ber_torepr) | ||
else .value | tovalue | ||
end | ||
else .constructed | map(_asn1_ber_torepr) | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
def _bencode_torepr: | ||
def _f: | ||
if .type == "string" then .value | tovalue | ||
elif .type == "integer" then .value | tovalue | ||
elif .type == "list" then .values | map(_f) | ||
elif .type == "dictionary" then | ||
( .pairs | ||
| map({key: (.key | _f), value: (.value | _f)}) | ||
| from_entries | ||
) | ||
else error("unknown type \(.type)") | ||
end; | ||
_f; | ||
if .type == "string" then .value | tovalue | ||
elif .type == "integer" then .value | tovalue | ||
elif .type == "list" then .values | map(_bencode_torepr) | ||
elif .type == "dictionary" then | ||
( .pairs | ||
| map({key: (.key | _bencode_torepr), value: (.value | _bencode_torepr)}) | ||
| from_entries | ||
) | ||
else error("unknown type \(.type)") | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
def _cbor_torepr: | ||
def _f: | ||
( if .major_type == "map" then | ||
( .pairs | ||
| map({key: (.key | _f), value: (.value | _f)}) | ||
| from_entries | ||
) | ||
elif .major_type == "array" then .elements | map(_f) | ||
elif .major_type == "bytes" then .value | tostring | ||
else .value | tovalue | ||
end | ||
); | ||
_f; | ||
if .major_type == "map" then | ||
( .pairs | ||
| map({key: (.key | _cbor_torepr), value: (.value | _cbor_torepr)}) | ||
| from_entries | ||
) | ||
elif .major_type == "array" then .elements | map(_cbor_torepr) | ||
elif .major_type == "bytes" then .value | tostring | ||
else .value | tovalue | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
def _msgpack_torepr: | ||
def _f: | ||
( if .type | . == "fixmap" or . == "map16" or . == "map32" then | ||
( .pairs | ||
| map({key: (.key | _f), value: (.value | _f)}) | ||
| from_entries | ||
) | ||
elif .type | . == "fixarray" or . == "array16" or . == "array32" then .elements | map(_f) | ||
elif .type | . == "bin8" or . == "bin16" or . == "bin32" then .value | tostring | ||
else .value | tovalue | ||
end | ||
); | ||
_f; | ||
if .type | . == "fixmap" or . == "map16" or . == "map32" then | ||
( .pairs | ||
| map({key: (.key | _msgpack_torepr), value: (.value | _msgpack_torepr)}) | ||
| from_entries | ||
) | ||
elif .type | . == "fixarray" or . == "array16" or . == "array32" then .elements | map(_msgpack_torepr) | ||
elif .type | . == "bin8" or . == "bin16" or . == "bin32" then .value | tostring | ||
else .value | tovalue | ||
end; |