Skip to content

Commit

Permalink
Add support for $sheet.A1 style sheet references unique to Libre
Browse files Browse the repository at this point in the history
Fixes #36
  • Loading branch information
axemonk committed Jan 25, 2025
1 parent 8b7ed41 commit 116829b
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 2 deletions.
43 changes: 41 additions & 2 deletions LibreOffice Calc Formula.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ contexts:
2: meta.function-call.arguments.libre punctuation.section.arguments.begin.libre
push: function-call-body

sheet-reference:

This comment has been minimized.

Copy link
@michaelblyons

michaelblyons Jan 26, 2025

Contributor

I think I'd match each of the styles separately and push to different contexts with the right matches. With what you have here, you'll match all the right stuff, but maybe more of the wrong stuff than you want.

This comment has been minimized.

Copy link
@michaelblyons

michaelblyons Jan 26, 2025

Contributor

You can make the quoted sheet name stuff (if relevant) its own context and include it in both the others.

- match: (?=\$?{{sheet}}[!\.])
push: sheet-reference-body

sheet-reference-body:
- meta_scope: meta.reference.sheet
- match: '[!\.]'
scope: punctuation.separator.sequence.sheet

This comment has been minimized.

Copy link
@michaelblyons

michaelblyons Jan 26, 2025

Contributor

Recommend the closing sub scope be libre to hint at where these rules came from. (I know this gets annoying for copy/paste between files.)

pop: 1
- match: \$
scope: punctuation.separator.sequence.libre

This comment has been minimized.

Copy link
@michaelblyons

michaelblyons Jan 26, 2025

Contributor

punctuation.definition.annotation.begin?

- match: \'
scope: punctuation.definition.annotation.begin.sheet
push:
- meta_content_scope: entity.name.struct.sheet
- match: \'\'
scope: constant.character.escape.sheet
- match: \'(?=[!\.])
scope: punctuation.definition.annotation.end.sheet
pop: 1
- match: '{{sheet}}'
scope: entity.name.struct.sheet
- include: immediately-pop

cell-or-range-reference:
- meta_append: true
- match: ({{rc}})(:)({{rc}})
Expand Down Expand Up @@ -71,8 +95,23 @@ variables:
# LibreOffice does not support tables
table: (?!.)

# # TODO: Update with LibreOffice alternate-format sheet references in addition.
# sheet: (?#WIP)
# TODO: Is there a cleaner more compact (and probably more efficient) way to
#(dupe) do this? `'` are only legal in excel sheet names when padded on
# either end with a legal character matched by [^:*/?\[\]\\],
# and said `'` must come in pairs.
# TODO: Update with LibreOffice alternate-format sheet references in addition.
sheet_delimited: |-
(?x:
(?:'[^:*/?\[\]\\]+('')*[^:*/?\[\]\\]+')|
(?:'[^:*/?\[\]\\]+')|
(?:\$'[^:*/?\[\]\\]+('')*[^:*/?\[\]\\]+')
)
sheet_normal: |-
(?x:
(?:[\w&&[^0-9]]\w*)|
(?:\$[^\.:*/?\[\]\\]+)
)
sheet: (?:{{sheet_delimited}}|{{sheet_normal}})

# RC row/column offset format
r_: |-
Expand Down
70 changes: 70 additions & 0 deletions tests/syntax_test_libre_references.localc.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
' SYNTAX TEST "Packages/Excel formula/LibreOffice Calc Formula.sublime-syntax"

'''[ SEMI-SHARED REFERENCES ]''''''''''''''''''''''''''''''''''''''''''''''''''

=C[2]

=R[4]
Expand All @@ -26,3 +28,71 @@
=RC[1]:R[1]C

=RC[1]:RC[2]

'''[ SHARED REFERENCES ]''''''''''''''''''''''''''''''''''''''''''''''''''

='John''sSheetDon''tTouch'!A1

='s''s'!N36
'^^^^^^^ meta.reference.sheet
'^ punctuation.definition.annotation.begin.sheet - entity
' ^^^^ entity.name.struct.sheet
' ^^ constant.character.escape.sheet
' ^ punctuation.definition.annotation.end.sheet - entity
' ^ punctuation.separator.sequence.sheet
' ^^^ meta.reference.cell.sheet storage.type.sheet

='s''''s'!N36
'^^^^^^^^^ meta.reference.sheet
'^ punctuation.definition.annotation.begin.sheet - entity
' ^^^^^^ entity.name.struct.sheet
' ^^^^ constant.character.escape.sheet
' ^ punctuation.definition.annotation.end.sheet - entity
' ^ punctuation.separator.sequence.sheet
' ^^^ meta.reference.cell.sheet storage.type.sheet

=한국어!L11
' <- keyword.operator.assignment
'^^^^^^^ meta.reference - meta meta
' ^ - meta.reference
'^^^ entity.name.struct
' ^ punctuation.separator.sequence
' ^^^ storage.type

=_hello_2world!N36
' <- keyword.operator.assignment
'^^^^^^^^^^^^^^^^^ meta.reference - meta meta
' ^ - meta.reference
'^^^^^^^^^^^^^ entity.name.struct
' ^ punctuation.separator.sequence - entity

='This''sASheetWithAnEscapedSingleQuote'!A1
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.reference.sheet - meta meta
'^ punctuation.definition.annotation.begin.sheet - entity
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entity.name.struct.sheet
' ^^ constant.character.escape.sheet
' ^ punctuation.definition.annotation.end.sheet - entity
' ^ punctuation.separator.sequence.sheet
' ^^ meta.reference.cell.sheet storage.type.sheet
' <- keyword.operator.assignment.sheet

=''''!A1
'^^^^^ meta.reference.sheet
'^ punctuation.definition.annotation.begin.sheet
' ^^ entity.name.struct.sheet constant.character.escape.sheet - punctuation
' ^ punctuation.definition.annotation.end.sheet
' ^ punctuation.separator.sequence.sheet
' ^^ meta.reference.cell.sheet storage.type.sheet
' <- keyword.operator.assignment.sheet

='^'!A1
'^^^^ meta.reference.sheet
'^ punctuation.definition.annotation.begin.sheet
' ^ entity.name.struct.sheet
' ^ punctuation.definition.annotation.end.sheet
' ^ punctuation.separator.sequence.sheet
' ^^ meta.reference.cell.sheet storage.type.sheet

'''[ LIBRE REFERENCES ]''''''''''''''''''''''''''''''''''''''''''''''''''

=$'John''sSheetDon''tTouch'.A1

0 comments on commit 116829b

Please sign in to comment.