~tim/scheme-vm

ref: 6276f397c829732a84c5ed8c87ba3253e0370267 scheme-vm/vm/atom.rb -rw-r--r-- 569 bytes
6276f397Tim Morgan Update code style 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'parslet'

class VM
  class Atom < String
    attr_reader :filename, :line, :column

    def initialize(name, filename: nil, line: nil, column: nil)
      super(name.to_s)
      @filename = filename
      @line = line
      @column = column
    end

    def raw
      self
    end

    alias eq? ==
    alias eqv? ==

    def to_ruby
      to_s
    end

    def copy_and_rename(name)
      self.class.new(name, filename: filename, line: line, column: column)
    end

    def sub(*_args)
      new_name = super
      copy_and_rename(new_name)
    end
  end
end