Sha256: 209e1d840686b569137008b401dab0f9e61f1f4f8eea16076162c34ebf990267

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Dendroid
  # This module contains for all classes representing elements of .
  module Syntax
    # 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

      # Constructor.
      # aSymbolName [String] The name of the grammar symbol.
      def initialize(symbolName)
        @name = valid_name(symbolName)
      end

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

      # Equality testing (based on symbol names)
      # @return [Boolean]
      def ==(other)
        name == other.name
      end

      private

      def valid_name(symbolName)
        if symbolName.is_a?(String)
          stripped = symbolName.strip
          if stripped.empty?
            err_msg = 'A symbol name cannot be empty.'
            raise StandardError, err_msg
          end
          stripped.to_sym
        else
          symbolName
        end
      end
    end # class
  end # module
end # module

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dendroid-0.2.04 lib/dendroid/syntax/grm_symbol.rb
dendroid-0.2.03 lib/dendroid/syntax/grm_symbol.rb
dendroid-0.2.02 lib/dendroid/syntax/grm_symbol.rb
dendroid-0.2.01 lib/dendroid/syntax/grm_symbol.rb
dendroid-0.2.00 lib/dendroid/syntax/grm_symbol.rb
dendroid-0.1.00 lib/dendroid/syntax/grm_symbol.rb
dendroid-0.0.12 lib/dendroid/syntax/grm_symbol.rb
dendroid-0.0.11 lib/dendroid/syntax/grm_symbol.rb
dendroid-0.0.10 lib/dendroid/syntax/grm_symbol.rb