-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update version: Introduce lazy parsers, JSON example, and separate pr…
…oject in different submodules
- Loading branch information
1 parent
a9e38e2
commit d1c4c86
Showing
54 changed files
with
234 additions
and
36 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 |
---|---|---|
|
@@ -38,4 +38,4 @@ jobs: | |
title: "Release ${{ github.ref_name }}" | ||
files: | | ||
LICENSE | ||
target/*.jar | ||
core/target/*.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,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.github.bjoernloetters</groupId> | ||
<artifactId>jcombinators</artifactId> | ||
<version>1.5.0-alpha</version> | ||
</parent> | ||
|
||
<artifactId>jcombinators-core</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.5.2</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.13.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,28 @@ | ||
package jcombinators.primitive; | ||
|
||
import jcombinators.Parser; | ||
import jcombinators.input.Input; | ||
import jcombinators.result.Result; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public final class LazyParser<T> implements Parser<T> { | ||
|
||
private final Supplier<Parser<T>> supplier; | ||
|
||
private Parser<T> parser = null; | ||
|
||
public LazyParser(final Supplier<Parser<T>> supplier) { | ||
this.supplier = supplier; | ||
} | ||
|
||
@Override | ||
public Result<T> apply(final Input input) { | ||
if (parser == null) { | ||
parser = supplier.get(); | ||
} | ||
|
||
return parser.apply(input); | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.github.bjoernloetters</groupId> | ||
<artifactId>jcombinators</artifactId> | ||
<version>1.5.0-alpha</version> | ||
</parent> | ||
|
||
<artifactId>jcombinators-documentation</artifactId> | ||
</project> |
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.github.bjoernloetters</groupId> | ||
<artifactId>jcombinators-examples</artifactId> | ||
<version>1.5.0-alpha</version> | ||
</parent> | ||
|
||
<artifactId>jcombinators-example-json</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.bjoernloetters</groupId> | ||
<artifactId>jcombinators-core</artifactId> | ||
<version>1.5.0-alpha</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
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,42 @@ | ||
package json; | ||
|
||
import jcombinators.Parser; | ||
import jcombinators.data.Tuple; | ||
import jcombinators.input.Input; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import static jcombinators.Parser.lazy; | ||
import static jcombinators.Parser.or; | ||
import static jcombinators.common.StringParser.literal; | ||
import static jcombinators.common.StringParser.regex; | ||
|
||
public final class Example { | ||
|
||
private Example() {} | ||
|
||
public static Parser<JsonValue> jsonValue() { | ||
return lazy(() -> or(jsonNull, jsonNumber, jsonBoolean, jsonArray, jsonObject, jsonString)); | ||
} | ||
|
||
private static final Parser<String> string = regex("\"([^\"\\\\]|\\\\.)*\"").map(string -> string.substring(1, string.length() - 1)); | ||
|
||
public static final Parser<JsonNumber> jsonNumber = regex("[+-]?(?:\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?") | ||
.map(Double::parseDouble).map(JsonNumber::new); | ||
|
||
public static final Parser<JsonBoolean> jsonBoolean = literal("true").map(ignore -> new JsonBoolean(true)) | ||
.or(literal("false").map(ignore -> new JsonBoolean(false))); | ||
|
||
public static final Parser<JsonNull> jsonNull = literal("null").map(ignore -> new JsonNull()); | ||
|
||
public static final Parser<JsonString> jsonString = string.map(JsonString::new); | ||
|
||
public static final Parser<JsonArray> jsonArray = jsonValue().separate(literal(",")).between(literal("["), literal("]")) | ||
.map(values -> values.toArray(new JsonValue[0])).map(JsonArray::new); | ||
|
||
private static final Parser<Tuple<String, JsonValue>> jsonObjectMember = string.keepLeft(literal(":")).and(jsonValue()); | ||
|
||
public static final Parser<JsonObject> jsonObject = jsonObjectMember.separate(literal(",")).between(literal("{"), literal("}")) | ||
.map(tuples -> new JsonObject(tuples.stream().collect(Collectors.toMap(Tuple::first, Tuple::second)))); | ||
|
||
} |
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 @@ | ||
package json; | ||
|
||
public record JsonArray(JsonValue[] values) implements JsonValue { | ||
} |
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 @@ | ||
package json; | ||
|
||
public record JsonBoolean(boolean value) implements JsonValue { | ||
} |
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 @@ | ||
package json; | ||
|
||
public record JsonNull() implements JsonValue { | ||
} |
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 @@ | ||
package json; | ||
|
||
public record JsonNumber(double value) implements JsonValue { | ||
} |
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 @@ | ||
package json; | ||
|
||
import java.util.Map; | ||
|
||
public record JsonObject(Map<String, JsonValue> values) implements JsonValue { | ||
} |
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 @@ | ||
package json; | ||
|
||
public record JsonString(String value) implements JsonValue { | ||
} |
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 @@ | ||
package json; | ||
|
||
public sealed interface JsonValue permits JsonObject, JsonString, JsonArray, JsonNull, JsonNumber, JsonBoolean { | ||
|
||
|
||
} |
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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.github.bjoernloetters</groupId> | ||
<artifactId>jcombinators</artifactId> | ||
<version>1.5.0-alpha</version> | ||
</parent> | ||
|
||
<artifactId>jcombinators-examples</artifactId> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>json</module> | ||
</modules> | ||
</project> |
Oops, something went wrong.