From 64c9e1865122757016ea330b4c8ee22e63dbdc12 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 6 May 2014 10:20:30 +0200 Subject: [PATCH] Setup for Java and Ragel. --- ext/liboga/org/liboga/xml/Lexer.rl | 40 ++++++++++++++++++++++++++++++ task/lexer.rake | 9 ++++++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 ext/liboga/org/liboga/xml/Lexer.rl diff --git a/ext/liboga/org/liboga/xml/Lexer.rl b/ext/liboga/org/liboga/xml/Lexer.rl new file mode 100644 index 0000000..a42c3bf --- /dev/null +++ b/ext/liboga/org/liboga/xml/Lexer.rl @@ -0,0 +1,40 @@ +package org.liboga.xml; + +%%machine lexer; + +import java.io.IOException; + +import org.jruby.Ruby; +import org.jruby.RubyModule; +import org.jruby.RubyClass; +import org.jruby.RubyObject; +import org.jruby.anno.JRubyClass; +import org.jruby.anno.JRubyMethod; +import org.jruby.runtime.ThreadContext; +import org.jruby.runtime.builtin.IRubyObject; + +@JRubyClass(name="Oga::XML::Lexer", parent="Object") +public class Lexer extends RubyObject +{ + %% write data; + + public Lexer(Ruby runtime, RubyClass klass) + { + super(runtime, klass); + } + + @JRubyMethod + public IRubyObject advance_native(ThreadContext context) + { + %% write init; + %% write exec; + + return context.getRuntime().getNil(); + } +} + +%%{ + main := |* + any; + *|; +}%% diff --git a/task/lexer.rake b/task/lexer.rake index 7b73c13..d75b72c 100644 --- a/task/lexer.rake +++ b/task/lexer.rake @@ -20,5 +20,12 @@ rule '.c' => '.rl' do |task| sh "ragel -C -G2 #{task.source} -o #{task.name}" end +rule '.java' => '.rl' do |task| + sh "ragel -J #{task.source} -o #{task.name}" +end + desc 'Generates the lexers' -task :lexer => ['ext/liboga/lexer.c'] +multitask :lexer => [ + 'ext/liboga/lexer.c', + 'ext/liboga/org/liboga/xml/Lexer.java' +]