Sha256: d0de14b7dc6d2999d97d4a58d2471152b2d62c4080a41d45a666c5774d177a3b

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

module Soroban

  class Formula < Treetop::Runtime::SyntaxNode
    def rewrite(value)
      value.gsub(/^= */, '')
    end
  end

  class Identifier < Treetop::Runtime::SyntaxNode
    def rewrite(value)
      "@#{value}.get"
    end
    def extract(value)
      value.to_sym
    end
  end

  class Function < Treetop::Runtime::SyntaxNode
    def rewrite(value)
      match = /^([^(]*)(.*)$/.match(value)
      "func_#{match[1].downcase}#{match[2]}"
    end
  end

  class Pow < Treetop::Runtime::SyntaxNode
    def rewrite(value)
      "**"
    end
  end

  class Equal < Treetop::Runtime::SyntaxNode
    def rewrite(value)
      "=="
    end
  end

  class NotEqual < Treetop::Runtime::SyntaxNode
    def rewrite(value)
      "!="
    end
  end

  class Label < Treetop::Runtime::SyntaxNode
    def rewrite(value)
      value.gsub('$', '')
    end
  end

  class Range < Treetop::Runtime::SyntaxNode
    def rewrite(value)
      "'#{value}'"
    end
    def extract(value)
      fc, fr, tc, tr = Soroban::getRange(value) 
      retval = []
      (fc..tc).each do |cc|
        (fr..tr).each do |cr|
          retval << "#{cc}#{cr}".to_sym
        end
      end
      retval
    end
  end

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
soroban-0.2.0 lib/soroban/parser/nodes.rb
soroban-0.1.1 lib/soroban/parser/nodes.rb
soroban-0.1.0 lib/soroban/parser/nodes.rb
Soroban-0.1.0 lib/soroban/parser/nodes.rb