summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2011-07-27 02:14:54 +0200
committerFlorian Frank <flori@ping.de>2011-07-27 02:40:10 +0200
commitbdb2b910a5ebd92471de13d7e90d54408f6b093e (patch)
treeae717c3fa4721733def0fe5b450fd350380814ce /java
parent9320a2a18a4d09f8e8a83129db793057968928b1 (diff)
downloadjson-bdb2b910a5ebd92471de13d7e90d54408f6b093e.tar.gz
started quirks mode for generator
Diffstat (limited to 'java')
-rw-r--r--java/src/json/ext/Generator.java6
-rw-r--r--java/src/json/ext/GeneratorMethods.java4
-rw-r--r--java/src/json/ext/GeneratorService.java2
-rw-r--r--java/src/json/ext/GeneratorState.java46
-rw-r--r--java/src/json/ext/OptionsReader.java2
-rw-r--r--java/src/json/ext/Parser.java74
-rw-r--r--java/src/json/ext/Parser.rl30
-rw-r--r--java/src/json/ext/ParserService.java2
-rw-r--r--java/src/json/ext/Utils.java2
9 files changed, 96 insertions, 72 deletions
diff --git a/java/src/json/ext/Generator.java b/java/src/json/ext/Generator.java
index fbc394f..78dc078 100644
--- a/java/src/json/ext/Generator.java
+++ b/java/src/json/ext/Generator.java
@@ -1,6 +1,6 @@
/*
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
- *
+ *
* Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
* for details.
*/
@@ -85,11 +85,11 @@ public final class Generator {
/**
* A class that concentrates all the information that is shared by
* generators working on a single session.
- *
+ *
* <p>A session is defined as the process of serializing a single root
* object; any handler directly called by container handlers (arrays and
* hashes/objects) shares this object with its caller.
- *
+ *
* <p>Note that anything called indirectly (via {@link GENERIC_HANDLER})
* won't be part of the session.
*/
diff --git a/java/src/json/ext/GeneratorMethods.java b/java/src/json/ext/GeneratorMethods.java
index 356f2d0..637b579 100644
--- a/java/src/json/ext/GeneratorMethods.java
+++ b/java/src/json/ext/GeneratorMethods.java
@@ -1,6 +1,6 @@
/*
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
- *
+ *
* Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
* for details.
*/
@@ -25,7 +25,7 @@ import org.jruby.util.ByteList;
/**
* A class that populates the
* <code>Json::Ext::Generator::GeneratorMethods</code> module.
- *
+ *
* @author mernen
*/
class GeneratorMethods {
diff --git a/java/src/json/ext/GeneratorService.java b/java/src/json/ext/GeneratorService.java
index 2f3b07e..ed33639 100644
--- a/java/src/json/ext/GeneratorService.java
+++ b/java/src/json/ext/GeneratorService.java
@@ -1,6 +1,6 @@
/*
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
- *
+ *
* Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
* for details.
*/
diff --git a/java/src/json/ext/GeneratorState.java b/java/src/json/ext/GeneratorState.java
index f04eda2..a53ff12 100644
--- a/java/src/json/ext/GeneratorState.java
+++ b/java/src/json/ext/GeneratorState.java
@@ -1,6 +1,6 @@
/*
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
- *
+ *
* Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
* for details.
*/
@@ -24,10 +24,10 @@ import org.jruby.util.ByteList;
/**
* The <code>JSON::Ext::Generator::State</code> class.
- *
+ *
* <p>This class is used to create State instances, that are use to hold data
* while generating a JSON text from a a Ruby data structure.
- *
+ *
* @author mernen
*/
public class GeneratorState extends RubyObject {
@@ -76,6 +76,11 @@ public class GeneratorState extends RubyObject {
*/
private boolean asciiOnly = DEFAULT_ASCII_ONLY;
static final boolean DEFAULT_ASCII_ONLY = false;
+ /**
+ * XXX
+ */
+ private boolean quirksMode = DEFAULT_QUIRKS_MODE;
+ static final boolean DEFAULT_QUIRKS_MODE = false;
/**
* The current depth (inside a #to_json call)
@@ -94,7 +99,7 @@ public class GeneratorState extends RubyObject {
/**
* <code>State.from_state(opts)</code>
- *
+ *
* <p>Creates a State object from <code>opts</code>, which ought to be
* {@link RubyHash Hash} to create a new <code>State</code> instance
* configured by <codes>opts</code>, something else to create an
@@ -136,11 +141,11 @@ public class GeneratorState extends RubyObject {
/**
* <code>State#initialize(opts = {})</code>
- *
+ *
* Instantiates a new <code>State</code> object, configured by <code>opts</code>.
- *
+ *
* <code>opts</code> can have the following keys:
- *
+ *
* <dl>
* <dt><code>:indent</code>
* <dd>a {@link RubyString String} used to indent levels (default: <code>""</code>)
@@ -151,7 +156,7 @@ public class GeneratorState extends RubyObject {
* <dd>a String that is put before a <code>":"</code> pair delimiter
* (default: <code>""</code>)
* <dt><code>:object_nl</code>
- * <dd>a String that is put at the end of a JSON object (default: <code>""</code>)
+ * <dd>a String that is put at the end of a JSON object (default: <code>""</code>)
* <dt><code>:array_nl</code>
* <dd>a String that is put at the end of a JSON array (default: <code>""</code>)
* <dt><code>:allow_nan</code>
@@ -181,6 +186,7 @@ public class GeneratorState extends RubyObject {
this.maxNesting = orig.maxNesting;
this.allowNaN = orig.allowNaN;
this.asciiOnly = orig.asciiOnly;
+ this.quirksMode = orig.quirksMode;
this.depth = orig.depth;
return this;
}
@@ -191,7 +197,7 @@ public class GeneratorState extends RubyObject {
@JRubyMethod
public IRubyObject generate(ThreadContext context, IRubyObject obj) {
RubyString result = Generator.generateJson(context, obj, this);
- if (!objectOrArrayLiteral(result)) {
+ if (!quirksMode && !objectOrArrayLiteral(result)) {
throw Utils.newException(context, Utils.M_GENERATOR_ERROR,
"only generation of JSON objects or arrays allowed");
}
@@ -364,6 +370,22 @@ public class GeneratorState extends RubyObject {
return context.getRuntime().newBoolean(asciiOnly);
}
+ @JRubyMethod(name="quirks_mode")
+ public RubyBoolean quirks_mode_get(ThreadContext context) {
+ return context.getRuntime().newBoolean(quirksMode);
+ }
+
+ @JRubyMethod(name="quirks_mode=")
+ public IRubyObject quirks_mode_set(IRubyObject quirks_mode) {
+ quirksMode = quirks_mode.isTrue();
+ return quirks_mode.getRuntime().newBoolean(quirksMode);
+ }
+
+ @JRubyMethod(name="quirks_mode?")
+ public RubyBoolean quirks_mode_p(ThreadContext context) {
+ return context.getRuntime().newBoolean(quirksMode);
+ }
+
public int getDepth() {
return depth;
}
@@ -390,7 +412,7 @@ public class GeneratorState extends RubyObject {
/**
* <code>State#configure(opts)</code>
- *
+ *
* <p>Configures this State instance with the {@link RubyHash Hash}
* <code>opts</code>, and returns itself.
* @param vOpts The options hash
@@ -418,6 +440,7 @@ public class GeneratorState extends RubyObject {
maxNesting = opts.getInt("max_nesting", DEFAULT_MAX_NESTING);
allowNaN = opts.getBool("allow_nan", DEFAULT_ALLOW_NAN);
asciiOnly = opts.getBool("ascii_only", DEFAULT_ASCII_ONLY);
+ quirksMode = opts.getBool("quirks_mode", DEFAULT_QUIRKS_MODE);
depth = opts.getInt("depth", 0);
@@ -426,7 +449,7 @@ public class GeneratorState extends RubyObject {
/**
* <code>State#to_h()</code>
- *
+ *
* <p>Returns the configuration instance variables as a hash, that can be
* passed to the configure method.
* @return
@@ -443,6 +466,7 @@ public class GeneratorState extends RubyObject {
result.op_aset(context, runtime.newSymbol("array_nl"), array_nl_get(context));
result.op_aset(context, runtime.newSymbol("allow_nan"), allow_nan_p(context));
result.op_aset(context, runtime.newSymbol("ascii_only"), ascii_only_p(context));
+ result.op_aset(context, runtime.newSymbol("quirks_mode"), quirks_mode_p(context));
result.op_aset(context, runtime.newSymbol("max_nesting"), max_nesting_get(context));
result.op_aset(context, runtime.newSymbol("depth"), depth_get(context));
return result;
diff --git a/java/src/json/ext/OptionsReader.java b/java/src/json/ext/OptionsReader.java
index c9c9c94..a0b76b1 100644
--- a/java/src/json/ext/OptionsReader.java
+++ b/java/src/json/ext/OptionsReader.java
@@ -1,6 +1,6 @@
/*
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
- *
+ *
* Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
* for details.
*/
diff --git a/java/src/json/ext/Parser.java b/java/src/json/ext/Parser.java
index cea42d4..6f9b30a 100644
--- a/java/src/json/ext/Parser.java
+++ b/java/src/json/ext/Parser.java
@@ -2,7 +2,7 @@
// line 1 "Parser.rl"
/*
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
- *
+ *
* Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
* for details.
*/
@@ -31,16 +31,16 @@ import org.jruby.util.ByteList;
/**
* The <code>JSON::Ext::Parser</code> class.
- *
+ *
* <p>This is the JSON parser implemented as a Java class. To use it as the
* standard parser, set
* <pre>JSON.parser = JSON::Ext::Parser</pre>
* This is performed for you when you <code>include "json/ext"</code>.
- *
+ *
* <p>This class does not perform the actual parsing, just acts as an interface
* to Ruby code. When the {@link #parse()} method is invoked, a
* Parser.ParserSession object is instantiated, which handles the process.
- *
+ *
* @author mernen
*/
public class Parser extends RubyObject {
@@ -71,7 +71,7 @@ public class Parser extends RubyObject {
/**
* Multiple-value return for internal parser methods.
- *
+ *
* <p>All the <code>parse<var>Stuff</var></code> methods return instances of
* <code>ParserResult</code> when successful, or <code>null</code> when
* there's a problem with the input data.
@@ -100,18 +100,18 @@ public class Parser extends RubyObject {
/**
* <code>Parser.new(source, opts = {})</code>
- *
+ *
* <p>Creates a new <code>JSON::Ext::Parser</code> instance for the string
* <code>source</code>.
* It will be configured by the <code>opts</code> Hash.
* <code>opts</code> can have the following keys:
- *
+ *
* <dl>
* <dt><code>:max_nesting</code>
* <dd>The maximum depth of nesting allowed in the parsed data
* structures. Disable depth checking with <code>:max_nesting => false|nil|0</code>,
* it defaults to 19.
- *
+ *
* <dt><code>:allow_nan</code>
* <dd>If set to <code>true</code>, allow <code>NaN</code>,
* <code>Infinity</code> and <code>-Infinity</code> in defiance of RFC 4627
@@ -120,15 +120,15 @@ public class Parser extends RubyObject {
* <dt><code>:symbolize_names</code>
* <dd>If set to <code>true</code>, returns symbols for the names (keys) in
* a JSON object. Otherwise strings are returned, which is also the default.
- *
+ *
* <dt><code>:create_additions</code>
* <dd>If set to <code>false</code>, the Parser doesn't create additions
* even if a matchin class and <code>create_id</code> was found. This option
* defaults to <code>true</code>.
- *
+ *
* <dt><code>:object_class</code>
* <dd>Defaults to Hash.
- *
+ *
* <dt><code>:array_class</code>
* <dd>Defaults to Array.
* </dl>
@@ -229,7 +229,7 @@ public class Parser extends RubyObject {
/**
* <code>Parser#parse()</code>
- *
+ *
* <p>Parses the current JSON text <code>source</code> and returns the
* complete data structure as a result.
*/
@@ -240,7 +240,7 @@ public class Parser extends RubyObject {
/**
* <code>Parser#source()</code>
- *
+ *
* <p>Returns a copy of the current <code>source</code> string, that was
* used to construct this Parser.
*/
@@ -268,7 +268,7 @@ public class Parser extends RubyObject {
/**
* A string parsing session.
- *
+ *
* <p>Once a ParserSession is instantiated, the source string should not
* change until the parsing is complete. The ParserSession object assumes
* the source {@link RubyString} is still associated to its original
@@ -308,11 +308,11 @@ public class Parser extends RubyObject {
return context.getRuntime();
}
-
+
// line 335 "Parser.rl"
-
+
// line 317 "Parser.java"
private static byte[] init__JSON_value_actions_0()
{
@@ -434,14 +434,14 @@ static final int JSON_value_en_main = 1;
int cs = EVIL;
IRubyObject result = null;
-
+
// line 439 "Parser.java"
{
cs = JSON_value_start;
}
// line 448 "Parser.rl"
-
+
// line 446 "Parser.java"
{
int _klen;
@@ -675,7 +675,7 @@ case 5:
}
}
-
+
// line 680 "Parser.java"
private static byte[] init__JSON_integer_actions_0()
{
@@ -781,7 +781,7 @@ static final int JSON_integer_en_main = 1;
ParserResult parseInteger(int p, int pe) {
int cs = EVIL;
-
+
// line 786 "Parser.java"
{
cs = JSON_integer_start;
@@ -789,7 +789,7 @@ static final int JSON_integer_en_main = 1;
// line 474 "Parser.rl"
int memo = p;
-
+
// line 794 "Parser.java"
{
int _klen;
@@ -911,7 +911,7 @@ case 5:
return new ParserResult(number, p + 1);
}
-
+
// line 916 "Parser.java"
private static byte[] init__JSON_float_actions_0()
{
@@ -1020,7 +1020,7 @@ static final int JSON_float_en_main = 1;
ParserResult parseFloat(int p, int pe) {
int cs = EVIL;
-
+
// line 1025 "Parser.java"
{
cs = JSON_float_start;
@@ -1028,7 +1028,7 @@ static final int JSON_float_en_main = 1;
// line 510 "Parser.rl"
int memo = p;
-
+
// line 1033 "Parser.java"
{
int _klen;
@@ -1150,7 +1150,7 @@ case 5:
return new ParserResult(number, p + 1);
}
-
+
// line 1155 "Parser.java"
private static byte[] init__JSON_string_actions_0()
{
@@ -1260,7 +1260,7 @@ static final int JSON_string_en_main = 1;
int cs = EVIL;
IRubyObject result = null;
-
+
// line 1265 "Parser.java"
{
cs = JSON_string_start;
@@ -1268,7 +1268,7 @@ static final int JSON_string_en_main = 1;
// line 563 "Parser.rl"
int memo = p;
-
+
// line 1273 "Parser.java"
{
int _klen;
@@ -1408,7 +1408,7 @@ case 5:
}
});
} catch (JumpException e) { }
- if (memoArray[1] != null) {
+ if (memoArray[1] != null) {
RubyClass klass = (RubyClass) memoArray[1];
if (klass.respondsTo("json_creatable?") &&
klass.callMethod(context, "json_creatable?").isTrue()) {
@@ -1425,7 +1425,7 @@ case 5:
}
}
-
+
// line 1430 "Parser.java"
private static byte[] init__JSON_array_actions_0()
{
@@ -1556,14 +1556,14 @@ static final int JSON_array_en_main = 1;
(RubyArray)parser.arrayClass.newInstance(context,
IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
-
+
// line 1561 "Parser.java"
{
cs = JSON_array_start;
}
// line 652 "Parser.rl"
-
+
// line 1568 "Parser.java"
{
int _klen;
@@ -1697,7 +1697,7 @@ case 5:
}
}
-
+
// line 1702 "Parser.java"
private static byte[] init__JSON_object_actions_0()
{
@@ -1839,14 +1839,14 @@ static final int JSON_object_en_main = 1;
(RubyHash)parser.objectClass.newInstance(context,
IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
-
+
// line 1844 "Parser.java"
{
cs = JSON_object_start;
}
// line 731 "Parser.rl"
-
+
// line 1851 "Parser.java"
{
int _klen;
@@ -2016,7 +2016,7 @@ case 5:
return new ParserResult(returnedResult, p + 1);
}
-
+
// line 2021 "Parser.java"
private static byte[] init__JSON_actions_0()
{
@@ -2129,7 +2129,7 @@ static final int JSON_en_main = 1;
int p, pe;
IRubyObject result = null;
-
+
// line 2134 "Parser.java"
{
cs = JSON_start;
@@ -2138,7 +2138,7 @@ static final int JSON_en_main = 1;
// line 798 "Parser.rl"
p = byteList.begin();
pe = p + byteList.length();
-
+
// line 2143 "Parser.java"
{
int _klen;
diff --git a/java/src/json/ext/Parser.rl b/java/src/json/ext/Parser.rl
index 779d3f3..6b99574 100644
--- a/java/src/json/ext/Parser.rl
+++ b/java/src/json/ext/Parser.rl
@@ -1,6 +1,6 @@
/*
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
- *
+ *
* Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
* for details.
*/
@@ -29,16 +29,16 @@ import org.jruby.util.ByteList;
/**
* The <code>JSON::Ext::Parser</code> class.
- *
+ *
* <p>This is the JSON parser implemented as a Java class. To use it as the
* standard parser, set
* <pre>JSON.parser = JSON::Ext::Parser</pre>
* This is performed for you when you <code>include "json/ext"</code>.
- *
+ *
* <p>This class does not perform the actual parsing, just acts as an interface
* to Ruby code. When the {@link #parse()} method is invoked, a
* Parser.ParserSession object is instantiated, which handles the process.
- *
+ *
* @author mernen
*/
public class Parser extends RubyObject {
@@ -69,7 +69,7 @@ public class Parser extends RubyObject {
/**
* Multiple-value return for internal parser methods.
- *
+ *
* <p>All the <code>parse<var>Stuff</var></code> methods return instances of
* <code>ParserResult</code> when successful, or <code>null</code> when
* there's a problem with the input data.
@@ -98,18 +98,18 @@ public class Parser extends RubyObject {
/**
* <code>Parser.new(source, opts = {})</code>
- *
+ *
* <p>Creates a new <code>JSON::Ext::Parser</code> instance for the string
* <code>source</code>.
* It will be configured by the <code>opts</code> Hash.
* <code>opts</code> can have the following keys:
- *
+ *
* <dl>
* <dt><code>:max_nesting</code>
* <dd>The maximum depth of nesting allowed in the parsed data
* structures. Disable depth checking with <code>:max_nesting => false|nil|0</code>,
* it defaults to 19.
- *
+ *
* <dt><code>:allow_nan</code>
* <dd>If set to <code>true</code>, allow <code>NaN</code>,
* <code>Infinity</code> and <code>-Infinity</code> in defiance of RFC 4627
@@ -118,15 +118,15 @@ public class Parser extends RubyObject {
* <dt><code>:symbolize_names</code>
* <dd>If set to <code>true</code>, returns symbols for the names (keys) in
* a JSON object. Otherwise strings are returned, which is also the default.
- *
+ *
* <dt><code>:create_additions</code>
* <dd>If set to <code>false</code>, the Parser doesn't create additions
* even if a matchin class and <code>create_id</code> was found. This option
* defaults to <code>true</code>.
- *
+ *
* <dt><code>:object_class</code>
* <dd>Defaults to Hash.
- *
+ *
* <dt><code>:array_class</code>
* <dd>Defaults to Array.
* </dl>
@@ -227,7 +227,7 @@ public class Parser extends RubyObject {
/**
* <code>Parser#parse()</code>
- *
+ *
* <p>Parses the current JSON text <code>source</code> and returns the
* complete data structure as a result.
*/
@@ -238,7 +238,7 @@ public class Parser extends RubyObject {
/**
* <code>Parser#source()</code>
- *
+ *
* <p>Returns a copy of the current <code>source</code> string, that was
* used to construct this Parser.
*/
@@ -266,7 +266,7 @@ public class Parser extends RubyObject {
/**
* A string parsing session.
- *
+ *
* <p>Once a ParserSession is instantiated, the source string should not
* change until the parsing is complete. The ParserSession object assumes
* the source {@link RubyString} is still associated to its original
@@ -578,7 +578,7 @@ public class Parser extends RubyObject {
}
});
} catch (JumpException e) { }
- if (memoArray[1] != null) {
+ if (memoArray[1] != null) {
RubyClass klass = (RubyClass) memoArray[1];
if (klass.respondsTo("json_creatable?") &&
klass.callMethod(context, "json_creatable?").isTrue()) {
diff --git a/java/src/json/ext/ParserService.java b/java/src/json/ext/ParserService.java
index f2ecae1..dde8834 100644
--- a/java/src/json/ext/ParserService.java
+++ b/java/src/json/ext/ParserService.java
@@ -1,6 +1,6 @@
/*
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
- *
+ *
* Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
* for details.
*/
diff --git a/java/src/json/ext/Utils.java b/java/src/json/ext/Utils.java
index f52ac8d..44d6a55 100644
--- a/java/src/json/ext/Utils.java
+++ b/java/src/json/ext/Utils.java
@@ -1,6 +1,6 @@
/*
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
- *
+ *
* Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
* for details.
*/