Class: ReVIEW::Compiler::SyntaxElement

Inherits:
Object
  • Object
show all
Defined in:
lib/review/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, argc, &block) ⇒ SyntaxElement

Returns a new instance of SyntaxElement.



49
50
51
52
53
54
# File 'lib/review/compiler.rb', line 49

def initialize(name, type, argc, &block)
  @name = name
  @type = type
  @argc_spec = argc
  @checker = block
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



56
57
58
# File 'lib/review/compiler.rb', line 56

def name
  @name
end

Instance Method Details

#block_allowed?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/review/compiler.rb', line 84

def block_allowed?
  @type == :block or @type == :optional or @type == :minicolumn
end

#block_required?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/review/compiler.rb', line 80

def block_required?
  @type == :block or @type == :minicolumn
end

#check_args(args) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/review/compiler.rb', line 58

def check_args(args)
  unless @argc_spec === args.size
    raise CompileError, "wrong # of parameters (block command //#{@name}, expect #{@argc_spec} but #{args.size})"
  end
  if @checker
    @checker.call(*args)
  end
end

#min_argcObject



67
68
69
70
71
72
73
74
# File 'lib/review/compiler.rb', line 67

def min_argc
  case @argc_spec
  when Range then @argc_spec.begin
  when Integer then @argc_spec
  else
    raise TypeError, "argc_spec is not Range/Integer: #{inspect}"
  end
end

#minicolumn?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/review/compiler.rb', line 76

def minicolumn?
  @type == :minicolumn
end