Sha256: d215e59d700e5371058720dfe5baf984efe9f27cedf992cd20c37a1f82e85757

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require_relative '../lexical/token_range'

module Rley # This module is used as a namespace
  module PTree # This module is used as a namespace
    class ParseTreeNode
      # Link to the grammar symbol
      attr_reader(:symbol)

      # A range of indices for tokens corresponding to the node.
      attr_reader(:range)

      def initialize(aSymbol, aRange)
        @symbol = aSymbol
        @range = Lexical::TokenRange.new(aRange)
      end
      
      # Notify the builder that the construction is over
      def done!()
        # Do nothing
      end

      # Assign a value from given range to each  undefined range bound
      def range=(aRange)
        range.assign(aRange)
      end

      # Emit a (formatted) string representation of the node.
      # Mainly used for diagnosis/debugging purposes.
      def to_string(indentation)
        return "#{symbol.name}#{range.to_string(indentation)}"
      end

      # Emit a short string representation of the node.
      # Mainly used for diagnosis/debugging purposes.
      def to_s()
        return "#{symbol.name}#{range.to_string(0)}"
      end
    end # class
  end # module
end # module
# End of file

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rley-0.7.07 lib/rley/ptree/parse_tree_node.rb
rley-0.7.06 lib/rley/ptree/parse_tree_node.rb
rley-0.7.05 lib/rley/ptree/parse_tree_node.rb
rley-0.7.04 lib/rley/ptree/parse_tree_node.rb