Permalink
Browse files

Add more files specific to NB plugin.

  • Loading branch information...
1 parent a1a29a0 commit fbcb9f681c3812c229d4db62dacb3188f15ce5ee @headius headius committed Mar 20, 2011
Showing with 95 additions and 0 deletions.
  1. +44 −0 lib/mirah/nbcompiler.rb
  2. +51 −0 src/org/mirah/Compiler.duby
View
@@ -0,0 +1,44 @@
+# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
+# All contributing project authors may be found in the NOTICE file.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'mirah'
+module Mirah
+ class NbCompiler
+ include org.mirah.DubyCompiler
+
+ class ParseResult
+ ParseError = org.mirah.ParseError
+
+ include org.mirah.ParseResult
+
+ attr_reader :ast, :errors
+ def initialize(ast, errors)
+ @ast = ast
+ parse_errors = errors.map do |error|
+ ParseError.new(error.message, error.position)
+ end
+ @errors = parse_errors.to_java(ParseError)
+ end
+ end
+
+ def parse(text)
+ Mirah::AST.type_factory = Mirah::JVM::Types::TypeFactory.new
+ ast = Mirah::AST.parse_ruby(text)
+ transformer = Mirah::Transform::Transformer.new(Mirah::CompilationState.new)
+ return ParseResult.new(
+ transformer.transform(ast, nil), transformer.errors)
+ end
+ end
+end
@@ -0,0 +1,51 @@
+# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
+# All contributing project authors may be found in the NOTICE file.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import org.jrubyparser.SourcePosition
+
+class ParseError
+ def initialize(message:String, position:SourcePosition)
+ @message = message
+ @position = position
+ end
+
+ def position
+ @position
+ end
+
+ def line
+ @position.getStartLine + 1
+ end
+
+ def message
+ @message
+ end
+end
+
+interface ParseResult do
+ def ast
+ returns Object
+ end
+
+ def errors
+ returns ParseError[]
+ end
+end
+
+interface DubyCompiler do
+ def parse(text:String)
+ returns ParseResult
+ end
+end

0 comments on commit fbcb9f6

Please sign in to comment.