soroban 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "soroban"
8
- s.version = "0.8.0"
8
+ s.version = "0.9.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jason Hutchens"]
12
- s.date = "2014-03-25"
12
+ s.date = "2014-10-22"
13
13
  s.description = "Soroban makes it easy to extract and execute formulas from Excel spreadsheets. It rewrites Excel formulas as Ruby expressions, and allows you to bind named variables to spreadsheet cells to easily manipulate inputs and capture outputs."
14
14
  s.email = "jason.hutchens@agworld.com.au"
15
15
  s.extra_rdoc_files = [
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.9.0
@@ -2,6 +2,7 @@
2
2
 
3
3
 
4
4
  module Soroban
5
+
5
6
  module Excel
6
7
  include Treetop::Runtime
7
8
 
@@ -1393,6 +1394,9 @@ module Soroban
1393
1394
  module Identifier0
1394
1395
  end
1395
1396
 
1397
+ module Identifier1
1398
+ end
1399
+
1396
1400
  def _nt_identifier
1397
1401
  start_index = index
1398
1402
  if node_cache[:identifier].has_key?(index)
@@ -1404,38 +1408,125 @@ module Soroban
1404
1408
  return cached
1405
1409
  end
1406
1410
 
1407
- i0, s0 = index, []
1411
+ i0 = index
1412
+ i1, s1 = index, []
1408
1413
  if has_terminal?('\G[a-zA-Z]', true, index)
1409
- r1 = true
1414
+ r2 = true
1410
1415
  @index += 1
1411
1416
  else
1412
- r1 = nil
1417
+ r2 = nil
1413
1418
  end
1414
- s0 << r1
1415
- if r1
1416
- s2, i2 = [], index
1419
+ s1 << r2
1420
+ if r2
1421
+ s3, i3 = [], index
1417
1422
  loop do
1418
1423
  if has_terminal?('\G[a-zA-Z0-9]', true, index)
1419
- r3 = true
1424
+ r4 = true
1420
1425
  @index += 1
1421
1426
  else
1422
- r3 = nil
1427
+ r4 = nil
1423
1428
  end
1424
- if r3
1425
- s2 << r3
1429
+ if r4
1430
+ s3 << r4
1426
1431
  else
1427
1432
  break
1428
1433
  end
1429
1434
  end
1430
- r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
1431
- s0 << r2
1435
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
1436
+ s1 << r3
1432
1437
  end
1433
- if s0.last
1434
- r0 = instantiate_node(Identifier,input, i0...index, s0)
1435
- r0.extend(Identifier0)
1438
+ if s1.last
1439
+ r1 = instantiate_node(Identifier,input, i1...index, s1)
1440
+ r1.extend(Identifier0)
1436
1441
  else
1437
- @index = i0
1438
- r0 = nil
1442
+ @index = i1
1443
+ r1 = nil
1444
+ end
1445
+ if r1
1446
+ r0 = r1
1447
+ else
1448
+ i5, s5 = index, []
1449
+ if has_terminal?('$', false, index)
1450
+ r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
1451
+ @index += 1
1452
+ else
1453
+ terminal_parse_failure('$')
1454
+ r6 = nil
1455
+ end
1456
+ s5 << r6
1457
+ if r6
1458
+ s7, i7 = [], index
1459
+ loop do
1460
+ if has_terminal?('\G[A-Za-z]', true, index)
1461
+ r8 = true
1462
+ @index += 1
1463
+ else
1464
+ r8 = nil
1465
+ end
1466
+ if r8
1467
+ s7 << r8
1468
+ else
1469
+ break
1470
+ end
1471
+ end
1472
+ if s7.empty?
1473
+ @index = i7
1474
+ r7 = nil
1475
+ else
1476
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
1477
+ end
1478
+ s5 << r7
1479
+ if r7
1480
+ if has_terminal?('$', false, index)
1481
+ r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
1482
+ @index += 1
1483
+ else
1484
+ terminal_parse_failure('$')
1485
+ r9 = nil
1486
+ end
1487
+ s5 << r9
1488
+ if r9
1489
+ if has_terminal?('\G[1-9]', true, index)
1490
+ r10 = true
1491
+ @index += 1
1492
+ else
1493
+ r10 = nil
1494
+ end
1495
+ s5 << r10
1496
+ if r10
1497
+ s11, i11 = [], index
1498
+ loop do
1499
+ if has_terminal?('\G[0-9]', true, index)
1500
+ r12 = true
1501
+ @index += 1
1502
+ else
1503
+ r12 = nil
1504
+ end
1505
+ if r12
1506
+ s11 << r12
1507
+ else
1508
+ break
1509
+ end
1510
+ end
1511
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
1512
+ s5 << r11
1513
+ end
1514
+ end
1515
+ end
1516
+ end
1517
+ if s5.last
1518
+ r5 = instantiate_node(Identifier,input, i5...index, s5)
1519
+ r5.extend(Identifier1)
1520
+ else
1521
+ @index = i5
1522
+ r5 = nil
1523
+ end
1524
+ if r5
1525
+ r0 = r5
1526
+ else
1527
+ @index = i0
1528
+ r0 = nil
1529
+ end
1439
1530
  end
1440
1531
 
1441
1532
  node_cache[:identifier][start_index] = r0
@@ -1873,4 +1964,5 @@ module Soroban
1873
1964
  include Excel
1874
1965
  end
1875
1966
 
1967
+
1876
1968
  end
@@ -53,7 +53,7 @@ module Soroban
53
53
  [0-9]+ <IntegerValue>
54
54
  end
55
55
  rule identifier
56
- [a-zA-Z] [a-zA-Z0-9]* <Identifier>
56
+ [a-zA-Z] [a-zA-Z0-9]* <Identifier> / '$' [A-Za-z]+ '$' [1-9] [0-9]* <Identifier>
57
57
  end
58
58
  rule label
59
59
  [A-Za-z]+ [1-9] [0-9]* <Label> / '$' [A-Za-z]+ '$' [1-9] [0-9]* <Label>
@@ -9,10 +9,10 @@ module Soroban
9
9
 
10
10
  class Identifier < Treetop::Runtime::SyntaxNode
11
11
  def rewrite_ruby(value)
12
- "@#{value}.get"
12
+ "@#{value.gsub('$', '')}.get"
13
13
  end
14
14
  def extract_labels(value)
15
- value.to_sym
15
+ value.gsub('$', '').to_sym
16
16
  end
17
17
  end
18
18
 
@@ -165,4 +165,11 @@ describe "Soroban" do
165
165
  sheet.A3.should be_within(1e-6).of(0.5)
166
166
  end
167
167
 
168
+ it "supports absolute cell references" do
169
+ sheet.set(:A1 => "1")
170
+ sheet.set(:A2 => "2")
171
+ sheet.set(:A3 => "=$A$2 + $A$1")
172
+ sheet.A3.should eq(3)
173
+ end
174
+
168
175
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soroban
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 8
8
+ - 9
9
9
  - 0
10
- version: 0.8.0
10
+ version: 0.9.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason Hutchens
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2014-03-25 00:00:00 Z
18
+ date: 2014-10-22 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: treetop