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: CallOpAssignment, ClassScoped, JRubyAst, Literal, Named, Scope, Scoped, Typed, Valued
Classes: Argument, Arguments, Array, BlockArgument, Body, Boolean, Break, Call, ClassDefinition, Colon2, Condition, Constant, EmptyArray, EmtpyArray, Ensure, ErrorNode, Field, FieldAssignment, FieldDeclaration, Fixnum, Float, ForLoop, FunctionalCall, Hash, If, Import, InterfaceDeclaration, JumpNode, Local, LocalAssignment, LocalDeclaration, Loop, MethodDefinition, Next, Node, Noop, Not, Null, OptionalArgument, Print, Raise, Redo, RequiredArgument, Rescue, RescueClause, RestArgument, Return, Script, Self, StaticMethodDefinition, String, Symbol, TempValue, TypeDefinition, TypeReference, VoidType, WhileLoop
Class Attribute Summary collapse
Class Method Summary
collapse
-
.defmacro(name, &block) ⇒ Object
-
.error_type ⇒ Object
-
.fixnum(parent, position, literal) ⇒ Object
-
.float(parent, position, literal) ⇒ Object
-
.macro(name) ⇒ Object
-
.no_type ⇒ Object
-
.parse(src, filename = '-', raise_errors = false) ⇒ Object
-
.parse_ruby(src, filename = '-') ⇒ Object
-
.type(typesym, array = false, meta = false) ⇒ Object
Shortcut method to construct type references.
-
.type_factory ⇒ Object
-
.type_factory=(factory) ⇒ Object
-
.unreachable_type ⇒ Object
Class Attribute Details
Returns the value of attribute verbose.
6
7
8
|
# File 'lib/duby/ast.rb', line 6
def verbose
@verbose
end
|
Class Method Details
.defmacro(name, &block) ⇒ Object
320
321
322
323
324
|
# File 'lib/duby/ast.rb', line 320
def self.defmacro(name, &block)
@macros ||= {}
raise "Conflicting macros for #{name}" if @macros[name]
@macros[name] = block
end
|
.fixnum(parent, position, literal) ⇒ Object
302
303
304
305
306
307
308
309
|
# File 'lib/duby/ast.rb', line 302
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
311
312
313
314
315
316
317
318
|
# File 'lib/duby/ast.rb', line 311
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
326
327
328
|
# File 'lib/duby/ast.rb', line 326
def self.macro(name)
@macros[name]
end
|
285
286
287
288
289
290
291
292
|
# File 'lib/duby/ast.rb', line 285
def self.no_type
factory = type_factory
if factory
factory.no_type
else
TypeReference::NoType
end
end
|
.parse(src, filename = '-', raise_errors = false) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/duby/transform.rb', line 93
def parse(src, filename='-', raise_errors=false)
ast = parse_ruby(src, filename)
transformer = Transform::Transformer.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/duby/transform.rb', line 106
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
puts "#{position.file}:#{position.start_line + 1}: #{ex.message}"
end
raise ex
end
end
|
.type(typesym, array = false, meta = false) ⇒ Object
Shortcut method to construct type references
276
277
278
279
280
281
282
283
|
# File 'lib/duby/ast.rb', line 276
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_factory ⇒ Object
267
268
269
|
# File 'lib/duby/ast.rb', line 267
def self.type_factory
Thread.current[:ast_type_factory]
end
|
.type_factory=(factory) ⇒ Object
271
272
273
|
# File 'lib/duby/ast.rb', line 271
def self.type_factory=(factory)
Thread.current[:ast_type_factory] = factory
end
|