Class: ReVIEW::Compiler::SyntaxElement
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #block_allowed? ⇒ Boolean
- #block_required? ⇒ Boolean
- #check_args(args) ⇒ Object
-
#initialize(name, type, argc, &block) ⇒ SyntaxElement
constructor
A new instance of SyntaxElement.
- #min_argc ⇒ Object
Constructor Details
#initialize(name, type, argc, &block) ⇒ SyntaxElement
Returns a new instance of SyntaxElement.
30 31 32 33 34 35 |
# File 'lib/review/compiler.rb', line 30 def initialize(name, type, argc, &block) @name = name @type = type @argc_spec = argc @checker = block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
37 38 39 |
# File 'lib/review/compiler.rb', line 37 def name @name end |
Instance Method Details
#block_allowed? ⇒ Boolean
61 62 63 |
# File 'lib/review/compiler.rb', line 61 def block_allowed? @type == :block or @type == :optional end |
#block_required? ⇒ Boolean
57 58 59 |
# File 'lib/review/compiler.rb', line 57 def block_required? @type == :block end |
#check_args(args) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/review/compiler.rb', line 39 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_argc ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/review/compiler.rb', line 48 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 |