Sha256: 4bd580d584e551ea2d94afa20ee7982b8300cd6d29fde1da6e58181eac17ede2

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Rley # This module is used as a namespace
  module Syntax # This module is used as a namespace
    # Abstract class for grammar symbols.
    # A grammar symbol is an element that appears in grammar rules.
    class GrmSymbol
      # @return [String] The name of the grammar symbol
      attr_reader(:name)

      # An indicator that tells whether the grammar symbol can generate a
      # non-empty string of terminals.
      attr_writer(:generative)

      # Constructor.
      # aName [String] The name of the grammar symbol.
      def initialize(aName)
        raise 'Internal error: nil name encountered' if aName.nil?

        @name = aName.dup
        @name.freeze
      end

      # The String representation of the grammar symbol
      # @return [String]
      def to_s
        name.to_s
      end

      # @return [Boolean] true iff the symbol is a terminal
      def terminal?
        # Default implementation to override if necessary
        false
      end

      # @return [Boolean] true iff the symbol is generative.
      def generative?
        @generative
      end
    end # class
  end # module
end # module

# End of file

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rley-0.8.08 lib/rley/syntax/grm_symbol.rb
rley-0.8.06 lib/rley/syntax/grm_symbol.rb
rley-0.8.05 lib/rley/syntax/grm_symbol.rb
rley-0.8.03 lib/rley/syntax/grm_symbol.rb
rley-0.8.02 lib/rley/syntax/grm_symbol.rb
rley-0.8.01 lib/rley/syntax/grm_symbol.rb
rley-0.8.00 lib/rley/syntax/grm_symbol.rb