Skip to content

Commit

Permalink
add DSF (domain specific formats), experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
laktak committed Sep 19, 2016
1 parent 5994818 commit bd42d2c
Show file tree
Hide file tree
Showing 45 changed files with 1,366 additions and 170 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'java'

version = '2.0.5'
version = '2.1.0'
group = 'org.hjson'
description = """Hjson, the Human JSON."""

Expand Down
2 changes: 1 addition & 1 deletion cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'application'

version = '2.0.5'
version = '2.1.0'
group = 'org.hjson.cli'
description = """Hjson CLI"""

Expand Down
29 changes: 20 additions & 9 deletions cli/src/org.hjson.cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import java.io.*;
import static java.lang.System.out;
import org.apache.commons.cli.*;

import java.lang.reflect.*;
import java.util.jar.Manifest;
import java.util.jar.Attributes;
import java.util.List;
import java.util.ArrayList;
import java.net.URL;

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


public static void main(String[] args) throws Exception {

Options options=new Options();
options.addOption(OptionBuilder.withLongOpt("help").withDescription("Show this screen.").create("h"));
options.addOption(OptionBuilder.withDescription("Output as formatted JSON.").create("j"));
options.addOption(OptionBuilder.withDescription("Output as JSON.").create("c"));
options.addOption(OptionBuilder.withLongOpt("version").withDescription("Show version.").create("v"));
options.addOption(Option.builder("h").longOpt("help").desc("Show this screen").build());
options.addOption(Option.builder("j").desc("Output as formatted JSON").build());
options.addOption(Option.builder("c").desc("Output as JSON").build());
options.addOption(Option.builder("v").longOpt("version").desc("Show version").build());
options.addOption(Option.builder().longOpt("math").desc("Enable math DSF (experimental)").build());
options.addOption(Option.builder().longOpt("hex").desc("Enable hex DSF (experimental)").build());

HjsonOptions opt=new HjsonOptions();

CommandLineParser parser=new DefaultParser();
HelpFormatter formatter=new HelpFormatter();
CommandLine cmd;

try {
cmd=parser.parse(options, args);

List<IHjsonDsfProvider> dsf=new ArrayList<IHjsonDsfProvider>();

if (cmd.hasOption("hex")) dsf.add(HjsonDsf.hex(false));
if (cmd.hasOption("math")) dsf.add(HjsonDsf.math());
opt.setDsfProviders(dsf.toArray(new IHjsonDsfProvider[0]));

if (cmd.hasOption("h")) {
formatter.printHelp("hjson [INPUT]", options);
return;
Expand All @@ -59,18 +72,16 @@ public static void main(String[] args) throws Exception {

if (cargs.isEmpty()) reader=new InputStreamReader(System.in);
else reader=new FileReader(cargs.get(0));
JsonValue value=JsonValue.readHjson(reader);
JsonValue value=JsonValue.readHjson(reader, opt);

if (cmd.hasOption("j")) out.println(value.toString(Stringify.FORMATTED));
else if (cmd.hasOption("c")) out.println(value.toString(Stringify.PLAIN));
else out.println(value.toString(Stringify.HJSON));
else out.println(value.toString(opt));

} catch (org.apache.commons.cli.ParseException e) {
out.println(e.getMessage());
formatter.printHelp("hjson [INPUT]", options);
System.exit(1);
}


}
}
8 changes: 5 additions & 3 deletions docs/allclasses-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_45) on Mon Aug 01 23:42:29 CEST 2016 -->
<title>All Classes (hjson 2.0.0 API)</title>
<meta name="date" content="2016-08-01">
<!-- Generated by javadoc (1.8.0_45) on Mon Sep 19 22:42:08 CEST 2016 -->
<title>All Classes (hjson 2.1.0 API)</title>
<meta name="date" content="2016-09-19">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h1 class="bar">All&nbsp;Classes</h1>
<div class="indexContainer">
<ul>
<li><a href="org/hjson/HjsonDsf.html" title="class in org.hjson" target="classFrame">HjsonDsf</a></li>
<li><a href="org/hjson/HjsonOptions.html" title="class in org.hjson" target="classFrame">HjsonOptions</a></li>
<li><a href="org/hjson/IHjsonDsfProvider.html" title="interface in org.hjson" target="classFrame"><span class="interfaceName">IHjsonDsfProvider</span></a></li>
<li><a href="org/hjson/JsonArray.html" title="class in org.hjson" target="classFrame">JsonArray</a></li>
<li><a href="org/hjson/JsonObject.html" title="class in org.hjson" target="classFrame">JsonObject</a></li>
<li><a href="org/hjson/JsonObject.Member.html" title="class in org.hjson" target="classFrame">JsonObject.Member</a></li>
Expand Down
8 changes: 5 additions & 3 deletions docs/allclasses-noframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_45) on Mon Aug 01 23:42:29 CEST 2016 -->
<title>All Classes (hjson 2.0.0 API)</title>
<meta name="date" content="2016-08-01">
<!-- Generated by javadoc (1.8.0_45) on Mon Sep 19 22:42:08 CEST 2016 -->
<title>All Classes (hjson 2.1.0 API)</title>
<meta name="date" content="2016-09-19">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h1 class="bar">All&nbsp;Classes</h1>
<div class="indexContainer">
<ul>
<li><a href="org/hjson/HjsonDsf.html" title="class in org.hjson">HjsonDsf</a></li>
<li><a href="org/hjson/HjsonOptions.html" title="class in org.hjson">HjsonOptions</a></li>
<li><a href="org/hjson/IHjsonDsfProvider.html" title="interface in org.hjson"><span class="interfaceName">IHjsonDsfProvider</span></a></li>
<li><a href="org/hjson/JsonArray.html" title="class in org.hjson">JsonArray</a></li>
<li><a href="org/hjson/JsonObject.html" title="class in org.hjson">JsonObject</a></li>
<li><a href="org/hjson/JsonObject.Member.html" title="class in org.hjson">JsonObject.Member</a></li>
Expand Down
8 changes: 4 additions & 4 deletions docs/constant-values.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_45) on Mon Aug 01 23:42:29 CEST 2016 -->
<title>Constant Field Values (hjson 2.0.0 API)</title>
<meta name="date" content="2016-08-01">
<!-- Generated by javadoc (1.8.0_45) on Mon Sep 19 22:42:08 CEST 2016 -->
<title>Constant Field Values (hjson 2.1.0 API)</title>
<meta name="date" content="2016-09-19">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Constant Field Values (hjson 2.0.0 API)";
parent.document.title="Constant Field Values (hjson 2.1.0 API)";
}
}
catch(err) {
Expand Down
8 changes: 4 additions & 4 deletions docs/deprecated-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_45) on Mon Aug 01 23:42:29 CEST 2016 -->
<title>Deprecated List (hjson 2.0.0 API)</title>
<meta name="date" content="2016-08-01">
<!-- Generated by javadoc (1.8.0_45) on Mon Sep 19 22:42:08 CEST 2016 -->
<title>Deprecated List (hjson 2.1.0 API)</title>
<meta name="date" content="2016-09-19">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Deprecated List (hjson 2.0.0 API)";
parent.document.title="Deprecated List (hjson 2.1.0 API)";
}
}
catch(err) {
Expand Down
8 changes: 4 additions & 4 deletions docs/help-doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_45) on Mon Aug 01 23:42:29 CEST 2016 -->
<title>API Help (hjson 2.0.0 API)</title>
<meta name="date" content="2016-08-01">
<!-- Generated by javadoc (1.8.0_45) on Mon Sep 19 22:42:08 CEST 2016 -->
<title>API Help (hjson 2.1.0 API)</title>
<meta name="date" content="2016-09-19">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="API Help (hjson 2.0.0 API)";
parent.document.title="API Help (hjson 2.1.0 API)";
}
}
catch(err) {
Expand Down
Loading

0 comments on commit bd42d2c

Please sign in to comment.