Skip to content

Commit

Permalink
Update the jruby support
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnflyer committed Dec 20, 2024
1 parent d55b4dd commit e81a52d
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 171 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ jobs:
bundler-cache: true
- name: Run tests
env:
COVERALLS: true
COVERALLS: ${{ matrix.ruby-version != 'jruby' }}
JRUBY_OPTS: ${{ matrix.ruby-version == 'jruby' && '--debug' || '' }}
run: bundle exec rake
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ end
platforms :rbx do
gem 'racc' # if using gems like ruby_parser or parser
# gem 'rubysl', '~> 2.0'
gem 'psych'
# gem 'psych'
gem 'rubinius-developer_tools'
end

platforms :jruby do
gem 'jar-dependencies', '~> 0.4.1'
gem 'ruby-maven', '~> 3.3.11'
end
1 change: 1 addition & 0 deletions lib/radius/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def render_tag(name, attributes = {}, &block)
else
tag_definition_block = @definitions[qualified_tag_name(name.to_s)]
if tag_definition_block
# puts name: name, attributes: attributes
stack(name, attributes, block) do |tag|
tag_definition_block.call(tag).to_s
end
Expand Down
6 changes: 5 additions & 1 deletion lib/radius/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ def stack_up

def default_scanner
if RUBY_PLATFORM == 'java'
require 'java'
if Gem::Version.new(JRUBY_VERSION) >= Gem::Version.new('9.3')
require 'jruby'
else
require 'java'
end
require 'radius/parser/java_scanner.jar'
::Radius.send(:include_package, 'radius.parser')
Radius::JavaScanner.new(JRuby.runtime)
Expand Down
Binary file modified lib/radius/parser/JavaScanner.class
Binary file not shown.
372 changes: 211 additions & 161 deletions lib/radius/parser/JavaScanner.java

Large diffs are not rendered by default.

43 changes: 36 additions & 7 deletions lib/radius/parser/JavaScanner.rl
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,37 @@

action _prefix { mark_pfx = p; }
action prefix {
prefix = input.substring(mark_pfx, p);
prefix = String.valueOf(input.substring(mark_pfx, p));
}
action _check_prefix {
if ( !prefix.equals(tag_prefix) ) {
// have to manually add ':' / Sep
// pass the text through & reset state
pass_through(input.substring(tagstart, p) + ":");
// Pass through the entire tag markup as text
pass_through(input.substring(tagstart, p + 1));
// Reset all state
prefix = "";
name = "";
attributes = RubyHash.newHash(runtime);
flavor = RubySymbol.newSymbol(runtime, "tasteless".intern());
tagstart = p + 1;
fgoto main;
}
}

action _starttag { mark_stg = p; }
action starttag { name = input.substring(mark_stg, p); }
action starttag {
name = String.valueOf(input.substring(mark_stg, p));
if (name == null || name.trim().isEmpty()) {
// Pass through the entire tag markup as text
pass_through(input.substring(tagstart, p + 1));
// Reset all state
prefix = "";
name = "";
attributes = RubyHash.newHash(runtime);
flavor = RubySymbol.newSymbol(runtime, "tasteless".intern());
tagstart = p + 1;
fgoto main;
}
}
action _attr { mark_attr = p; }
action attr {
attributes.op_aset(
Expand All @@ -40,7 +57,7 @@
# words
PrefixChar = [\-A-Za-z0-9._?] ;
NameChar = [\-A-Za-z0-9._:?] ;
TagName = NameChar+ >_starttag %starttag;
TagName = ([\-A-Za-z0-9._?]+ (':' [\-A-Za-z0-9._?]+)*) >_starttag %starttag;
Prefix = PrefixChar+ >_prefix %prefix;
Open = "<";
Sep = ":" >_check_prefix;
Expand Down Expand Up @@ -111,11 +128,23 @@ public class JavaScanner {
}

void tag(String prefix, String name, RubyHash attr, RubySymbol flavor) {
// Validate both prefix and name
if ((prefix == null || prefix.trim().isEmpty()) &&
(name == null || name.trim().isEmpty())) {
pass_through("<");
return;
}

if (name == null || name.trim().isEmpty()) {
pass_through("<" + prefix + ":");
return;
}

RubyHash tag = RubyHash.newHash(runtime);
tag.op_aset(
runtime.getCurrentContext(),
RubySymbol.newSymbol(runtime, "prefix"),
RubyString.newString(runtime, prefix)
RubyString.newString(runtime, prefix != null ? prefix : "")
);
tag.op_aset(
runtime.getCurrentContext(),
Expand Down

0 comments on commit e81a52d

Please sign in to comment.