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
- #code_block? ⇒ Boolean
-
#initialize(name, type, argc, esc, &block) ⇒ SyntaxElement
constructor
A new instance of SyntaxElement.
- #min_argc ⇒ Object
- #parse_args(args) ⇒ Object
Constructor Details
#initialize(name, type, argc, esc, &block) ⇒ SyntaxElement
Returns a new instance of SyntaxElement.
471 472 473 474 475 476 477 |
# File 'lib/review/compiler.rb', line 471 def initialize(name, type, argc, esc, &block) @name = name @type = type @argc_spec = argc @esc_patterns = esc @checker = block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
479 480 481 |
# File 'lib/review/compiler.rb', line 479 def name @name end |
Instance Method Details
#block_allowed? ⇒ Boolean
515 516 517 |
# File 'lib/review/compiler.rb', line 515 def block_allowed? @type == :block or @type == :code_block or @type == :optional or @type == :optional_code_block end |
#block_required? ⇒ Boolean
511 512 513 |
# File 'lib/review/compiler.rb', line 511 def block_required? @type == :block or @type == :code_block end |
#check_args(args) ⇒ Object
481 482 483 484 485 486 |
# File 'lib/review/compiler.rb', line 481 def check_args(args) unless @argc_spec === args.size raise ReVIEW::CompileError, "wrong # of parameters (block command //#{@name}, expect #{@argc_spec} but #{args.size})" end @checker.call(*args) if @checker end |
#code_block? ⇒ Boolean
519 520 521 |
# File 'lib/review/compiler.rb', line 519 def code_block? @type == :code_block or @type == :optional_code_block end |
#min_argc ⇒ Object
488 489 490 491 492 493 494 495 |
# File 'lib/review/compiler.rb', line 488 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 |
#parse_args(args) ⇒ Object
497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/review/compiler.rb', line 497 def parse_args(args) if @esc_patterns args.map.with_index do |pattern, i| if @esc_patterns[i] args[i].__send__("to_#{@esc_patterns[i]}") else args[i].to_doc end end else args.map(&:to_doc) end end |