Skip to content

Commit bd42d2c

Browse files
committed
add DSF (domain specific formats), experimental
1 parent 5994818 commit bd42d2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1366
-170
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apply plugin: 'java'
22

3-
version = '2.0.5'
3+
version = '2.1.0'
44
group = 'org.hjson'
55
description = """Hjson, the Human JSON."""
66

cli/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'java'
22
apply plugin: 'maven'
33
apply plugin: 'application'
44

5-
version = '2.0.5'
5+
version = '2.1.0'
66
group = 'org.hjson.cli'
77
description = """Hjson CLI"""
88

cli/src/org.hjson.cli/Main.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import java.io.*;
55
import static java.lang.System.out;
66
import org.apache.commons.cli.*;
7+
8+
import java.lang.reflect.*;
79
import java.util.jar.Manifest;
810
import java.util.jar.Attributes;
911
import java.util.List;
12+
import java.util.ArrayList;
1013
import java.net.URL;
1114

1215
public class Main {
@@ -24,21 +27,31 @@ public static String convertStreamToString(InputStream is) throws IOException {
2427
return writer.toString();
2528
}
2629

27-
2830
public static void main(String[] args) throws Exception {
2931

3032
Options options=new Options();
31-
options.addOption(OptionBuilder.withLongOpt("help").withDescription("Show this screen.").create("h"));
32-
options.addOption(OptionBuilder.withDescription("Output as formatted JSON.").create("j"));
33-
options.addOption(OptionBuilder.withDescription("Output as JSON.").create("c"));
34-
options.addOption(OptionBuilder.withLongOpt("version").withDescription("Show version.").create("v"));
33+
options.addOption(Option.builder("h").longOpt("help").desc("Show this screen").build());
34+
options.addOption(Option.builder("j").desc("Output as formatted JSON").build());
35+
options.addOption(Option.builder("c").desc("Output as JSON").build());
36+
options.addOption(Option.builder("v").longOpt("version").desc("Show version").build());
37+
options.addOption(Option.builder().longOpt("math").desc("Enable math DSF (experimental)").build());
38+
options.addOption(Option.builder().longOpt("hex").desc("Enable hex DSF (experimental)").build());
39+
40+
HjsonOptions opt=new HjsonOptions();
3541

3642
CommandLineParser parser=new DefaultParser();
3743
HelpFormatter formatter=new HelpFormatter();
3844
CommandLine cmd;
3945

4046
try {
4147
cmd=parser.parse(options, args);
48+
49+
List<IHjsonDsfProvider> dsf=new ArrayList<IHjsonDsfProvider>();
50+
51+
if (cmd.hasOption("hex")) dsf.add(HjsonDsf.hex(false));
52+
if (cmd.hasOption("math")) dsf.add(HjsonDsf.math());
53+
opt.setDsfProviders(dsf.toArray(new IHjsonDsfProvider[0]));
54+
4255
if (cmd.hasOption("h")) {
4356
formatter.printHelp("hjson [INPUT]", options);
4457
return;
@@ -59,18 +72,16 @@ public static void main(String[] args) throws Exception {
5972

6073
if (cargs.isEmpty()) reader=new InputStreamReader(System.in);
6174
else reader=new FileReader(cargs.get(0));
62-
JsonValue value=JsonValue.readHjson(reader);
75+
JsonValue value=JsonValue.readHjson(reader, opt);
6376

6477
if (cmd.hasOption("j")) out.println(value.toString(Stringify.FORMATTED));
6578
else if (cmd.hasOption("c")) out.println(value.toString(Stringify.PLAIN));
66-
else out.println(value.toString(Stringify.HJSON));
79+
else out.println(value.toString(opt));
6780

6881
} catch (org.apache.commons.cli.ParseException e) {
6982
out.println(e.getMessage());
7083
formatter.printHelp("hjson [INPUT]", options);
7184
System.exit(1);
7285
}
73-
74-
7586
}
7687
}

docs/allclasses-frame.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
<!-- NewPage -->
33
<html lang="en">
44
<head>
5-
<!-- Generated by javadoc (1.8.0_45) on Mon Aug 01 23:42:29 CEST 2016 -->
6-
<title>All Classes (hjson 2.0.0 API)</title>
7-
<meta name="date" content="2016-08-01">
5+
<!-- Generated by javadoc (1.8.0_45) on Mon Sep 19 22:42:08 CEST 2016 -->
6+
<title>All Classes (hjson 2.1.0 API)</title>
7+
<meta name="date" content="2016-09-19">
88
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
99
<script type="text/javascript" src="script.js"></script>
1010
</head>
1111
<body>
1212
<h1 class="bar">All&nbsp;Classes</h1>
1313
<div class="indexContainer">
1414
<ul>
15+
<li><a href="org/hjson/HjsonDsf.html" title="class in org.hjson" target="classFrame">HjsonDsf</a></li>
1516
<li><a href="org/hjson/HjsonOptions.html" title="class in org.hjson" target="classFrame">HjsonOptions</a></li>
17+
<li><a href="org/hjson/IHjsonDsfProvider.html" title="interface in org.hjson" target="classFrame"><span class="interfaceName">IHjsonDsfProvider</span></a></li>
1618
<li><a href="org/hjson/JsonArray.html" title="class in org.hjson" target="classFrame">JsonArray</a></li>
1719
<li><a href="org/hjson/JsonObject.html" title="class in org.hjson" target="classFrame">JsonObject</a></li>
1820
<li><a href="org/hjson/JsonObject.Member.html" title="class in org.hjson" target="classFrame">JsonObject.Member</a></li>

docs/allclasses-noframe.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
<!-- NewPage -->
33
<html lang="en">
44
<head>
5-
<!-- Generated by javadoc (1.8.0_45) on Mon Aug 01 23:42:29 CEST 2016 -->
6-
<title>All Classes (hjson 2.0.0 API)</title>
7-
<meta name="date" content="2016-08-01">
5+
<!-- Generated by javadoc (1.8.0_45) on Mon Sep 19 22:42:08 CEST 2016 -->
6+
<title>All Classes (hjson 2.1.0 API)</title>
7+
<meta name="date" content="2016-09-19">
88
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
99
<script type="text/javascript" src="script.js"></script>
1010
</head>
1111
<body>
1212
<h1 class="bar">All&nbsp;Classes</h1>
1313
<div class="indexContainer">
1414
<ul>
15+
<li><a href="org/hjson/HjsonDsf.html" title="class in org.hjson">HjsonDsf</a></li>
1516
<li><a href="org/hjson/HjsonOptions.html" title="class in org.hjson">HjsonOptions</a></li>
17+
<li><a href="org/hjson/IHjsonDsfProvider.html" title="interface in org.hjson"><span class="interfaceName">IHjsonDsfProvider</span></a></li>
1618
<li><a href="org/hjson/JsonArray.html" title="class in org.hjson">JsonArray</a></li>
1719
<li><a href="org/hjson/JsonObject.html" title="class in org.hjson">JsonObject</a></li>
1820
<li><a href="org/hjson/JsonObject.Member.html" title="class in org.hjson">JsonObject.Member</a></li>

docs/constant-values.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
<!-- NewPage -->
33
<html lang="en">
44
<head>
5-
<!-- Generated by javadoc (1.8.0_45) on Mon Aug 01 23:42:29 CEST 2016 -->
6-
<title>Constant Field Values (hjson 2.0.0 API)</title>
7-
<meta name="date" content="2016-08-01">
5+
<!-- Generated by javadoc (1.8.0_45) on Mon Sep 19 22:42:08 CEST 2016 -->
6+
<title>Constant Field Values (hjson 2.1.0 API)</title>
7+
<meta name="date" content="2016-09-19">
88
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
99
<script type="text/javascript" src="script.js"></script>
1010
</head>
1111
<body>
1212
<script type="text/javascript"><!--
1313
try {
1414
if (location.href.indexOf('is-external=true') == -1) {
15-
parent.document.title="Constant Field Values (hjson 2.0.0 API)";
15+
parent.document.title="Constant Field Values (hjson 2.1.0 API)";
1616
}
1717
}
1818
catch(err) {

docs/deprecated-list.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
<!-- NewPage -->
33
<html lang="en">
44
<head>
5-
<!-- Generated by javadoc (1.8.0_45) on Mon Aug 01 23:42:29 CEST 2016 -->
6-
<title>Deprecated List (hjson 2.0.0 API)</title>
7-
<meta name="date" content="2016-08-01">
5+
<!-- Generated by javadoc (1.8.0_45) on Mon Sep 19 22:42:08 CEST 2016 -->
6+
<title>Deprecated List (hjson 2.1.0 API)</title>
7+
<meta name="date" content="2016-09-19">
88
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
99
<script type="text/javascript" src="script.js"></script>
1010
</head>
1111
<body>
1212
<script type="text/javascript"><!--
1313
try {
1414
if (location.href.indexOf('is-external=true') == -1) {
15-
parent.document.title="Deprecated List (hjson 2.0.0 API)";
15+
parent.document.title="Deprecated List (hjson 2.1.0 API)";
1616
}
1717
}
1818
catch(err) {

docs/help-doc.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
<!-- NewPage -->
33
<html lang="en">
44
<head>
5-
<!-- Generated by javadoc (1.8.0_45) on Mon Aug 01 23:42:29 CEST 2016 -->
6-
<title>API Help (hjson 2.0.0 API)</title>
7-
<meta name="date" content="2016-08-01">
5+
<!-- Generated by javadoc (1.8.0_45) on Mon Sep 19 22:42:08 CEST 2016 -->
6+
<title>API Help (hjson 2.1.0 API)</title>
7+
<meta name="date" content="2016-09-19">
88
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
99
<script type="text/javascript" src="script.js"></script>
1010
</head>
1111
<body>
1212
<script type="text/javascript"><!--
1313
try {
1414
if (location.href.indexOf('is-external=true') == -1) {
15-
parent.document.title="API Help (hjson 2.0.0 API)";
15+
parent.document.title="API Help (hjson 2.1.0 API)";
1616
}
1717
}
1818
catch(err) {

0 commit comments

Comments
 (0)