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.
52 53 54 55 56 57 |
# File 'lib/review/compiler.rb', line 52 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.
59 60 61 |
# File 'lib/review/compiler.rb', line 59 def name @name end |
Instance Method Details
#block_allowed? ⇒ Boolean
79 80 81 |
# File 'lib/review/compiler.rb', line 79 def block_allowed? @type == :block or @type == :optional end |
#block_required? ⇒ Boolean
75 76 77 |
# File 'lib/review/compiler.rb', line 75 def block_required? @type == :block end |
#check_args(args) ⇒ Object
61 62 63 64 |
# File 'lib/review/compiler.rb', line 61 def check_args(args) raise CompileError, "wrong # of parameters (block command //#{@name}, expect #{@argc_spec} but #{args.size})" unless @argc_spec === args.size @checker.call(*args) if @checker end |
#min_argc ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/review/compiler.rb', line 66 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 |