Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<connection>scm:git:git@github.com:vieiro/toml-java.git</connection>
<developerConnection>scm:git:git@github.com:vieiro/toml-java.git</developerConnection>
<url>https://github.com/vieiro/toml-java</url>
<tag>HEAD</tag>
</scm>
<tag>HEAD</tag>
</scm>

<issueManagement>
<system>Github</system>
Expand Down Expand Up @@ -59,7 +59,7 @@
<plugins>
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.8</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -80,9 +80,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<version.antlr>4.13.1</version.antlr>
<maven.compiler.release>11</maven.compiler.release>
</properties>

<dependencies>
Expand All @@ -96,37 +95,37 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.0</version>
<version>6.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.10.0</version>
<version>6.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<version>3.4.2</version>
<version>3.4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
<version>2.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.flipkart.zjsonpatch</groupId>
<artifactId>zjsonpatch</artifactId>
<version>0.4.14</version>
<version>0.4.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.14.0</version>
<version>2.20.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -147,7 +146,7 @@
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
<version>3.1.4</version>
<executions>
<execution>
<id>default-deploy</id>
Expand All @@ -160,7 +159,7 @@
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.0</version>
<configuration>
<goals>deploy</goals>
<arguments>-Dgpg.passphrase=${gpg.passphrase}</arguments>
Expand All @@ -181,7 +180,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -191,14 +190,14 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.14.1</version>
<configuration>
<compilerArgument>-Xlint:unchecked</compilerArgument>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<version>3.5.4</version>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
Expand All @@ -218,7 +217,7 @@
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
<configuration>
</configuration>
<executions>
Expand All @@ -232,7 +231,7 @@
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version>
<version>3.12.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down
2 changes: 2 additions & 0 deletions src/main/antlr4/net/vieiro/toml/antlr4/TOMLAntlrLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ UNEXPECTED_VALUE_DATA: . -> type(INVALID_VALUE), popMode;
mode INLINE_TABLE_MODE;

INLINE_TABLE_WS : WS -> skip ;
INLINE_TABLE_NL : NL -> type(NL) ;
INLINE_TABLE_COMMENT : COMMENT -> type(COMMENT) ;
INLINE_TABLE_KEY_DOT : DOT -> type(DOT) ;
INLINE_TABLE_COMMA : COMMA -> type(COMMA) ;
R_BRACE : '}' -> popMode ;
Expand Down
10 changes: 4 additions & 6 deletions src/main/antlr4/net/vieiro/toml/antlr4/TOMLAntlrParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ bool_ : BOOLEAN ;

date_time : OFFSET_DATE_TIME | LOCAL_DATE_TIME | LOCAL_DATE | LOCAL_TIME ;

inline_table :
L_BRACE key EQUALS inline_value (COMMA key EQUALS inline_value)*? R_BRACE
| L_BRACE R_BRACE;
inline_table :
L_BRACE comment_or_nl key EQUALS inline_value comment_or_nl (COMMA comment_or_nl key EQUALS inline_value comment_or_nl)* (COMMA comment_or_nl)? R_BRACE
| L_BRACE comment_or_nl R_BRACE;

inner_array: L_BRACKET inline_value? (COMMA inline_value)*? COMMA*? R_BRACKET;

inline_value: string | integer | floating_point | bool_ | date_time | inner_array | inline_table;
inline_value: string | integer | floating_point | bool_ | date_time | array_ | inline_table;

array_ : L_BRACKET array_values? comment_or_nl R_BRACKET ;

Expand Down
13 changes: 2 additions & 11 deletions src/main/java/net/vieiro/toml/TOMLVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,6 @@ public Object visitInline_table(TOMLAntlrParser.Inline_tableContext ctx) {
return Collections.unmodifiableMap(inlineTable);
}

@Override
public Object visitInner_array(TOMLAntlrParser.Inner_arrayContext ctx) {
if (ctx.inline_value() != null) {
List<Object> innerArray = ctx.inline_value().stream().map((v) -> v.accept(this)).collect(Collectors.toList());
return Collections.unmodifiableList(innerArray);
}
return Collections.emptyList();
}

@Override
public Object visitInline_value(TOMLAntlrParser.Inline_valueContext ctx) {
if (ctx.string() != null) {
Expand All @@ -379,8 +370,8 @@ public Object visitInline_value(TOMLAntlrParser.Inline_valueContext ctx) {
return ctx.bool_().accept(this);
} else if (ctx.date_time() != null) {
return ctx.date_time().accept(this);
} else if (ctx.inner_array() != null) {
return ctx.inner_array().accept(this);
} else if (ctx.array_() != null) {
return ctx.array_().accept(this);
} else if (ctx.inline_table() != null) {
return ctx.inline_table().accept(this);
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/net/vieiro/toml/TOMLArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public void testShouldParseArraysProperly() throws Exception {
assertEquals(3, ((List) nested_arrays_of_ints.get(1)).size());
}

{
assertTrue(toml.getArray("multiline-array").isPresent());
List<Object> multilineArray = toml.getArray("multiline-array").get();
assertEquals(4, multilineArray.size());
assertEquals(1L, multilineArray.get(0));
assertEquals(2L, multilineArray.get(1));
assertEquals(3L, multilineArray.get(2));
assertEquals(5L, multilineArray.get(3));
}

}

}
8 changes: 8 additions & 0 deletions src/test/java/net/vieiro/toml/TOMLInlineTablesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public void testShouldParseInlineTablesProperly() throws Exception {
String pug = toml.getString("animal/type/name").orElse(null);
assertEquals("pug", pug);

Long mlDetailsYear = toml.getLong("multiline-table/details/year").orElse(0L);
assertEquals(1968L, mlDetailsYear);

String mlDetailsModel = toml.getString("multiline-table/details/model").orElse(null);
assertEquals("Mustang", mlDetailsModel);

Long inlineTableTrailingCommaValue = toml.getLong("inline_table_trailing_comma/value").orElse(0L);
assertEquals(1L, inlineTableTrailingCommaValue);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,9 @@ public class TOMLInvalidDocumentTest {
"invalid/inline-table/double-comma.toml",
"invalid/inline-table/duplicate-key.toml",
"invalid/inline-table/empty.toml",
"invalid/inline-table/linebreak-1.toml",
"invalid/inline-table/linebreak-2.toml",
"invalid/inline-table/linebreak-3.toml",
"invalid/inline-table/linebreak-4.toml",
"invalid/inline-table/nested_key_conflict.toml",
"invalid/inline-table/no-comma.toml",
"invalid/inline-table/overwrite.toml",
"invalid/inline-table/trailing-comma.toml",
"invalid/inline-table/unclosed-table.toml",
"invalid/integer/capital-bin.toml",
"invalid/integer/capital-hex.toml",
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/net/vieiro/toml/array-test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ colors = [ "red", "yellow", "green" ]
nested_arrays_of_ints = [ [ 1, 2 ], [3, 4, 5] ]
nested_mixed_array = [ [ 1, 2 ], ["a", "b", "c"] ]
more_integers = [4, 5, 6,]

multiline-array = [ 1,
# Second set of value separated by comment
2, 3, 5 ]
17 changes: 15 additions & 2 deletions src/test/resources/net/vieiro/toml/inline-table-test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ animal = { type.name = "pug" }
nested = { brand = "Ford", details = { year = 1968, model ="Mustang"}}
ahash = { version = "0.8", default-features = false, features = ["compile-time-rng"] }

multiline-array = [ 1,
2, 3, 5 ]
multiline-table = {
# Comment 1
brand = "Ford",
details = {
year = 1968,
# Comment 2
model ="Mustang",
tags = [
"t1",
"t2",
"t3"
]
}
}

inline_table_trailing_comma = { name = "test", value = 1, }

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.