Module: Duby::AST

Defined in:
lib/duby/ast.rb,
lib/duby/ast/call.rb,
lib/duby/ast/flow.rb,
lib/duby/ast/type.rb,
lib/duby/compiler.rb,
lib/duby/ast/class.rb,
lib/duby/ast/local.rb,
lib/duby/transform.rb,
lib/duby/ast/method.rb,
lib/duby/ast/literal.rb,
lib/duby/jvm/compiler.rb,
lib/duby/ast/structure.rb,
lib/duby/ast/intrinsics.rb,
lib/duby/jvm/source_generator/precompile.rb

Defined Under Namespace

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.verboseObject

Returns the value of attribute verbose.



6
7
8
# File 'lib/duby/ast.rb', line 6

def verbose
  @verbose
end

Class Method Details

.block_typeObject



541
542
543
# File 'lib/duby/ast.rb', line 541

def self.block_type
  TypeReference::BlockType
end

.defmacro(name, &block) ⇒ Object



563
564
565
566
567
# File 'lib/duby/ast.rb', line 563

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

.error_typeObject



533
534
535
# File 'lib/duby/ast.rb', line 533

def self.error_type
  TypeReference::ErrorType
end

.fixnum(parent, position, literal) ⇒ Object



545
546
547
548
549
550
551
552
# File 'lib/duby/ast.rb', line 545

def self.fixnum(parent, position, literal)
  factory = type_factory
  if factory
    factory.fixnum(parent, position, literal)
  else
    Fixnum.new(parent, position, literal)
  end
end

.float(parent, position, literal) ⇒ Object



554
555
556
557
558
559
560
561
# File 'lib/duby/ast.rb', line 554

def self.float(parent, position, literal)
  factory = type_factory
  if factory
    factory.float(parent, position, literal)
  else
    Float.new(parent, position, literal)
  end
end

.macro(name) ⇒ Object



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

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

.no_typeObject



524
525
526
527
528
529
530
531
# File 'lib/duby/ast.rb', line 524

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

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



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/duby/transform.rb', line 154

def parse(src, filename='-', raise_errors=false, transformer=nil)
  ast = parse_ruby(src, filename)
  transformer ||= Transform::Transformer.new(Duby::CompilationState.new)
  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)


167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/duby/transform.rb', line 167

def parse_ruby(src, filename='-')
  raise ArgumentError if src.nil?
  parser = Parser.new
  config = ParserConfiguration.new(0, CompatVersion::RUBY1_9, true)
  begin
    parser.parse(filename, StringReader.new(src), config)
  rescue => ex
    if ex.cause.respond_to? :position
      position = ex.cause.position
      Duby.print_error(ex.cause.message, position)
    end
    raise ex
  end
end

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

Shortcut method to construct type references



515
516
517
518
519
520
521
522
# File 'lib/duby/ast.rb', line 515

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

.type_factoryObject



506
507
508
# File 'lib/duby/ast.rb', line 506

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

.type_factory=(factory) ⇒ Object



510
511
512
# File 'lib/duby/ast.rb', line 510

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

.unreachable_typeObject



537
538
539
# File 'lib/duby/ast.rb', line 537

def self.unreachable_type
  TypeReference::UnreachableType
end