Class: Antlr4Native::ContextMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/antlr4-native/context_method.rb

Constant Summary collapse

RULE_METHODS =
%w(enterRule exitRule getRuleIndex).freeze
META_METHODS =
%w(accept copyFrom).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, raw_args, return_type, context) ⇒ ContextMethod

Returns a new instance of ContextMethod.


8
9
10
11
12
13
# File 'lib/antlr4-native/context_method.rb', line 8

def initialize(name, raw_args, return_type, context)
  @name = name
  @raw_args = raw_args
  @return_type = return_type
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.


6
7
8
# File 'lib/antlr4-native/context_method.rb', line 6

def context
  @context
end

#nameObject (readonly)

Returns the value of attribute name.


6
7
8
# File 'lib/antlr4-native/context_method.rb', line 6

def name
  @name
end

#raw_argsObject (readonly)

Returns the value of attribute raw_args.


6
7
8
# File 'lib/antlr4-native/context_method.rb', line 6

def raw_args
  @raw_args
end

#return_typeObject (readonly)

Returns the value of attribute return_type.


6
7
8
# File 'lib/antlr4-native/context_method.rb', line 6

def return_type
  @return_type
end

Instance Method Details

#argsObject


25
26
27
28
29
# File 'lib/antlr4-native/context_method.rb', line 25

def args
  @args ||= raw_args.split(',').map do |arg|
    ContextMethodArg.new(arg.strip)
  end
end

#constructor?Boolean

Returns:

  • (Boolean)

55
56
57
# File 'lib/antlr4-native/context_method.rb', line 55

def constructor?
  name == context.name
end

#context_method?Boolean

@TODO: consider revising this

Returns:

  • (Boolean)

36
37
38
39
40
41
# File 'lib/antlr4-native/context_method.rb', line 36

def context_method?
  !token_method? &&
    !rule_method? &&
    !meta_method? &&
    !constructor?
end

#cpp_nameObject


15
16
17
18
19
20
21
22
23
# File 'lib/antlr4-native/context_method.rb', line 15

def cpp_name
  @cpp_name ||=
    if args.size == 1 && args.first.name == 'i'
      # special case
      "#{name}At"
    else
      [name, *args.map(&:name)].join('_')
    end
end

#meta_method?Boolean

Returns:

  • (Boolean)

51
52
53
# File 'lib/antlr4-native/context_method.rb', line 51

def meta_method?
  META_METHODS.include?(name)
end

#returns_vector?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/antlr4-native/context_method.rb', line 31

def returns_vector?
  return_type.start_with?('std::vector')
end

#rule_method?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'lib/antlr4-native/context_method.rb', line 47

def rule_method?
  RULE_METHODS.include?(name)
end

#token_method?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/antlr4-native/context_method.rb', line 43

def token_method?
  name[0].upcase == name[0]
end