-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix quoteless string starting with punctuator - add cli
- Loading branch information
Showing
34 changed files
with
310 additions
and
68 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 |
---|---|---|
|
@@ -4,3 +4,5 @@ gradle | |
gradlew | ||
gradle.bat | ||
build/ | ||
hjson.iml | ||
.idea |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
ql-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ | ||
js-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ | ||
ml-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"ql-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", | ||
"js-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", | ||
"ml-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ql-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ | ||
js-ascii: "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" | ||
ml-ascii: | ||
''' | ||
! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ | ||
''' |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"": empty | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"": "empty" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"": empty | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
A quoteless string is OK, | ||
but two must be contained in an array. |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
# invalid quoteless string | ||
ql: ] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
# invalid quoteless string | ||
ql: } | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
# invalid quoteless string | ||
ql: { | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
# invalid quoteless string | ||
ql: [ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
# invalid quoteless string | ||
ql: : | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
# invalid quoteless string | ||
ql: , | ||
} |
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
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 +1 @@ | ||
foo=bar | ||
allow quoteless strings |
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 +1 @@ | ||
"foo=bar" | ||
"allow quoteless strings" |
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 +1 @@ | ||
foo=bar | ||
allow quoteless strings |
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 |
---|---|---|
|
@@ -70,5 +70,4 @@ | |
two: "2" | ||
minus: "-3" | ||
} | ||
"": empty | ||
} |
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 |
---|---|---|
|
@@ -49,6 +49,5 @@ | |
"one": "1", | ||
"two": "2", | ||
"minus": "-3" | ||
}, | ||
"": "empty" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -75,6 +75,4 @@ | |
two: "2" | ||
minus: "-3" | ||
} | ||
|
||
"": empty | ||
} |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
charset_test.hjson | ||
comments_test.hjson | ||
empty_test.hjson | ||
fail10_test.json | ||
fail11_test.json | ||
fail12_test.json | ||
fail13_test.json | ||
fail14_test.json | ||
fail15_test.json | ||
fail16_test.json | ||
fail17_test.json | ||
fail19_test.json | ||
fail20_test.json | ||
fail21_test.json | ||
fail22_test.json | ||
fail23_test.json | ||
fail24_test.json | ||
fail26_test.json | ||
fail28_test.json | ||
fail29_test.json | ||
fail2_test.json | ||
fail30_test.json | ||
fail31_test.json | ||
fail32_test.json | ||
fail33_test.json | ||
fail34_test.json | ||
fail5_test.json | ||
fail6_test.json | ||
fail7_test.json | ||
fail8_test.json | ||
failKey1_test.hjson | ||
failKey2_test.hjson | ||
failKey3_test.hjson | ||
failObj1_test.hjson | ||
failObj2_test.hjson | ||
failObj3_test.hjson | ||
failStr1_test.hjson | ||
failStr2_test.hjson | ||
failStr3_test.hjson | ||
failStr4_test.hjson | ||
failStr5_test.hjson | ||
failStr6_test.hjson | ||
kan_test.hjson | ||
keys_test.hjson | ||
oa_test.hjson | ||
pass1_test.json | ||
pass2_test.json | ||
pass3_test.json | ||
pass4_test.json | ||
passSingle_test.hjson | ||
root_test.hjson | ||
stringify1_test.hjson | ||
strings_test.hjson | ||
trail_test.hjson |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
SELF=`dirname $0` | ||
java -jar $SELF/Hjson-cli.jar $* |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@echo off | ||
java -jar %~dp0\Hjson-cli.jar %* |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
apply plugin: 'java' | ||
apply plugin: 'maven' | ||
apply plugin: 'application' | ||
|
||
version = '2.0.0' | ||
group = 'org.hjson.cli' | ||
description = """Hjson CLI""" | ||
|
||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
|
||
sourceSets { | ||
main { | ||
java { | ||
srcDir 'src' | ||
} | ||
} | ||
} | ||
|
||
repositories { | ||
flatDir { | ||
dirs '../build/libs' | ||
} | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile 'org.hjson:hjson:'+version | ||
compile 'commons-cli:commons-cli:1.3.1' | ||
} | ||
|
||
mainClassName = 'org.hjson.cli.Main' | ||
|
||
jar { | ||
baseName = 'Hjson' | ||
manifest { | ||
attributes( | ||
'Class-Path': configurations.compile.collect { it.getName() }.join(' '), | ||
'Main-Class': 'org.hjson.cli.Main', | ||
'Hjson-Version': version, | ||
) | ||
} | ||
} | ||
|
||
task distjar(type: Jar) { | ||
manifest=jar.manifest | ||
archiveName="Hjson-cli.jar" | ||
//baseName="Hjson-dist" | ||
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } | ||
with jar | ||
|
||
} | ||
|
||
task dist(type: Copy, dependsOn: distjar) { | ||
from('build/libs') { | ||
include '*.jar' | ||
} | ||
from('bin') { | ||
include '*' | ||
} | ||
into 'build/target' | ||
} | ||
|
||
task zip(type:Zip, dependsOn: dist) { | ||
from ('build/target') | ||
include '*' | ||
archiveName 'hjson.zip' | ||
destinationDir file('build/zip') | ||
} |
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.hjson.cli; | ||
|
||
import org.hjson.*; | ||
import java.io.*; | ||
import static java.lang.System.out; | ||
import org.apache.commons.cli.*; | ||
import java.util.jar.Manifest; | ||
import java.util.jar.Attributes; | ||
import java.util.List; | ||
import java.net.URL; | ||
|
||
public class Main { | ||
|
||
public static String convertStreamToString(InputStream is) throws IOException { | ||
Writer writer=new StringWriter(); | ||
char[] buffer=new char[1024]; | ||
try { | ||
Reader reader=new BufferedReader(new InputStreamReader(is, "UTF-8")); | ||
int n; | ||
while ((n=reader.read(buffer))!=-1) writer.write(buffer, 0, n); | ||
} finally { | ||
is.close(); | ||
} | ||
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")); | ||
|
||
CommandLineParser parser=new DefaultParser(); | ||
HelpFormatter formatter=new HelpFormatter(); | ||
CommandLine cmd; | ||
|
||
try { | ||
cmd=parser.parse(options, args); | ||
if (cmd.hasOption("h")) { | ||
formatter.printHelp("hjson [INPUT]", options); | ||
return; | ||
} else if (cmd.hasOption("v")) { | ||
String className=JsonObject.class.getSimpleName()+".class"; | ||
String classPath=JsonObject.class.getResource(className).toString(); | ||
if (!classPath.startsWith("jar")) return; | ||
String manifestPath=classPath.substring(0, classPath.lastIndexOf("!")+1)+"/META-INF/MANIFEST.MF"; | ||
Attributes attr=new Manifest(new URL(manifestPath).openStream()).getMainAttributes(); | ||
out.println("hjson v"+attr.getValue("Hjson-Version")); | ||
return; | ||
} | ||
|
||
List<String> cargs=cmd.getArgList(); | ||
Reader reader; | ||
|
||
if (cargs.size()>1) throw new org.apache.commons.cli.ParseException("input"); | ||
|
||
if (cargs.isEmpty()) reader=new InputStreamReader(System.in); | ||
else reader=new FileReader(cargs.get(0)); | ||
JsonValue value=JsonValue.readHjson(reader); | ||
|
||
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)); | ||
|
||
} catch (org.apache.commons.cli.ParseException e) { | ||
out.println(e.getMessage()); | ||
formatter.printHelp("hjson [INPUT]", options); | ||
System.exit(1); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.