Skip to content

Commit fc81645

Browse files
committed
feat: first version of the KDL 2.0 parser
1 parent 26c0783 commit fc81645

File tree

1,216 files changed

+8472
-7321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,216 files changed

+8472
-7321
lines changed

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_style = tab
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.{yml,yaml}]
11+
tab_width = 2

.github/workflows/build.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Gradle CI
2+
3+
on:
4+
push:
5+
branches:
6+
- trunk
7+
pull_request:
8+
branches:
9+
- trunk
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v4
18+
with:
19+
distribution: temurin
20+
java-version: 17
21+
- name: Setup Gradle
22+
uses: gradle/actions/setup-gradle@v3
23+
- name: Build with Gradle
24+
run: ./gradlew build

.github/workflows/build.yml

-24
This file was deleted.

.github/workflows/release.yaml

-38
This file was deleted.

.java-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
temurin-17

CODE_OF_CONDUCT.md

+50-19
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,73 @@
44

55
If you see behavior that makes you feel unsafe or unwelcome or otherwise uncomfortable, follow these steps:
66

7-
1. Let the person know that what they did is not appropriate and ask them to stop and/or edit their message(s) or commits.
7+
1. Let the person know that what they did is not appropriate and ask them to stop and/or edit their message(s) or
8+
commits.
89
2. That person should immediately stop the behavior and correct the issue.
910
3. If this doesn’t happen, or if you're uncomfortable speaking up, [contact the maintainers](#contacting-maintainers).
10-
4. As soon as available, a maintainer will look into the issue, and take [further action (see below)](#further-enforcement), starting with a warning, then temporary block, then long-term repo or organization ban.
11+
4. As soon as available, a maintainer will look into the issue, and
12+
take [further action (see below)](#further-enforcement), starting with a warning, then temporary block, then
13+
long-term repo or organization ban.
1114

12-
**The maintainer team will prioritize the well-being and comfort of those affected over the comfort of the offending party.** See [some examples below](#enforcement-examples).
15+
**The maintainer team will prioritize the well-being and comfort of those affected over the comfort of the offending
16+
party.** See [some examples below](#enforcement-examples).
1317

1418
## Our Pledge
1519

16-
In the interest of fostering an open and welcoming environment, we as contributors and maintainers of this project pledge to making participation in our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, technical preferences, nationality, personal appearance, race, religion, or sexual identity and orientation.
20+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers of this project
21+
pledge to making participation in our community a harassment-free experience for everyone, regardless of age, body size,
22+
disability, ethnicity, gender identity and expression, level of experience, technical preferences, nationality, personal
23+
appearance, race, religion, or sexual identity and orientation.
1724

18-
This commitment means that inappropriate behavior can lead to intervention. This includes our intention to address issues with [missing stairs](https://en.wikipedia.org/wiki/Missing_stair) who may not have explicitly violated any written-down rules but might still be disrupting the community.
25+
This commitment means that inappropriate behavior can lead to intervention. This includes our intention to address
26+
issues with [missing stairs](https://en.wikipedia.org/wiki/Missing_stair) who may not have explicitly violated any
27+
written-down rules but might still be disrupting the community.
1928

2029
## Scope
2130

22-
This Code of Conduct applies both within spaces involving this project and in other spaces involving community members. This includes the repository, its Pull Requests and Issue tracker, its Twitter community, private email communications in the context of the project, and any events where members of the project are participating, as well as adjacent communities and venues affecting the project's members.
31+
This Code of Conduct applies both within spaces involving this project and in other spaces involving community members.
32+
This includes the repository, its Pull Requests and Issue tracker, its Twitter community, private email communications
33+
in the context of the project, and any events where members of the project are participating, as well as adjacent
34+
communities and venues affecting the project's members.
2335

24-
Depending on the violation, the maintainers may decide that violations of this code of conduct that have happened outside of the scope of the community may deem an individual unwelcome, and take appropriate action to maintain the comfort and safety of its members.
36+
Depending on the violation, the maintainers may decide that violations of this code of conduct that have happened
37+
outside of the scope of the community may deem an individual unwelcome, and take appropriate action to maintain the
38+
comfort and safety of its members.
2539

2640
## Contacting Maintainers
2741

2842
- [Hannah Kolbeck <[email protected]>](mailto:[email protected])
43+
- [Romain Delamare <[email protected]>](mailto:[email protected])
2944

3045
## Further Enforcement
3146

32-
If you've already followed the [initial enforcement steps](#enforcement), these are the steps maintainers will take for further enforcement, as needed:
47+
If you've already followed the [initial enforcement steps](#enforcement), these are the steps maintainers will take for
48+
further enforcement, as needed:
3349

3450
1. Repeat the request to stop.
35-
2. If the person doubles down, they will have offending messages removed or edited by a maintainers given an official warning. The PR or Issue may be locked.
51+
2. If the person doubles down, they will have offending messages removed or edited by a maintainers given an official
52+
warning. The PR or Issue may be locked.
3653
3. If the behavior continues or is repeated later, the person will be blocked from participating for 24 hours.
3754
4. If the behavior continues or is repeated after the temporary block, a long-term (6-12mo) ban will be used.
3855

3956
On top of this, maintainers may remove any offending messages, images, contributions, etc, as they deem necessary.
4057

41-
Maintainers reserve full rights to skip any of these steps, at their discretion, if the violation is considered to be a serious and/or immediate threat to the health and well-being of members of the community. These include any threats, serious physical or verbal attacks, and other such behavior that would be completely unacceptable in any social setting that puts our members at risk.
58+
Maintainers reserve full rights to skip any of these steps, at their discretion, if the violation is considered to be a
59+
serious and/or immediate threat to the health and well-being of members of the community. These include any threats,
60+
serious physical or verbal attacks, and other such behavior that would be completely unacceptable in any social setting
61+
that puts our members at risk.
4262

4363
Members expelled from events or venues with any sort of paid attendance will not be refunded.
4464

4565
## Who Watches the Watchers?
4666

47-
Maintainers and other leaders who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. These may include anything from removal from the maintainer team to a permanent ban from the community.
67+
Maintainers and other leaders who do not follow or enforce the Code of Conduct in good faith may face temporary or
68+
permanent repercussions as determined by other members of the project's leadership. These may include anything from
69+
removal from the maintainer team to a permanent ban from the community.
4870

49-
Additionally, as a project hosted on both GitHub, [their Community Guidielines may be applied to maintainers of this project](https://help.github.com/articles/github-community-guidelines/), externally of this project's procedures.
71+
Additionally, as a project hosted on both
72+
GitHub, [their Community Guidielines may be applied to maintainers of this project](https://help.github.com/articles/github-community-guidelines/),
73+
externally of this project's procedures.
5074

5175
## Enforcement Examples
5276

@@ -62,25 +86,31 @@ The vast majority of situations work out like this. This interaction is common,
6286
6387
### The Maintainer Case
6488

65-
Sometimes, though, you need to get maintainers involved. Maintainers will do their best to resolve conflicts, but people who were harmed by something **will take priority**.
89+
Sometimes, though, you need to get maintainers involved. Maintainers will do their best to resolve conflicts, but people
90+
who were harmed by something **will take priority**.
6691

6792
> Patt: "Honestly, sometimes I just really hate using $library and anyone who uses it probably sucks at their job."
6893
6994
> Alex: "Whoa there, could you dial it back a bit? There's a CoC thing about attacking folks' tech use like that."
7095
7196
> Patt: "I'm not attacking anyone, what's your problem?"
7297
73-
> Alex: "@maintainers hey uh. Can someone look at this issue? Patt is getting a bit aggro. I tried to nudge them about it, but nope."
98+
> Alex: "@maintainers hey uh. Can someone look at this issue? Patt is getting a bit aggro. I tried to nudge them about
99+
> it, but nope."
74100
75-
> KeeperOfCommitBits: (on issue) "Hey Patt, maintainer here. Could you tone it down? This sort of attack is really not okay in this space."
101+
> KeeperOfCommitBits: (on issue) "Hey Patt, maintainer here. Could you tone it down? This sort of attack is really not
102+
> okay in this space."
76103
77104
> Patt: "Leave me alone I haven't said anything bad wtf is wrong with you."
78105
79-
> KeeperOfCommitBits: (deletes user's comment), "@patt I mean it. Please refer to the CoC over at (URL to this CoC) if you have questions, but you can consider this an actual warning. I'd appreciate it if you reworded your messages in this thread, since they made folks there uncomfortable. Let's try and be kind, yeah?"
106+
> KeeperOfCommitBits: (deletes user's comment), "@patt I mean it. Please refer to the CoC over at (URL to this CoC) if
107+
> you have questions, but you can consider this an actual warning. I'd appreciate it if you reworded your messages in this
108+
> thread, since they made folks there uncomfortable. Let's try and be kind, yeah?"
80109
81-
> Patt: "@keeperofbits Okay sorry. I'm just frustrated and I'm kinda burnt out and I guess I got carried away. I'll DM Alex a note apologizing and edit my messages. Sorry for the trouble."
110+
> Patt: "@keeperofbits Okay sorry. I'm just frustrated and I'm kinda burnt out and I guess I got carried away. I'll DM
111+
> Alex a note apologizing and edit my messages. Sorry for the trouble."
82112
83-
> KeeperOfCommitBits: "@patt Thanks for that. I hear you on the stress. Burnout sucks :/. Have a good one!"
113+
> KeeperOfCommitBits: "@patt Thanks for that. I hear you on the stress. Burnout sucks :/. Have a good one!"
84114
85115
### The Nope Case
86116

@@ -96,7 +126,8 @@ Sometimes, though, you need to get maintainers involved. Maintainers will do the
96126
97127
## Attribution
98128

99-
This Code of Conduct was generated using [WeAllJS Code of Conduct Generator](https://npm.im/weallbehave), which is based on the [WeAllJS Code of
129+
This Code of Conduct was generated using [WeAllJS Code of Conduct Generator](https://npm.im/weallbehave), which is based
130+
on the [WeAllJS Code of
100131
Conduct](https://wealljs.org/code-of-conduct), which is itself based on
101132
[Contributor Covenant](http://contributor-covenant.org), version 1.4, available
102133
at

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Copyright 2022 Hannah Kolbeck
2+
Copyright 2025 Romain Delamare
23

34
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
45
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
@@ -12,4 +13,3 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1213
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1314
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1415
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15-

README.md

+56-41
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,82 @@
1-
# KDL4j
1+
# KDL4j v2
22

3-
A Java implementation of a parser for the [KDL Document Language](https://github.com/kdl-org/kdl).
3+
A Java implementation of a parser for the [KDL Document Language](https://github.com/kdl-org/kdl). Supports KDL
4+
version `2.0.0`.
45

5-
## Status
6+
This library targets Java 11 as a minimum version.
67

7-
![Gradle CI](https://github.com/hkolbeck/kdl4j/workflows/Gradle%20CI/badge.svg)
8+
## Status
89

9-
This project is beta-quality. It's been extensively tested, but the spec it implements is still in flux.
10+
![Gradle CI](https://github.com/kdl-org/kdl4j/workflows/Gradle%20CI/badge.svg)
1011

1112
## Usage
1213

13-
### Parsing
14+
### Dependency
1415

15-
```java
16-
final KDLParser parser = new KDLParser();
16+
Releases are published on [GitHub Packages](https://docs.github.com/en/packages). You need to authenticate with GitHub
17+
using a token with `read:packages` permission. See the official documentation for more information on how to
18+
authenticate on GitHub Packages for
19+
[Maven](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry)
20+
or for
21+
[Gradle](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry).
1722

18-
final KDLDocument documentFromString = parser.parse("node_name \"arg\"")
19-
// OR
20-
final KDLDocument documentFromReader = parser.parse(new FileReader("some/file.kdl"))
21-
```
23+
Then you can add the KDL4j dependency. Maven:
2224

23-
`KDLDocument` objects, and all descendants of `KDLObject`, are immutable and threadsafe, though that is not true of their
24-
`Builder` objects. If you need to make changes to a `KDLDocument`, use the `filter()` and `mutate()` functions explained below.
25+
```xml
2526

26-
### Searching and Mutating Documents
27+
<dependencies>
28+
<dependency>
29+
<groupId>dev.kdl</groupId>
30+
<artifactId>kdl4j</artifactId>
31+
<version>1.0.0-SNAPSHOT</version>
32+
</dependency>
33+
</dependencies>
34+
```
2735

28-
Several utilities are provided for finding nodes in documents. Each presents the same interface, but the way they search
29-
the document differs. There are three search types:
36+
Gradle:
3037

31-
* RootSearch - Searches entirely at the root, primarily used for mutations to the root as discussed below
32-
* GeneralSearch - Searches for nodes anywhere in the tree matching a single, possibly compound, node predicate
33-
* PathedSearch - Searches for nodes down a specified path. At each level a different node predicate can be specified
38+
```groovy
39+
dependencies {
40+
implementation 'dev.kdl:kdl4j:1.0.0-SNAPSHOT'
41+
}
42+
```
3443

35-
Each provides four methods for searching or mutating documents:
44+
Alternatively, you can use the packages [hosted by JitPack](https://jitpack.io/#kdl-org/kdl4j). In this case, make sure
45+
you use the `com.github.kdl-org` groupId.
3646

37-
* `anyMatch(document)` - Returns true if any node matches the search, false otherwise
38-
* `filter(document, trim)` - Removes all nodes from the tree not on a branch that matches the predicates of the search. if
39-
`trim` is set, removes all their non-matching children
40-
* `list(document, trim)` - Produces a new document with all matching nodes at the root. If `trim` is set, removes all
41-
their non-matching children
42-
* `mutate(document, mutation)` - Applies a provided `Mutation` to every matching node in the tree, depth first.
47+
### Parsing
4348

44-
There are 3 types of `Mutations` provided, and users may provide custom mutations. Provided are `AddMutation`,
45-
`SubtractMutation`, and `SetMutation`. Each performs functions hinted at by the name. See individual javadocs for details.
49+
```java
50+
import parse.dev.kdl.KDLParser;
51+
52+
// Create a KDL 2 parser
53+
var parser = KdlParser.v2();
54+
// Parse from a String
55+
var documentFromString = parser.parse("filename", "node_name \"arg\"");
56+
// Parse from an InputStream
57+
var documentFromReader = parser.parse("filename", new ByteArrayInputStream(/**/));
58+
// Parse from a file
59+
var documentFromReader = parser.parse(Paths.get("path", "to", "file"));
60+
```
4661

4762
### Printing
4863

49-
By default, calling `document.toKDL()` or `document.writeKDL(writer)` will print the structure with:
50-
51-
* 4 space indents
52-
* No semicolons
53-
* Printable ASCII characters which can be escaped, escaped
54-
* Empty children printed
55-
* `null` arguments and properties with `null` values printed
56-
* `\n` (unicode `\u{0a}`) for newlines
64+
The `KDLPrinter` class allows printing a KDL document to a `String`, a `Writer`, an `OutputStream` or to a file. By
65+
default, it:
66+
67+
- prints one character tabulation for each indentation level
68+
- does not print node separators (`;`)
69+
- does not print braces for nodes without children
70+
- prints arguments and properties with null value
71+
- uses `E` as the exponent character in decimal values
5772

58-
Any of these can be changed by creating a new PrintConfig object and passing it into the print method. See the javadocs
59-
on PrintConfig for more information.
73+
Any of these can be changed by creating a `PrintConfiguration` and passing it to the `KDLPrinter` constructor.
6074

6175
## Contributing
6276

6377
Please read the Code of Conduct before opening any issues or pull requests.
6478

65-
Besides code fixes, the easiest way to contribute is by generating test cases. Check out
66-
[the test cases directory](https://github.com/hkolbeck/kdl4j/tree/trunk/src/test/resources/test_cases) to see the existing ones.
79+
Besides code fixes, the easiest way to contribute is by generating test cases. Check out
80+
[the test cases directory](src/test/resources/test_cases) to see the
81+
existing ones.
6782
See the README there for more details.

0 commit comments

Comments
 (0)