Skip to content

Commit 5d5589f

Browse files
committed
Merge branch 'main' into herb-rust
2 parents 843e65c + ff7ad02 commit 5d5589f

Some content is hidden

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

45 files changed

+2579
-3
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export PATH="$PWD/javascript/packages/formatter/bin:$PATH"
44
export PATH="$PWD/javascript/packages/language-server/bin:$PATH"
55
export PATH="$PWD/javascript/packages/highlighter/bin:$PATH"
66
export PATH="$PWD/javascript/packages/stimulus-lint/bin:$PATH"
7+
export PATH="$PWD/java/bin:$PATH"
78
export PATH="$PWD/rust/bin:$PATH"

.gitattributes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Templates
22
templates/**/*.c.erb linguist-language=C
3+
templates/**/*.cpp.erb linguist-language=C++
34
templates/**/*.h.erb linguist-language=C
5+
templates/**/*.java.erb linguist-language=Java
6+
templates/**/*.js.erb linguist-language=JavaScript
47
templates/**/*.rb.erb linguist-language=Ruby
5-
templates/**/*.cpp.erb linguist-language=C++
68
templates/**/*.rs.erb linguist-language=Rust
79
templates/**/*.ts.erb linguist-language=TypeScript
810

.github/labeler.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ typescript:
3737
- '**/javascript/**/*.ts'
3838
- '**/javascript/**/*.ts.erb'
3939

40+
java:
41+
- changed-files:
42+
- any-glob-to-any-file:
43+
- '**/*.java'
44+
- '**/*.java.erb'
45+
4046
ruby:
4147
- changed-files:
4248
- any-glob-to-any-file:

.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Build
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
48

59
permissions:
610
contents: read

.github/workflows/java.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Java
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build:
14+
name: Build
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 10
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Java
23+
uses: actions/setup-java@v4
24+
with:
25+
distribution: 'temurin'
26+
java-version: '17'
27+
28+
- name: Set up Ruby
29+
uses: ruby/setup-ruby@v1
30+
with:
31+
bundler-cache: true
32+
33+
- name: Render Templates
34+
run: bundle exec rake templates
35+
36+
- name: Compile Herb
37+
run: bundle exec rake make
38+
39+
- name: Build JNI library
40+
run: make jni
41+
working-directory: java
42+
43+
- name: Compile Java classes
44+
run: make java
45+
working-directory: java
46+
47+
- name: Run tests
48+
run: ./run_tests.sh
49+
working-directory: java
50+
51+
- name: Test CLI version command
52+
run: ./bin/herb-java version
53+
working-directory: java

.gitignore

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,17 @@ ext/herb/error_helpers.c
8989
ext/herb/error_helpers.h
9090
ext/herb/nodes.c
9191
ext/herb/nodes.h
92+
java/error_helpers.c
93+
java/error_helpers.h
94+
java/nodes.c
95+
java/nodes.h
96+
java/org/herb/ast/Errors.java
97+
java/org/herb/ast/Nodes.java
98+
java/org/herb/ast/NodeVisitor.java
99+
java/org/herb/ast/Visitor.java
92100
javascript/packages/core/src/errors.ts
93-
javascript/packages/core/src/nodes.ts
94101
javascript/packages/core/src/node-type-guards.ts
102+
javascript/packages/core/src/nodes.ts
95103
javascript/packages/core/src/visitor.ts
96104
javascript/packages/node/extension/error_helpers.cpp
97105
javascript/packages/node/extension/error_helpers.h
@@ -105,6 +113,7 @@ rust/src/errors.rs
105113
rust/src/nodes.rs
106114
sig/serialized_ast_errors.rbs
107115
sig/serialized_ast_nodes.rbs
116+
sig/serialized_ast_nodes.rbs
108117
src/ast_nodes.c
109118
src/ast_pretty_print.c
110119
src/errors.c
@@ -117,6 +126,10 @@ wasm/error_helpers.h
117126
wasm/nodes.cpp
118127
wasm/nodes.h
119128

129+
# Java Build Artifacts
130+
java/target/
131+
java/.java_compiled
132+
120133
# Rust Build Artifacts
121134
rust/target/
122135
rust/Cargo.lock

docs/.vitepress/config/theme.mts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ const defaultSidebar = [
9090
{ text: "Reference", link: "/bindings/javascript/reference" },
9191
],
9292
},
93+
{
94+
text: "Java",
95+
collapsed: false,
96+
items: [
97+
{ text: "Installation", link: "/bindings/java/" },
98+
{ text: "Reference", link: "/bindings/java/reference" },
99+
],
100+
},
93101
{
94102
text: "Rust",
95103
collapsed: false,

docs/docs/bindings/java/index.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# Herb Java Bindings
6+
7+
Herb provides official Java bindings through JNI (Java Native Interface) to the C library, allowing you to parse HTML+ERB in Java projects with native performance.
8+
9+
> [!TIP] More Language Bindings
10+
> Herb also has bindings for:
11+
> - [Ruby](/bindings/ruby/)
12+
> - [JavaScript/Node.js](/bindings/javascript/)
13+
> - [Rust](/bindings/rust/)
14+
15+
## Installation
16+
17+
### Prerequisites
18+
19+
Ensure you have Java installed:
20+
21+
:::code-group
22+
```shell
23+
java -version
24+
```
25+
:::
26+
27+
### Build from Source
28+
29+
Clone the repository and build the Java bindings:
30+
31+
:::code-group
32+
```shell
33+
git clone https://github.com/your-org/herb.git
34+
cd herb/java
35+
make templates
36+
make jni
37+
make java
38+
```
39+
:::
40+
41+
This creates the native library (`libherb_jni.dylib` on macOS, `.so` on Linux).
42+
43+
### Setting Up Your Project
44+
45+
Add the compiled classes to your classpath and ensure the native library is in your `java.library.path`.
46+
47+
## Getting Started
48+
49+
### Basic Example
50+
51+
Here's a simple example of parsing HTML+ERB:
52+
53+
:::code-group
54+
```java
55+
import org.herb.Herb;
56+
import org.herb.ParseResult;
57+
58+
public class Example {
59+
public static void main(String[] args) {
60+
String source = "<h1><%= user.name %></h1>";
61+
62+
ParseResult result = Herb.parse(source);
63+
64+
if (result.getValue() != null) {
65+
System.out.println(result.getValue().treeInspect());
66+
}
67+
}
68+
}
69+
```
70+
:::
71+
72+
### Lexing Example
73+
74+
You can also tokenize HTML+ERB source:
75+
76+
:::code-group
77+
```java
78+
import org.herb.Herb;
79+
import org.herb.LexResult;
80+
import org.herb.Token;
81+
82+
public class LexExample {
83+
public static void main(String[] args) {
84+
String source = "<h1><%= user.name %></h1>";
85+
86+
LexResult result = Herb.lex(source);
87+
88+
for (Token token : result.getTokens()) {
89+
System.out.println(token.inspect());
90+
}
91+
}
92+
}
93+
```
94+
:::

0 commit comments

Comments
 (0)