aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-01-26 01:32:16 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2017-01-26 01:35:24 +0100
commita38ad4d64dc65170d690aaec6ff752f02758c078 (patch)
tree246bfe96e8290a9b28d11b26b565e0789f254e4d
parentcd4107b782ad91e7d9ee0eb15528fec6472223a8 (diff)
downloadjson-rpc-shell-a38ad4d64dc65170d690aaec6ff752f02758c078.tar.gz
json-rpc-shell-a38ad4d64dc65170d690aaec6ff752f02758c078.tar.xz
json-rpc-shell-a38ad4d64dc65170d690aaec6ff752f02758c078.zip
json-format.pl: further fixes
- skip_ws() -> gettoken() as it doesn't always skip whitespace - add a newline after each top-level token - since we've become a streaming parser, GNU parallel may not apply, so remove the comment at the top of the file
-rwxr-xr-xjson-format.pl15
1 files changed, 6 insertions, 9 deletions
diff --git a/json-format.pl b/json-format.pl
index f43488c..571e89e 100755
--- a/json-format.pl
+++ b/json-format.pl
@@ -1,6 +1,4 @@
#!/usr/bin/env perl
-# To speed up processing of large files, GNU parallel can be used:
-# $ parallel --pipe -k json-format.pl INPUT
use strict;
use warnings;
use Term::ANSIColor;
@@ -75,7 +73,7 @@ sub nexttoken ($) {
return 'ERROR', $text;
}
-sub skip_ws ($) {
+sub gettoken ($) {
my $json = shift;
while (my ($token, $text) = nexttoken $json) {
next if !$keep_ws && $token eq 'WS';
@@ -85,8 +83,7 @@ sub skip_ws ($) {
}
sub printindent () {
- print "\n";
- print ' ' x $indent;
+ print "\n", ' ' x $indent;
}
sub do_value ($$$);
@@ -94,7 +91,7 @@ sub do_object ($) {
my $json = shift;
my $in_field_name = 1;
my $first = 1;
- while (my ($token, $text) = skip_ws $json) {
+ while (my ($token, $text) = gettoken $json) {
if ($token eq 'COLON') {
$in_field_name = 0;
} elsif ($token eq 'COMMA') {
@@ -117,7 +114,7 @@ sub do_object ($) {
sub do_array ($) {
my $json = shift;
my $first = 1;
- while (my ($token, $text) = skip_ws $json) {
+ while (my ($token, $text) = gettoken $json) {
if ($token eq 'RBRACKET') {
$indent--;
printindent unless $keep_ws;
@@ -151,7 +148,7 @@ sub do_value ($$$) {
}
my @buffer;
-while (my ($token, $text) = skip_ws \@buffer) {
+while (my ($token, $text) = gettoken \@buffer) {
do_value $token, $text, \@buffer;
+ print "\n" unless $keep_ws;
}
-print "\n" unless $keep_ws;