Sha256: 53b06746fb5b8579a63ed85478bcbf33aaff9c100c60c53ddc7474a3b46f1d98
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
=begin This is experimental. Please do not use it. IT WILL NOT WORK I don't know if i will extend the work on the evaluation of formulas. You can access all formulas as a string and do whatever you want with this. =end require 'llip' require 'llip/visitable' class Formula include LLIP::Visitable attr_accessor :name attr_accessor :params end class Param include LLIP::Visitable attr_accessor :column_name end class Visitor def visit_formula(formula) puts " -- " + formula.name formula.params.each { |p| p.accept(self) } end def visit_param(param) puts " |-- " + param.column_name end end class SpreadsheetParser < LLIP::Parser letters = ("A".."Z").to_a.join("|") token :id, "(#{letters})+" token :"(", '\(' token :")", '\)' token :"[", '[' token :"]", ']' token :".", '.' num = (1..9).to_a.join("|") token :num , "(#{num})(#{num}|0)*" token :sep, ":" scope :formula production :formula do |p| p.token(:id) do |result,scanner,parser| result = Formula.new result.name = scanner.current puts "<"+result.name+">" raise unless scanner.next == :"(" raise unless scanner.next == :"[" scanner.next result.params = parser.parse_params raise unless scanner.current == :"]" raise unless scanner.current == :")" scanner.next result end end production :params, :recursive do |p| p.default do |scanner, parser| [] end p.token(:id) do |result, scanner, parser| param = Param.new param.column_name = scanner.current.to_s raise unless scanner.next == :"." raise unless scanner.next == :num param.column_name += scanner.current.to_s scanner.next result << param end p.token(:sep) do |result,scanner,parser| scanner.next result end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
roo-0.4.0 | lib/roo/spreadsheetparser.rb |