Skip to content

Commit

Permalink
Adds possibility to use functions between cells. #5
Browse files Browse the repository at this point in the history
  • Loading branch information
jaunruh committed May 30, 2018
1 parent 7b83df1 commit 3b769b1
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
as yet unclassified
calculateResult

| currentContent expression result |
| currentContent expression result function cellPointCollection cellTextCollection |
currentContent := self text asString.
self calcRepresentation: currentContent.

(currentContent isEmpty) ifFalse: [
((currentContent at: 1) = $=) ifTrue: [
expression := ((currentContent subStrings: '=') at: 1).
result := Compiler evaluate: expression.
((currentContent first) = $=) ifTrue: [
expression := currentContent allButFirst.
function := SpreadsheetRegexMatcher getFunctionFromString: expression.
function ifNotNil: [
cellPointCollection := SpreadsheetRegexMatcher getCellIndicesForString: expression.
cellTextCollection := self grid getCellContentForPointCollection: cellPointCollection.
result := SpreadsheetMath perform: function on: cellTextCollection.
]
ifNil: [
result := Compiler evaluate: expression.
].
self text: result asString.
].
].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"acceptOnCR" : "AS 5/22/2018 22:26",
"calcRepresentation" : "AS 5/22/2018 22:44",
"calcRepresentation:" : "AS 5/22/2018 22:44",
"calculateResult" : "AS 5/25/2018 09:50",
"calculateResult" : "JU 5/30/2018 00:22",
"crAction" : "AS 5/22/2018 22:29",
"finish" : "AS 5/22/2018 22:53",
"initialize" : "AS 5/25/2018 10:58",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
layout
getCellContentForPointCollection: aCollection
"return a cell collection for a collection of points"

| cellContentCollection singleCell cellText |
cellContentCollection := OrderedCollection new.
aCollection do: [ :each |
singleCell := self cellAtRowIndex: each y colIndex: each x.
Transcript show: each.
Transcript show: singleCell contentMorph.
cellText := singleCell cell contents.
(cellText) ifNotEmpty: [
cellContentCollection add: cellText
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"editor:" : "AS 5/16/2018 17:03",
"functionWindow" : "PH 5/21/2018 20:52",
"functionWindow:" : "PH 5/21/2018 20:52",
"getCellContentForPointCollection:" : "JU 5/30/2018 00:31",
"grabbed" : "LH 5/6/2018 13:32",
"grabbed:" : "LH 5/6/2018 13:32",
"gridBounds" : "AS 5/18/2018 19:13",
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
as yet unclassified
listOfReduceOperations

^{#*. #+. #/}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
as yet unclassified
perform: anOperation on: aCollection
"perfrom the given operation on the given collection using the regex matcher"

(self listOfReduceOperations includes: anOperation)
ifTrue: [
^ aCollection reduce: anOperation
].
(aCollection respondsTo: anOperation)
ifTrue: [
^ aCollection perform: anOperation
].
^ self
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"class" : {
"listOfReduceOperations" : "JU 5/29/2018 17:02",
"perform:on:" : "JU 5/29/2018 17:02" },
"instance" : {
} }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "Spreadsheet-Core",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
],
"name" : "SpreadsheetMath",
"pools" : [
],
"super" : "Object",
"type" : "normal" }
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
as yet unclassified
functionsDict
"dict mapping the regex to the function"

^ Dictionary newFrom: {
#'sum(.*)' -> #sum.
#'max(.*)' -> #max.
#'prod(.*)' -> #*.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
as yet unclassified
getCellIndicesForString: aString
"extracts the indices for a given string"

| cellRegex cellString cellCollection fromCellPoint toCellPoint cellPointCollection |
cellRegex := '[a-zA-Z]+[0-9]+' asRegex.

cellString := self getCellstringFromString: aString.
cellCollection := cellRegex matchesIn: cellString.
cellPointCollection := OrderedCollection new.

self assert: cellCollection size > 1.
fromCellPoint := self getColumnAndRowFromCellLabel: (cellCollection at: 1).
toCellPoint :=self getColumnAndRowFromCellLabel: (cellCollection at: 2).

(fromCellPoint x) to: (toCellPoint x) do: [ :xDim |
(fromCellPoint y) to: (toCellPoint y) do: [ :yDim |
cellPointCollection add: (xDim@yDim)
]
].
^cellPointCollection

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
as yet unclassified
getCellstringFromString: aString
"get the substring describing the cells 'a7:b8' from the string"

| cellsRegex |
cellsRegex := '[a-zA-Z]+[0-9]+\:[a-zA-Z]+[0-9]+' asRegex.
^(cellsRegex matchesIn: aString) first
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
as yet unclassified
getColumnAndRowFromCellLabel: aLabel
"split a cell label into a char and a digit and convert the char to a digit >> return column and row as vector"

| char charAsDigit digit |
char := aLabel first.
charAsDigit := self getNumberFromChar: char.
digit := aLabel allButFirst asNumber.
^charAsDigit@digit
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
as yet unclassified
getFunctionFromString: aString
"return a function embedded within a string"

| functionsDict matcher |
functionsDict := self functionsDict.
functionsDict keys do: [ :each |
matcher := each asRegex.
(matcher matches: aString) ifTrue: [
^functionsDict at: each
]
].
^nil

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
as yet unclassified
getNumberFromChar: aChar
"convert a char to an integer value via the asciiValue"

| asciiVal |
asciiVal := aChar asCharacter asciiValue.
(asciiVal > 64 and: asciiVal < 91) ifTrue: [
^asciiVal - 64
].
(asciiVal > 96 and: asciiVal < 123) ifTrue: [
^asciiVal - 96
].
^false
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
as yet unclassified
hasOperation: anOperation
"checks if operation exists in functionsDict"

^self functionsDict values includes: anOperation
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"class" : {
"functionsDict" : "JU 5/29/2018 15:35",
"getCellIndicesForString:" : "JU 5/29/2018 23:50",
"getCellstringFromString:" : "JU 5/29/2018 23:46",
"getColumnAndRowFromCellLabel:" : "JU 5/29/2018 16:27",
"getFunctionFromString:" : "JU 5/29/2018 17:25",
"getNumberFromChar:" : "JU 5/29/2018 16:17",
"hasOperation:" : "JU 5/29/2018 16:55" },
"instance" : {
} }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "Spreadsheet-Core",
"classinstvars" : [
"statements" ],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
],
"name" : "SpreadsheetRegexMatcher",
"pools" : [
],
"super" : "Object",
"type" : "normal" }

0 comments on commit 3b769b1

Please sign in to comment.