JRuby lexer boilerplate with actual input.
This doesn't actually lex anything just yet but at least the input from Ruby is in place.
This commit is contained in:
parent
fea5ec7946
commit
f39fe5d857
|
@ -10,16 +10,7 @@ public class LibogaService implements BasicLibraryService
|
||||||
{
|
{
|
||||||
public boolean basicLoad(final Ruby runtime) throws IOException
|
public boolean basicLoad(final Ruby runtime) throws IOException
|
||||||
{
|
{
|
||||||
RubyModule xml = (RubyModule) runtime.getModule("Oga")
|
org.liboga.xml.Lexer.load(runtime);
|
||||||
.getConstant("XML");
|
|
||||||
|
|
||||||
RubyClass lexer = xml.defineClassUnder(
|
|
||||||
"Lexer",
|
|
||||||
runtime.getObject(),
|
|
||||||
runtime.getObject().getAllocator()
|
|
||||||
);
|
|
||||||
|
|
||||||
lexer.defineAnnotatedMethods(org.liboga.xml.Lexer.class);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,17 @@ package org.liboga.xml;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.jcodings.Encoding;
|
||||||
|
|
||||||
import org.jruby.Ruby;
|
import org.jruby.Ruby;
|
||||||
import org.jruby.RubyModule;
|
import org.jruby.RubyModule;
|
||||||
import org.jruby.RubyClass;
|
import org.jruby.RubyClass;
|
||||||
import org.jruby.RubyObject;
|
import org.jruby.RubyObject;
|
||||||
|
import org.jruby.RubyString;
|
||||||
import org.jruby.anno.JRubyClass;
|
import org.jruby.anno.JRubyClass;
|
||||||
import org.jruby.anno.JRubyMethod;
|
import org.jruby.anno.JRubyMethod;
|
||||||
import org.jruby.runtime.ThreadContext;
|
import org.jruby.runtime.ThreadContext;
|
||||||
|
import org.jruby.runtime.ObjectAllocator;
|
||||||
import org.jruby.runtime.builtin.IRubyObject;
|
import org.jruby.runtime.builtin.IRubyObject;
|
||||||
|
|
||||||
@JRubyClass(name="Oga::XML::Lexer", parent="Object")
|
@JRubyClass(name="Oga::XML::Lexer", parent="Object")
|
||||||
|
@ -18,6 +22,28 @@ public class Lexer extends RubyObject
|
||||||
{
|
{
|
||||||
%% write data;
|
%% write data;
|
||||||
|
|
||||||
|
public static void load(Ruby runtime)
|
||||||
|
{
|
||||||
|
RubyModule xml = (RubyModule) runtime.getModule("Oga")
|
||||||
|
.getConstant("XML");
|
||||||
|
|
||||||
|
RubyClass lexer = xml.defineClassUnder(
|
||||||
|
"Lexer",
|
||||||
|
runtime.getObject(),
|
||||||
|
ALLOCATOR
|
||||||
|
);
|
||||||
|
|
||||||
|
lexer.defineAnnotatedMethods(Lexer.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator()
|
||||||
|
{
|
||||||
|
public IRubyObject allocate(Ruby runtime, RubyClass klass)
|
||||||
|
{
|
||||||
|
return new org.liboga.xml.Lexer(runtime, klass);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public Lexer(Ruby runtime, RubyClass klass)
|
public Lexer(Ruby runtime, RubyClass klass)
|
||||||
{
|
{
|
||||||
super(runtime, klass);
|
super(runtime, klass);
|
||||||
|
@ -26,22 +52,27 @@ public class Lexer extends RubyObject
|
||||||
@JRubyMethod
|
@JRubyMethod
|
||||||
public IRubyObject advance_native(ThreadContext context)
|
public IRubyObject advance_native(ThreadContext context)
|
||||||
{
|
{
|
||||||
|
// Pull the data in from Ruby land.
|
||||||
|
RubyString rb_str = (RubyString) this.getInstanceVariable("@data");
|
||||||
|
Encoding encoding = rb_str.getEncoding();
|
||||||
|
|
||||||
|
byte[] data = rb_str.getBytes();
|
||||||
|
|
||||||
int act = 0;
|
int act = 0;
|
||||||
int cs = 0;
|
int cs = 0;
|
||||||
int ts = 0;
|
int ts = 0;
|
||||||
int te = 0;
|
int te = 0;
|
||||||
int p = 0;
|
int p = 0;
|
||||||
int pe = 0;
|
int pe = data.length;
|
||||||
int eof = 0;
|
int eof = 0;
|
||||||
int top = 0;
|
int top = 0;
|
||||||
|
|
||||||
int[] data = {};
|
|
||||||
int[] stack = {};
|
int[] stack = {};
|
||||||
|
|
||||||
%% write init;
|
%% write init;
|
||||||
%% write exec;
|
%% write exec;
|
||||||
|
|
||||||
return context.getRuntime().getNil();
|
return context.nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue