Module: Mirah::AST

Defined in:
lib/mirah/ast/call.rb,
lib/mirah/ast.rb,
lib/mirah/ast/flow.rb,
lib/mirah/ast/type.rb,
lib/mirah/ast/class.rb,
lib/mirah/ast/local.rb,
lib/mirah/ast/scope.rb,
lib/mirah/ast/method.rb,
lib/mirah/plugin/gwt.rb,
lib/mirah/ast/literal.rb,
lib/mirah/jvm/compiler.rb,
lib/mirah/ast/structure.rb,
lib/mirah/compiler/call.rb,
lib/mirah/compiler/flow.rb,
lib/mirah/compiler/type.rb,
lib/mirah/ast/intrinsics.rb,
lib/mirah/compiler/class.rb,
lib/mirah/compiler/local.rb,
lib/mirah/compiler/method.rb,
lib/mirah/compiler/literal.rb,
lib/mirah/transform/ast_ext.rb,
lib/mirah/compiler/structure.rb,
lib/mirah/jvm/source_generator/precompile.rb

Overview

Copyright © 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.

Defined Under Namespace

Modules: Annotated, Binding, ClassScoped, Literal, Named, Scope, Scoped, Typed, Valued Classes: AccessLevel, Annotation, Argument, Arguments, Array, BindingReference, Block, BlockArgument, BlockPass, Body, Boolean, Break, Builtin, Call, ClassAppendSelf, ClassDefinition, ClosureDefinition, Colon2, Condition, Constant, ConstructorDefinition, EmptyArray, EmtpyArray, Ensure, ErrorNode, Field, FieldAssignment, FieldDeclaration, Fixnum, Float, FunctionalCall, Hash, If, Import, Include, InlineCode, InterfaceDeclaration, JsniMethodDefinition, Local, LocalAssignment, LocalDeclaration, Loop, MacroDefinition, MethodDefinition, MirahErrorHandler, Next, Node, NodeProxy, Noop, Not, Null, OptionalArgument, Raise, Redo, Regexp, RequiredArgument, Rescue, RescueClause, RestArgument, Return, ScopedBody, Script, Self, StaticMethodDefinition, StaticScope, String, StringConcat, Super, Symbol, TempValue, ToString, TypeDefinition, TypeReference, Unquote, UnquoteAssign, UnquotedValue, UnquotedValueAssign

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.verboseObject

Returns the value of attribute verbose.



23
24
25
# File 'lib/mirah/ast.rb', line 23

def verbose
  @verbose
end

Class Method Details

.block_typeObject



582
583
584
# File 'lib/mirah/ast.rb', line 582

def self.block_type
  TypeReference::BlockType
end

.defmacro(name, &block) ⇒ Object



594
595
596
597
598
# File 'lib/mirah/ast.rb', line 594

def self.defmacro(name, &block)
  @macros ||= {}
  raise "Conflicting macros for #{name}" if @macros[name]
  @macros[name] = block
end

.error_typeObject



569
570
571
# File 'lib/mirah/ast.rb', line 569

def self.error_type
  TypeReference::ErrorType
end

.fixnum(parent, position, literal) ⇒ Object



586
587
588
# File 'lib/mirah/ast.rb', line 586

def self.fixnum(parent, position, literal)
  Fixnum.new(parent, position, literal)
end

.float(parent, position, literal) ⇒ Object



590
591
592
# File 'lib/mirah/ast.rb', line 590

def self.float(parent, position, literal)
  Float.new(parent, position, literal)
end

.macro(name) ⇒ Object



600
601
602
# File 'lib/mirah/ast.rb', line 600

def self.macro(name)
  @macros[name]
end

.no_typeObject



560
561
562
563
564
565
566
567
# File 'lib/mirah/ast.rb', line 560

def self.no_type
  factory = type_factory
  if factory
    factory.no_type
  else
    TypeReference::NoType
  end
end

.parse(src, filename = 'dash_e', raise_errors = false, transformer = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mirah/transform/ast_ext.rb', line 28

def parse(src, filename='dash_e', raise_errors=false, transformer=nil)
  ast = parse_ruby(src, filename)
  transformer ||= Transform::Transformer.new(Mirah::Util::CompilationState.new)
  transformer.filename = filename
  ast = transformer.transform(ast, nil)
  if raise_errors
    transformer.errors.each do |e|
      raise e.cause || e
    end
  end
  ast
end

.parse_ruby(src, filename = '-') ⇒ Object

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mirah/transform/ast_ext.rb', line 42

def parse_ruby(src, filename='-')
  raise ArgumentError if src.nil?
  parser = MirahParser.new
  parser.filename = filename
  parser.errorHandler = MirahErrorHandler.new
  begin
    parser.parse(src)
  rescue => ex
    if ex.cause.kind_of? Java::Jmeta::SyntaxError
      ex = SyntaxError.wrap ex.cause, nil
    end

    if ex.cause.respond_to? :position
      position = ex.cause.position
      Mirah.print_error(ex.cause.message, position)
    end
    raise ex
  end
end

.type(scope, typesym, array = false, meta = false) ⇒ Object

Shortcut method to construct type references



551
552
553
554
555
556
557
558
# File 'lib/mirah/ast.rb', line 551

def self.type(scope, typesym, array = false, meta = false)
  factory = type_factory
  if factory
    factory.type(scope, typesym, array, meta)
  else
    TypeReference.new(typesym, array, meta)
  end
end

.type_factoryObject



542
543
544
# File 'lib/mirah/ast.rb', line 542

def self.type_factory
  Thread.current[:ast_type_factory]
end

.type_factory=(factory) ⇒ Object



546
547
548
# File 'lib/mirah/ast.rb', line 546

def self.type_factory=(factory)
  Thread.current[:ast_type_factory] = factory
end

.unreachable_typeObject



573
574
575
576
577
578
579
580
# File 'lib/mirah/ast.rb', line 573

def self.unreachable_type
  factory = type_factory
  if factory
    factory.unreachable_type
  else
    TypeReference::UnreachableType
  end
end