42
Implementation of Table Structured References in LibreOffice Calc Eike Rathke, Red Hat, Inc. 2015-09-25

Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

Implementation of Table Structured References in LibreOffice Calc

Eike Rathke, Red Hat, Inc.2015-09-25

Page 2: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

2Table Structured References in Calc, Eike Rathke (erAck)

About the Speaker

Eike Rathke, known on the net as erAckBased in Hamburg, GermanyWorked on StarOffice from 1993 to 2000 for Star DivisionWorked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and one other companyWorks on LibreOffice since 2011, employed by Red Hat, Inc.Areas of expertise:

Calc core, formula compiler and interpreternumber formatter/scanneri18n framework, locale data

Also mentor and knowledge spreader whenever possibleWeb site http://erack.de/

Page 3: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

3Table Structured References in Calc, Eike Rathke (erAck)

Agenda

Brief overview on formula compilationChallenges of Table structured referencesImagine all the tokensSolve the puzzle

Page 4: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

4Table Structured References in Calc, Eike Rathke (erAck)

Brief overview on formula compilation

Only what is needed to understand the later approach …

Page 5: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

5Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

=SUM(A2:A4)

Page 6: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

6Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

=SUM(A2:A4)Two passes1.Scan text into tokens, each token with

OpCode (enum values of functions, operators, ...)StackVarEnum (type of token)Stored in FormulaTokenArray::pCode

Page 7: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

7Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

SUM ( A2:A4 )↓ ↓ ↓ ↓ocSum ocOpen ocPush ocClose

Page 8: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

8Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

SUM ( A2:A4 )↓ ↓ ↓ ↓ocSum ocOpen ocPush ocClosesvByte svSep svDoubleRef svSep

Page 9: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

9Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

=SUM(A2:A4)Two passes1.Scan text into tokens, each token with

OpCode (enum values of functions, operators, ...)StackVarEnum (type of token)Stored in FormulaTokenArray::pCode

Page 10: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

10Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

=SUM(A2:A4)Two passes1.Scan text into tokens, each token with

OpCode (enum values of functions, operators, ...)StackVarEnum (type of token)Stored in FormulaTokenArray::pCode

2.Create a sequence of interpret-able tokensin Reverse Polish Notation (RPN)through a recursive descending parserStored in FormulaTokenArray::pRPN

Page 11: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

11Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

SUM ( A2:A4 )↓ ↓ ↓ ↓ocSum ocOpen ocPush ocClosesvByte svSep svDoubleRef svSep

Page 12: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

12Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

SUM ( A2:A4 )↓ ↓ ↓ ↓ocSum ocOpen ocPush ocClosesvByte svSep svDoubleRef svSep

ocSum

Page 13: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

13Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

SUM ( A2:A4 )↓ ↓ ↓ ↓ocSum ocOpen ocPush ocClosesvByte svSep svDoubleRef svSep

ocSum ┐ └

Page 14: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

14Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

SUM ( A2:A4 )↓ ↓ ↓ ↓ocSum ocOpen ocPush ocClosesvByte svSep svDoubleRef svSep

ocSum ┐ └ ocPush

Page 15: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

15Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

SUM ( A2:A4 )↓ ↓ ↓ ↓ocSum ocOpen ocPush ocClosesvByte svSep svDoubleRef svSep

ocSum ┐ └ ocPush ┘

Page 16: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

16Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

SUM ( A2:A4 )↓ ↓ ↓ ↓ocSum ocOpen ocPush ocClosesvByte svSep svDoubleRef svSep

ocSum ┐ └

ocPush

Page 17: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

17Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

SUM ( A2:A4 )↓ ↓ ↓ ↓ocSum ocOpen ocPush ocClosesvByte svSep svDoubleRef svSep

ocPush ocSum

Page 18: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

18Table Structured References in Calc, Eike Rathke (erAck)

Compiling a Formula

SUM ( A2:A4 )↓ ↓ ↓ ↓ocSum ocOpen ocPush ocClosesvByte svSep svDoubleRef svSep

ocPush ocSumsvDoubleRef svByte

Page 19: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

19Table Structured References in Calc, Eike Rathke (erAck)

Challenges of Table structured references

It might look easy, but ...

Page 20: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

20Table Structured References in Calc, Eike Rathke (erAck)

Challenges of TableRef

Header1 Header2

Data11 Data21

Data12 Data22

Data13 Data23

Total1 Total2

A table is a cell range defined as a named database rangeOptional header rowOne or more data rowsOptional totals row

Table structured references provide a syntax to address different parts of such tableAssume this sample table to be named Table and to cover cells A1:B5 for the examples later

Page 21: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

21Table Structured References in Calc, Eike Rathke (erAck)

Challenges of TableRef

structure-reference = [table-identifier] intra-table-reference

table-identifier = [book-prefix] table-name

table-name = name

intra-table-reference = spaced-lbracket inner-reference spaced-rbracket / keyword / ("[" [simple-column-name] "]")

inner-reference = keyword-list / ([keyword-list spaced-comma] column-range)

keyword = "[#All]" / "[#Data]" / "[#Headers]" / "[#Totals]" / "[#This Row]"

keyword-list = keyword / ("[#Headers]" spaced-comma "[#Data]") / ("[#Data]" spaced-comma "[#Totals]")

column-range = column [":" column]

column = simple-column-name / ("[" *space simple-column-name *space "]")

simple-column-name = [any-nospace-column-character *any-column-character] any-nospace-column-character

escape-column-character = tick / "[" / "]" / "#"

tick = %x27

unescaped-column-character = character ; MUST NOT match escape-column-character or space

any-column-character = any-nospace-column-character / space

any-nospace-column-character = unescaped-column-character / (tick escape-column-character)

spaced-comma = [space] comma [space]

spaced-lbracket = "[" [space]

spaced-rbracket = [space] "]"

(Definitions excerpt of [MS-XLSX]: 2.2.2 Formulas, https://msdn.microsoft.com/en-us/library/dd906358.aspx)

Page 22: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

22Table Structured References in Calc, Eike Rathke (erAck)

Challenges of TableRef

Example Reference Resulting Range

Table[[#All]] A1:B5 (entire table)

Table[] A2:B4 (data area)

Table[[#Data]] A2:B4 (data area)

Table[[#Headers]] A1:B1 (header row)

Table[[#Totals]] A5:B5 (totals row)

Table[[Header1]] A2:A4 (data of column Header1)

Table[[#Data],[Header1]] A2:A4 (data of column Header1)

Table[[#Totals],[Header1]] A5 (totals of column Header1)

Table[[#Headers],[#Data],[Header1]] A1:A4 (header and data of column Header1)

Table[[#This Row]] A1:B1,A2:B2,… (all cells of this row)

Table[[#This Row],[Header1]] A1,A2,… (this row's cell of column Header1)

Table[[#This Row],[Header1]:[Header2]] A1:B1,A2:B2,… (this row's cells of column range)

Page 23: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

23Table Structured References in Calc, Eike Rathke (erAck)

Imagine all the tokens

One for each...

Page 24: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

24Table Structured References in Calc, Eike Rathke (erAck)

Imagine all the tokens

Symbol Token

Table (name) ocDBArea, already existed

[ ocTableRefOpen

] ocTableRefClose

#All ocTableRefItemAll

#Headers ocTableRefItemHeaders

#Data ocTableRefItemData

#Totals ocTableRefItemTotals

#This Row ocTableRefItemThisRow

, ocSep

: ocRange

… resulting token / reference ocTableRef

Page 25: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

25Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

With yet another new token...

Page 26: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

26Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

=SUM(Table[[#Data],[Header1]])

Page 27: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

27Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

=SUM(Table[[#Data],[Header1]])Table[[#Data],[Header1]]

Page 28: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

28Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [[#Data],[Header1]]↓ocDBAreasvIndex

Page 29: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

29Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [#Data],[Header1]]↓ ↓ocDBArea ocTableRefOpensvIndex svSep

Page 30: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

30Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [#Data],[Header1]]↓ ↓ocDBArea ocTableRefOpensvIndex svSep↘ocTableRefsvIndex(ScTableRefToken, additionally holds item information and another token reference)

Page 31: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

31Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [#Data],[Header1]]↓ ↓ocTableRef ocTROsvIndex svSep

Page 32: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

32Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [ #Data],[Header1]]↓ ↓ ↓ocTableRef ocTRO ocTROsvIndex svSep

Page 33: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

33Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [ #Data ],[Header1]]↓ ↓ ↓ ↓ocTableRef ocTRO ocTRO ocTableRefItemDatasvIndex svSep

Page 34: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

34Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [ #Data ],[Header1]]↓ ↓ ↓ ↓ocTableRef ocTRO ocTRO ocTableRefItemDatasvIndex svSep#Data

Page 35: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

35Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [ #Data ] ,[Header1]]↓ ↓ ↓ ↓ ↓ocTableRef ocTRO ocTRO ocTRID ocTRCsvIndex svSep#Data

Page 36: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

36Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [ #Data ] , [ Header1 ]]

↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ocTableRef ocTRO ocTRO ocTRID ocTRC ocSep ocTRO ocPush

svIndex svSep svSingleRef

#Data A1

Page 37: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

37Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [ #Data ] , [ Header1 ] ]

↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ocTableRef ocTRO ocTRO ocTRID ocTRC ocSep ocTRO ocPush C C

svIndex svSep svSingleRef

#Data A1

Page 38: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

38Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [ #Data ] , [ Header1 ] ]

↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ocTableRef ocTRO ocTRO ocTRID ocTRC ocSep ocTRO ocPush C C

svIndex svSep svSingleRef

#Data A1

ocPush

svDoubleRef

A2:A4

Page 39: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

39Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [ #Data ] , [ Header1 ] ]

↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ocTableRef ocTRO ocTRO ocTRID ocTRC ocSep ocTRO ocPush C C

svIndex svSep svSingleRef

#Data A1

ocPush

svDoubleRef

A2:A4

Page 40: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

40Table Structured References in Calc, Eike Rathke (erAck)

Solving the puzzle

Table [ [ #Data ] , [ Header1 ] ]

↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ocTableRef ocTRO ocTRO ocTRID ocTRC ocSep ocTRO ocPush C C

svIndex svSep svSingleRef

#Data A1

ocPush

svDoubleRef

A2:A4

ocPush

svDoubleRef

A2:A4

Page 41: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

41Table Structured References in Calc, Eike Rathke (erAck)

Questions?

I might be able to answer...

Page 42: Implementation of Table Structured References in ... · Worked on StarOffice from 1993 to 2000 for Star Division Worked on OpenOffice.org from 2000 to 2011 for Sun Microsystems and

42Table Structured References in Calc, Eike Rathke (erAck)

All text and image content in this document is licensed under the Creative Commons Attribution-Share Alike 3.0 License (unless otherwise specified). "LibreOffice" and "The Document Foundation" are registered trademarks. Their respective logos and icons are subject to international copyright laws. The use of these therefore is subject to the trademark policy.

Thank you …

… for using LibreOffice!… for supporting LibreOffice!… for hacking LibreOffice!