Class: TypedRb::Model::TmRegexp

Inherits:
Expr show all
Defined in:
lib/typed/model/tm_regexp.rb

Overview

Regular expresssion

Instance Attribute Summary collapse

Attributes inherited from Expr

#col, #line, #node, #type

Instance Method Summary collapse

Constructor Details

#initialize(exp, options, node) ⇒ TmRegexp

Returns a new instance of TmRegexp.



9
10
11
12
13
# File 'lib/typed/model/tm_regexp.rb', line 9

def initialize(exp, options, node)
  super(node)
  @exp = exp
  @ptions = options
end

Instance Attribute Details

#expObject (readonly)

Returns the value of attribute exp.



8
9
10
# File 'lib/typed/model/tm_regexp.rb', line 8

def exp
  @exp
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/typed/model/tm_regexp.rb', line 8

def options
  @options
end

Instance Method Details

#check_type(context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/typed/model/tm_regexp.rb', line 15

def check_type(context)
  options.check_type(context) if options
  exp_type = exp.check_type(context)
  if exp_type.compatible?(Types::TyString.new(node), :lt)
    Types::TyRegexp.new(node)
  else
    error_message = "Error type checking  Regexp: Expected String type for expression, found #{exp_type}"
    fail Types::TypeCheckError.new(error_message, node)
  end
end