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
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ jobs:
- name: Render Templates
run: bundle exec rake templates

# TODO: Drop `BUNDLE_GEMFILE` and the separate cop test run once https://github.com/rubocop/rubocop-ast/pull/420 is released.
- name: RuboCop
run: bundle exec rubocop
env:
BUNDLE_GEMFILE: gemfiles/rubocop.gemfile
run: |-
bundle install
bundle exec rubocop
bundle exec ruby test/rubocop/includes_assertion_test.rb

- name: Yerba
run: bundle exec yerba check
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you encounter any issues when following along with this file please don't hes
- [**Clang 21**](https://clang.llvm.org): The compiler used to build this project.
- [**Clang Format 21**](https://clang.llvm.org/docs/ClangFormat.html): For formatting the project.
- [**Clang Tidy 21**](https://clang.llvm.org/extra/clang-tidy/): For linting the project.
- [**Prism Ruby Parser v1.9.0**](https://github.com/ruby/prism/releases/tag/v1.9.0): We use Prism for Parsing the Ruby Source Code in the HTML+ERB files.
- [**Prism Ruby Parser v2.0.0**](https://github.com/ruby/prism/releases/tag/v2.0.0): We use Prism for Parsing the Ruby Source Code in the HTML+ERB files.
- [**Ruby**](https://www.ruby-lang.org/en/): We need Ruby as a dependency for `bundler`.
- [**Bundler**](https://bundler.io): We are using `bundler` to build [`prism`](https://github.com/ruby/prism) from source so we can build `herb` against it.
- [**Emscripten 5**](https://emscripten.org): For the WebAssembly build of `libherb` so it can be used in the browser using the [`@herb-tools/browser`](https://github.com/marcoroth/herb/blob/main/javascript/packages/browser) package.
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "https://rubygems.org"

gemspec

gem "prism", github: "ruby/prism", tag: "v1.9.0"
gem "prism", github: "ruby/prism", tag: "v2.0.0"

gem "actionview", "~> 8.1", require: "action_view"
gem "benchmark"
Expand All @@ -20,6 +20,7 @@ gem "maxitest", "~> 6.0"
gem "minitest-difftastic", "~> 0.2"
gem "nokogiri", "~> 1.19"
gem "oxc", "~> 0.149.0"
gem "parallel", "~> 1.27"
gem "rake", "~> 13.4"
gem "rake-compiler", "~> 1.3"
gem "rake-compiler-dock", "~> 1.12"
Expand All @@ -28,8 +29,7 @@ gem "rbs-inline", "~> 0.14"
gem "reactionview", github: "marcoroth/reactionview", branch: "herb-v0.11"
gem "reline", "~> 0.7"
gem "rolldown", "~> 1.2"
gem "rubocop", "~> 1.72"
gem "rubocop-performance", "~> 1.26.0"
# TODO: Move `rubocop` and `rubocop-performance` back here from `gemfiles/rubocop.gemfile` once https://github.com/rubocop/rubocop-ast/pull/420 is released.
gem "sorbet"
gem "steep", "~> 2.1"
gem "turbo-rails", "~> 2.0", require: false
Expand Down
30 changes: 4 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ GIT

GIT
remote: https://github.com/ruby/prism.git
revision: c0e37816e97e23e92524a4070e1b99a4025bc63f
tag: v1.9.0
revision: e2727368fd9fc2486e2acc8aa513f0cd9e7e02cf
tag: v2.0.0
specs:
prism (1.9.0)
prism (2.0.0)

PATH
remote: .
Expand Down Expand Up @@ -154,7 +154,6 @@ GEM
lightningcss (1.33.0-x86_64-darwin)
lightningcss (1.33.0-x86_64-linux-gnu)
lightningcss (1.33.0-x86_64-linux-musl)
lint_roller (1.1.0)
lipgloss (0.2.2-aarch64-linux-gnu)
lipgloss (0.2.2-aarch64-linux-musl)
lipgloss (0.2.2-arm64-darwin)
Expand Down Expand Up @@ -255,7 +254,6 @@ GEM
erb
psych (>= 4.0.0)
tsort
regexp_parser (2.11.3)
reline (0.7.0)
io-console (~> 0.5)
rolldown (1.2.8-aarch64-linux-gnu)
Expand All @@ -264,25 +262,6 @@ GEM
rolldown (1.2.8-x86_64-darwin)
rolldown (1.2.8-x86_64-linux-gnu)
rolldown (1.2.8-x86_64-linux-musl)
rubocop (1.84.0)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.49.0)
parser (>= 3.3.7.2)
prism (~> 1.7)
rubocop-performance (1.26.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (1.13.0)
securerandom (0.4.1)
sorbet (0.6.13466)
sorbet-static (= 0.6.13466)
Expand Down Expand Up @@ -358,6 +337,7 @@ DEPENDENCIES
minitest-difftastic (~> 0.2)
nokogiri (~> 1.19)
oxc (~> 0.149.0)
parallel (~> 1.27)
prism!
rake (~> 13.4)
rake-compiler (~> 1.3)
Expand All @@ -367,8 +347,6 @@ DEPENDENCIES
reactionview!
reline (~> 0.7)
rolldown (~> 1.2)
rubocop (~> 1.72)
rubocop-performance (~> 1.26.0)
sorbet
steep (~> 2.1)
turbo-rails (~> 2.0)
Expand Down
6 changes: 4 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
# TODO: Drop the `test/rubocop` exclusion once https://github.com/rubocop/rubocop-ast/pull/420 is released and RuboCop is back in the main `Gemfile`.
t.test_files = FileList["test/**/*_test.rb"].exclude("test/rubocop/**/*")
end

Rake::TestTask.new("test:engine") do |t|
Expand All @@ -25,7 +26,8 @@ end
Rake::TestTask.new("test:all") do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
# TODO: Drop the `test/rubocop` exclusion once https://github.com/rubocop/rubocop-ast/pull/420 is released and RuboCop is back in the main `Gemfile`.
t.test_files = FileList["test/**/*_test.rb"].exclude("test/rubocop/**/*")
end

task "make" do
Expand Down
4 changes: 3 additions & 1 deletion bin/integration
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ bin/leaks_parse examples/test.html.erb

bin/lint
bin/tidy
bundle exec rubocop
# TODO: Back to `bundle exec rubocop` once https://github.com/rubocop/rubocop-ast/pull/420 is released.
BUNDLE_GEMFILE=gemfiles/rubocop.gemfile bundle exec rubocop
BUNDLE_GEMFILE=gemfiles/rubocop.gemfile bundle exec ruby test/rubocop/includes_assertion_test.rb

echo ""
echo "Integration successful!"
38 changes: 7 additions & 31 deletions ext/herb/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

Add it to your Gemfile before the herb git reference:

gem "prism", github: "ruby/prism", tag: "v1.9.0"
gem "prism", github: "ruby/prism", tag: "v2.0.0"
gem "herb", github: "...", branch: "..."

Then run `bundle install` again.
Expand Down Expand Up @@ -55,13 +55,10 @@
$VPATH << "$(srcdir)/../../src/prism"
$VPATH << "$(srcdir)/../../src/lib"
$VPATH << "$(srcdir)/../../src/util"
$VPATH << prism_src_path
$VPATH << "#{prism_src_path}/util"

$INCFLAGS << " -I#{prism_include_path}"
$INCFLAGS << " -I#{include_path}"
$INCFLAGS << " -I#{prism_src_path}"
$INCFLAGS << " -I#{prism_src_path}/util"

$CFLAGS << " -fvisibility=hidden"
$CFLAGS << " -DHERB_EXCLUDE_PRETTYPRINT"
Expand All @@ -71,32 +68,11 @@

herb_src_files = Dir.glob("#{$srcdir}/../../src/**/*.c").map { |file| file.delete_prefix("../../../../ext/herb/") }.sort

prism_main_files = [
"diagnostic.c",
"encoding.c",
"node.c",
"options.c",
"pack.c",
"prettyprint.c",
"prism.c",
"regexp.c",
"serialize.c",
"static_literals.c",
"token_type.c"
]

prism_util_files = [
"pm_buffer.c",
"pm_char.c",
"pm_constant_pool.c",
"pm_integer.c",
"pm_list.c",
"pm_memchr.c",
"pm_newline_list.c",
"pm_string.c",
"pm_strncasecmp.c",
"pm_strpbrk.c"
]
prism_src_files = Dir.glob("#{prism_src_path}/*.c").map do |file|
wrapper = "prism_#{File.basename(file)}"
File.write(wrapper, "#include \"#{file}\"\n")
wrapper
end

core_src_files = [
"extension.c",
Expand All @@ -106,7 +82,7 @@
"parser_options_helpers.c"
]

$srcs = core_src_files + herb_src_files + prism_main_files + prism_util_files
$srcs = core_src_files + herb_src_files + prism_src_files

puts "Sources to be compiled: #{$srcs.inspect}"

Expand Down
9 changes: 9 additions & 0 deletions gemfiles/rubocop.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

source "https://rubygems.org"

# TODO: Move these gems back into the main `Gemfile` and delete this file once https://github.com/rubocop/rubocop-ast/pull/420 is released.

gem "maxitest", "~> 6.0"
gem "rubocop", "~> 1.72"
gem "rubocop-performance", "~> 1.26.0"
78 changes: 78 additions & 0 deletions gemfiles/rubocop.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.3)
json (2.21.2)
language_server-protocol (3.17.0.6)
lint_roller (1.1.0)
maxitest (6.2.0)
minitest (>= 5.20.0, < 5.28.0)
minitest (5.27.0)
parallel (1.28.0)
parser (3.3.13.0)
ast (~> 2.4.1)
racc
prism (1.9.0)
racc (1.8.1)
rainbow (3.1.1)
regexp_parser (2.13.1)
rubocop (1.84.0)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.49.0)
parser (>= 3.3.7.2)
prism (~> 1.7)
rubocop-performance (1.26.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (1.13.0)
unicode-display_width (3.3.0)
unicode-emoji (~> 4.3)
unicode-emoji (4.3.0)

PLATFORMS
aarch64-linux-gnu
aarch64-linux-musl
arm64-darwin
ruby
x86_64-darwin
x86_64-linux-gnu
x86_64-linux-musl

DEPENDENCIES
maxitest (~> 6.0)
rubocop (~> 1.72)
rubocop-performance (~> 1.26.0)

CHECKSUMS
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
bundler (4.0.19) sha256=b48056e4c77fb3853cc47775b5447ede44aaa4f53c32f168014ab4fe86587d47
json (2.21.2) sha256=1f1d3b7cf2b3ba1a69beca0bb6db13d5438b80bff3cd54cdaaa620b9b07c1c6a
language_server-protocol (3.17.0.6) sha256=5ef2c0c138f8267e1bc631d3328347d354f96724b0af22f2c79516120443b7f0
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
maxitest (6.2.0) sha256=bb66472dd3f6565e4db5246826a05ce9096958d9e26ba9a8fdcae20288be1f4f
minitest (5.27.0) sha256=2d3b17f8a36fe7801c1adcffdbc38233b938eb0b4966e97a6739055a45fa77d5
parallel (1.28.0) sha256=33e6de1484baf2524792d178b0913fc8eb94c628d6cfe45599ad4458c638c970
parser (3.3.13.0) sha256=e02f9b63c2fe05b0c68f692ba4df89b3cb113b663964f75d988fbebfd6c3deca
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
regexp_parser (2.13.1) sha256=5aedb6b7c35688f51e86eef17a15374dfd287c83f4ca644b2c5f3ec50a33b44b
rubocop (1.84.0) sha256=88dec310153bb685a879f5a7cdb601f6287b8f0ee675d9dc63a17c7204c4190a
rubocop-ast (1.49.0) sha256=49c3676d3123a0923d333e20c6c2dbaaae2d2287b475273fddee0c61da9f71fd
rubocop-performance (1.26.1) sha256=cd19b936ff196df85829d264b522fd4f98b6c89ad271fa52744a8c11b8f71834
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
unicode-display_width (3.3.0) sha256=4b7aa66a4b11db50f6f7e98411215cd0dd10eaecb665d36eec5bcacb3fa0b613
unicode-emoji (4.3.0) sha256=11c02fa73290378c066bb0562cd4c87d8e1b706fbbe0059ca12746a4244de8ce

BUNDLED WITH
4.0.19
13 changes: 7 additions & 6 deletions java/herb_jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,18 @@ Java_org_herb_Herb_parseRuby(JNIEnv* env, jclass clazz, jstring source) {
return NULL;
}

pm_buffer_t buffer = { 0 };
pm_serialize(&parse_result->parser, parse_result->root, &buffer);
pm_buffer_t* buffer = pm_buffer_new();
pm_serialize(parse_result->parser, parse_result->root, buffer);

jbyteArray result = NULL;
size_t length = pm_buffer_length(buffer);

if (buffer.length > 0) {
result = (*env)->NewByteArray(env, (jsize) buffer.length);
(*env)->SetByteArrayRegion(env, result, 0, (jsize) buffer.length, (const jbyte*) buffer.value);
if (length > 0) {
result = (*env)->NewByteArray(env, (jsize) length);
(*env)->SetByteArrayRegion(env, result, 0, (jsize) length, (const jbyte*) pm_buffer_value(buffer));
}

pm_buffer_free(&buffer);
pm_buffer_free(buffer);
herb_free_ruby_parse_result(parse_result);
(*env)->ReleaseStringUTFChars(env, source, src);

Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@herb-tools/core": "0.11.1",
"@ruby/prism": "^1.9.0"
"@ruby/prism": "^2.0.0"
},
"files": [
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/browser/test/browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("@herb-tools/browser", () => {
test("version() returns a string", async () => {
const version = Herb.version
expect(typeof version).toBe("string")
expect(version).toBe("@herb-tools/browser@0.11.1, @herb-tools/core@0.11.1, libprism@1.9.0, libherb@0.11.1 (WebAssembly)")
expect(version).toBe("@herb-tools/browser@0.11.1, @herb-tools/core@0.11.1, libprism@2.0.0, libherb@0.11.1 (WebAssembly)")
})

test("parse() can process a simple template", async () => {
Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
},
"dependencies": {
"@ruby/prism": "^1.9.0"
"@ruby/prism": "^2.0.0"
},
"devDependencies": {},
"files": [
Expand Down
4 changes: 2 additions & 2 deletions javascript/packages/core/test/prism-visitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PrismVisitor } from "../src/prism/index.js"

import type { PrismNodes, PrismParseResult } from "../src/prism/index.js"

let parse: (source: string) => PrismParseResult
let parse: (source: Uint8Array) => PrismParseResult

class CollectingVisitor extends PrismVisitor {
public names: string[] = []
Expand All @@ -28,7 +28,7 @@ class CollectingVisitor extends PrismVisitor {
const collect = (source: string): string[] => {
const visitor = new CollectingVisitor()

visitor.visit(parse(source).value)
visitor.visit(parse(new TextEncoder().encode(source)).value)

return visitor.names
}
Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/formatter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@herb-tools/node-wasm": "0.11.1",
"@herb-tools/printer": "0.11.1",
"@herb-tools/rewriter": "0.11.1",
"@ruby/prism": "^1.9.0",
"@ruby/prism": "^2.0.0",
"tinyglobby": "^0.2.15"
},
"files": [
Expand Down
Loading
Loading