Skip to content

Commit

Permalink
Remove ParserOptions class, replace with normal TomlReadFeature bit f…
Browse files Browse the repository at this point in the history
…ield
  • Loading branch information
yawkat committed Mar 27, 2021
1 parent 51ed8ae commit f366d3b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ class Parser {
private static final JsonNodeFactory factory = new JsonNodeFactoryImpl();

private final JacksonTomlParseException.ErrorContext errorContext;
private final ParserOptions options;
private final int options;
private final Lexer lexer;

private TomlToken next;

private Parser(JacksonTomlParseException.ErrorContext errorContext, ParserOptions options, Reader reader) throws IOException {
private Parser(JacksonTomlParseException.ErrorContext errorContext, int options, Reader reader) throws IOException {
this.errorContext = errorContext;
this.options = options;
this.lexer = new Lexer(reader, errorContext);
this.next = lexer.yylex();
}

public static ObjectNode parse(JacksonTomlParseException.ErrorContext errorContext, ParserOptions options, Reader reader) throws IOException {
public static ObjectNode parse(JacksonTomlParseException.ErrorContext errorContext, int options, Reader reader) throws IOException {
return new Parser(errorContext, options, reader).parse();
}

Expand Down Expand Up @@ -191,7 +191,7 @@ private JsonNode parseDateTime(int nextState) throws IOException {
text = text.substring(0, 10) + 'T' + text.substring(11);
}

if (options.parseTemporalAsJavaTime) {
if (TomlReadFeature.PARSE_JAVA_TIME.enabledIn(options)) {
Temporal value;
if (token == TomlToken.LOCAL_DATE) {
value = LocalDate.parse(text);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,13 @@ protected Writer _createWriter(IOContext ioCtxt, OutputStream out, JsonEncoding
private ObjectNode parse(ObjectReadContext readCtxt, IOContext ctxt, Reader r0) {
JacksonTomlParseException.ErrorContext errorContext = new JacksonTomlParseException.ErrorContext(ctxt.sourceReference(), null);
int readFeatures = readCtxt.getFormatReadFeatures(DEFAULT_TOML_PARSER_FEATURE_FLAGS);
ParserOptions options = new ParserOptions(
TomlReadFeature.PARSE_JAVA_TIME.enabledIn(readFeatures)
);
try {
if (ctxt.isResourceManaged() || isEnabled(StreamReadFeature.AUTO_CLOSE_SOURCE)) {
try (Reader r = r0) {
return Parser.parse(errorContext, options, r);
return Parser.parse(errorContext, readFeatures, r);
}
} else {
return Parser.parse(errorContext, options, r0);
return Parser.parse(errorContext, readFeatures, r0);
}
} catch (IOException e) {
throw _wrapIOFailure(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

@SuppressWarnings("OctalInteger")
public class ParserTest {
private final ParserOptions testOptions = new ParserOptions(false);
private final ObjectMapper jsonMapper = JsonMapper.builder()
.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)
.enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS)
Expand All @@ -33,10 +32,10 @@ private ObjectNode json(@Language("json") String json) {
}

private ObjectNode toml(@Language("toml") String toml) throws IOException {
return toml(testOptions, toml);
return toml(0, toml);
}

private ObjectNode toml(ParserOptions opts, @Language("toml") String toml) throws IOException {
private ObjectNode toml(int opts, @Language("toml") String toml) throws IOException {
return Parser.parse(new JacksonTomlParseException.ErrorContext(null, null), opts, new StringReader(toml));
}

Expand Down Expand Up @@ -896,7 +895,7 @@ public void intTypes() throws IOException {
.put("int1", 99)
.put("int2", 4242424242L)
.put("int3", new BigInteger("171717171717171717171717")),
toml(new ParserOptions(false), "int1 = +99\n" +
toml("int1 = +99\n" +
"int2 = 4242424242\n" +
"int3 = 171717171717171717171717")
);
Expand All @@ -911,7 +910,7 @@ public void longBase() throws IOException {
.put("hex3", 0xddead_beefL)
.put("oct1", 01234567777777L)
.put("bin1", 0b11010110101010101010101010101010101010L),
toml(new ParserOptions(false), "hex1 = 0xdDEADBEEF\n" +
toml("hex1 = 0xdDEADBEEF\n" +
"hex2 = 0xddeadbeef\n" +
"hex3 = 0xddead_beef\n" +
"oct1 = 0o1234567777777\n" +
Expand All @@ -928,7 +927,7 @@ public void bigintBase() throws IOException {
.put("hex3", new BigInteger("DDEADBEEFDDEADBEEF", 16))
.put("oct1", new BigInteger("12345677777771234567777777", 8))
.put("bin1", new BigInteger("1101011010101010101010101010101010101011010110101010101010101010101010101010", 2)),
toml(new ParserOptions(false), "hex1 = 0xDDEADBEEFDDEADBEEF\n" +
toml("hex1 = 0xDDEADBEEFDDEADBEEF\n" +
"hex2 = 0xddeadbeefddeadbeef\n" +
"hex3 = 0xddead_beefddead_beef\n" +
"oct1 = 0o12345677777771234567777777\n" +
Expand All @@ -939,7 +938,7 @@ public void bigintBase() throws IOException {
@Test
public void javaTimeDeser() throws IOException {
// this is the same test as above, except with explicit java.time deserialization
ParserOptions options = new ParserOptions(true);
int options = TomlReadFeature.PARSE_JAVA_TIME.getMask();

Assert.assertEquals(
JsonNodeFactory.instance.objectNode()
Expand Down

0 comments on commit f366d3b

Please sign in to comment.