;
use utf8;
package JSON::Relaxed;
use JSON::Relaxed::Parser; our $VERSION = $JSON::Relaxed::Parser::VERSION;
=encoding UTF-8
=head1 NAME
JSON::Relaxed -- An extension of JSON that allows for bet
=head1 Relaxed JSON?
There's been increasing support for the idea of expanding JSON to improve
human-readability.
"Relaxed" JSON (RJSON) is a term that has been used to describe a
JSON-ish format tha
that JSON doesn't.
Most notably, RJSON allows the use of JavaScript-like comments and
eliminates the need to quote all keys and values.
An (official) specification can be found on
L<RelaxedJSON.org|h
use Object::Pad;
use utf8;
package JSON::Relaxed::Parser;
our $VERSION = "0.098";
class JSON::Relaxed::Parser;
# Instance data.
field $data :mutator; # RJSON string being parser
field @pretoks;
tandard.
# Strict true -> RJSON conformant.
# Strict false (default) -> RRJSON. Everything goes :).
field $strict :mutator :param = 0;
# Allow extra stuff after the JSON structure.
# Strict mode
input
if ( $booleans ) {
if ( ref($booleans) ne 'ARRAY' ) {
$booleans = [ $JSON::Boolean::false, $JSON::Boolean::true ];
}
}
else {
$booleans = [ 0, 1 ];
}
my $glue = 0;
d_attr) );
use utf8;
=head1 NAME
Class::JSON_Object - Role for Class::JSON_Object
=head1 SYNOPSIS
use Object::Pad;
class Action :does(Class::JSON_Object) {
field $operation;
f
ield $arg;
}
# Create instance and load from JSON.
my $op = Action->new->load('{"operation":"move","arg":42}');
# Accessors are automatically provided.
say "Operation = ", $op->o
n the form of
JavaScript objects in JSON format. This class, actually a role, makes
it easy to define classes that construct Perl objects that correspond to
the JSON objects.
The intention is that th
e JSON::Relaxed::ErrorCodes;
use JSON::Relaxed::Parser; our $VERSION = $JSON::Relaxed::Parser::VERSION;
=head1 JSON::Relaxed::ErrorCodes -- Error messages
If the document cannot be parsed, JSON::R
cy mode, JSON::Relaxed returns an undefined
value instead and sets the following error indicators:
=over 4
=item * $JSON::Relaxed::err_id
A unique code for a specific error.
=item * $JSON::Relaxed
ieved using
the parser methods err_id() and err_msg().
Following is a list of all error codes in JSON::Relaxed:
=over 4
=item * C<missing-input>
No input was found. This can be caused by:
$pa
$options->{verbose};
::break();
my @configs;
#
if ( $lines->[0] =~ /^##config:\s*json/ ) {
my $cf = "";
shift(@$lines);
$$linecnt++;
while ( @$lines ) {
if ( $lines->[0] =~ /
}
}
if ( $cf ) {
my $prename = "__PRECFG__";
my $precfg = ChordPro::Config->new( json_load( $cf, $prename ) );
$precfg->precheck($prename);
push( @configs, $precfg->prep_con
\n") unless $have;
push( @configs, $have->prep_configs($cf) );
}
else {
for ( "prp", "json" ) {
( my $cf = $diag->{file} ) =~ s/\.\w+$/.$_/;
$cf .= ".$_" if $cf eq $diag->{file};
nex
print( join( "\n",
$mode && $mode == 2
? @{ json_chords(\@chordnames ) }
: @{ list_chords(\@chordnames, "__CLI__", 1) } ), "\n" );
}
sub json_chords ( $chords ) {
assert_tuning();
my
T, 'pv' );
# Processing JSON.
sub json_load( $json, $source = "<builtin>" ) {
my $info = json_parser();
if ( $info->{parser} eq "JSON::Relaxed" ) {
state $pp = JSON::Relaxed::Parser->new( c
ta = $pp->decode($json."\n");
return $data unless $pp->is_error;
$source .= ": " if $source;
die("${source}JSON error: " . $pp->err_msg . "\n");
}
else {
state $pp = JSON::PP->new;
# Glu
some relaxation.
$json =~ s/"\s*\\\n\s*"//g;
$pp->relaxed if $info->{relaxed};
$pp->decode($json."\n");
}
}
# JSON parser, what and how (also used by runtimeinfo().
sub json_parser() {
my
This can
be used to produce documents with back matter pages.
=item B<--config=>I<JSON> (shorter: B<--cfg>)
A JSON file that defines the behaviour of the program and the layout
of the output. See L
nfig file depends on the operating system and user
environment. A common value is C</etc/chordpro.json> on Linux systems.
This is the place where the system manager can put settings like the
paper si
ystem and user
environment. Common values are C<$HOME/.config/chordpro/chordpro.json>
and C<$HOME/.chordpro/chordpro.json>, where C<$HOME> indicates the
user home directory.
Here you can put settings
);
# Establish config files. Global config is easy.
for ( $self->normalize("/etc/$app_lc.json") ) {
next unless $_ && -f;
$configs->{sysconfig} = $_;
}
$configs = {};
# The use
alize( fn_catfile( $path, "$app_lc.prp" ) ),
$self->normalize( fn_catfile( $path, "$app_lc.json" ) ) ) {
next unless $_ && fs_test( f => $_ );
$configs->{userconfig} = $_;
last;
gdir // "<undef>", "\n") if $self->debug;
for ( $self->normalize(".$app_lc.json"),
$self->normalize("$app_lc.json") ) {
next unless $_ && fs_test( f => $_ );
$configs->{config} = $_;
la
le"),
"", $self->GetParent->{prefs_configfile} || "",
"Config files (*.prp,*.json)|*.prp;*.json|All files|*.*",
0|wxFD_OPEN,
wxDefaultPosition);
my $ret = $fd->ShowModa
new );
# die("PANIC! Config merge error")
# unless UNIVERSAL::isa( $cfg->{settings}->{strict}, 'JSON::Boolean' );
# use DDP; p $cfg->{pdf}->{songbook}, as => "accum after \"$file\"";
}
# H
xpand_tilde($file);
if ( $file =~ /\.json$/i ) {
if ( my $lines = fs_load( $file, { split => 1, fail => "soft" } ) ) {
my $new = json_load( join( "\n", @$lines, '' ), $file );
delete $cfg->{_chords};
delete $cfg->{chords};
delete $cfg->{_src};
my $parser = JSON::Relaxed::Parser->new( key_order => 1 );
# Load schema.
my $schema = do {
my $schema =
properties were defined.
Data::Properties can also be used to define data structures, just like
JSON but with much less quotes.
Property lookup can use a preset property context. If a context I<ctx
##############
use JSON::Relaxed qw();
use JSON::XS qw();
use File::LoadLines;
use Encode qw(decode_utf8);
binmode STDOUT => ':utf8';
binmode STDERR => ':utf8';
my $parser = JSON::Relaxed::Parser->n
> "soft" };
my $json = loadlines( $file, $opts );
die( "$file: $opts->{error}\n") if $opts->{error};
my $data = $parser->decode($json);
if ( $parser->is_error ) {
warn( "$file: JSON error: ", $par
ser->err_msg, "\n" );
next;
}
my $writer = JSON::XS->new->canonical->utf8(0)->pretty($test)->convert_blessed;
if ( $output && $output ne "-" ) {
open( my $fd, '>:utf8', $output )
or die
p} };
}
exists( $symbols->{"strum_$code"} );
}
push( @EXPORT, qw( is_strum ) );
sub as_json() {
my $ret = "{\n";
for ( sort keys %$symbols ) {
$ret .= qq{ "$_" : };
my $s = $symb
u%04x"}, ord($s) );
}
$ret .= ",\n";
}
$ret =~ s/,\n$/\n/;
$ret .= "}\n";
}
push( @EXPORT_OK, qw( as_json ) );
1;
unless ( caller ) {
$symbols || _build();
print as_json();
}
.26;
use Object::Pad;
# Output backend to extract meta data.
class ChordPro::Output::Meta;
use JSON::PP;
use ChordPro::Utils qw( qquote max );
use Ref::Util qw(is_arrayref);
my $sep = "; ";
metho
w( $self,
"Select a new configuration file",
"", "customconfig",
"*.json",
wxFD_SAVE|wxFD_OVERWRITE_PROMPT
);
my $ret = $fd->ShowModal;
return unless
;
my $cfg = fn_catfile( CP->findresdirs("config")->[-1],
$state{expert}
? "chordpro.json"
: "config.tmpl" );
if ( fs_copy( $cfg, $fn ) ) {
$self->{fp_customconfig}->SetPath( fn
fig}->GetPath;
unless ( $path =~ /\.\w+$/ ) {
$self->{fp_customconfig}->SetPath( $path .= ".json" );
}
return if fs_test( s => $path ); # existing config
my $md = Wx::MessageDialog
:Locale gettext => '_T';
use ChordPro::Files;
use ChordPro::Paths;
use ChordPro::Utils qw( plural json_load is_true );
use constant FONTSIZE => 12;
use constant SETTINGS_VERSION => 3;
use Encode qw(
sified) configs.
skipoldcfg => 0,
# Presets.
# Title as defined by or derived from the JSON file.
# When multiple presets are possible, a list of titles separated by TABs
# (which are
y %instruments; # new style
my %tasks; # new style
my $findopts = { filter => qr/^.*\.json$/i, recurse => 0 };
local $ENV{CHORDPRO_LIB};
CP->setup_resdirs;
# Collect standard
ew($self->{nb_config}, wxID_ANY, "", "Select a configuration file", "Config files (*.prp,*.json)|*.prp;*.json");
$self->{fp_customconfig}->SetToolTip(_T("Select the custom configuration file to be
// Configuration for ChordPro
//
// This is a really relaxed JSON document, see
// https://metacpan.org/pod/JSON::Relaxed#REALLY-RELAXED-EXTENSIONS
// For GUI.
config {
QuickJS.
// Handler "quickjs_xs" uses embedded QuickJS only.
// Handler "quickjs_qjs" uses external QuickJS only.
// Handler "quickjs" uses internal or external Qu
This can
be used to produce documents with back matter pages.
=item B<--config=>I<JSON> (shorter: B<--cfg>)
A JSON file that defines the behaviour of the program and the layout
of the output. See L
nfig file depends on the operating system and user
environment. A common value is C</etc/chordpro.json> on Linux systems.
This is the place where the system manager can put settings like the
paper si
ystem and user
environment. Common values are C<$HOME/.config/chordpro/chordpro.json>
and C<$HOME/.chordpro/chordpro.json>, where C<$HOME> indicates the
user home directory.
Here you can put settings