Sha256: ce315eec0d14da3ac186d4765ce7fc5f4ab8eccde221bdb0c3992cf8c497ae06

Contents?: true

Size: 962 Bytes

Versions: 9

Compression:

Stored size: 962 Bytes

Contents

module ShellOpts
  module Ast
    class Node
      # The associated Grammar::Node object
      attr_reader :grammar

      # Key of node. Shorthand for grammar.key
      def key() @grammar.key end

      # Name of node (either program, command, or option name)
      attr_reader :name

      # Initialize an +Ast::Node+ object. +grammar+ is the corresponding
      # grammar object (+Grammar::Node+) and +name+ is the name of the option
      # or sub-command
      def initialize(grammar, name)
        @grammar, @name = grammar, name
      end

      # Return a name/value pair
      def to_tuple
        [name, values]
      end

      # Return either a value (option value), an array of values (command), or
      # nil (option without a value). Should be defined in sub-classes
      def values() raise end

      # :nocov:
      def dump(&block)
        puts key.inspect
        indent { yield } if block_given?
      end
      # :nocov:
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
shellopts-1.0.1 lib/shellopts/ast/node.rb
shellopts-1.0.0 lib/shellopts/ast/node.rb
shellopts-0.9.7 lib/shellopts/ast/node.rb
shellopts-0.9.6 lib/shellopts/ast/node.rb
shellopts-0.9.5 lib/shellopts/ast/node.rb
shellopts-0.9.4 lib/shellopts/ast/node.rb
shellopts-0.9.3 lib/shellopts/ast/node.rb
shellopts-0.9.2 lib/shellopts/ast/node.rb
shellopts-0.9.1 lib/shellopts/ast/node.rb