From 116829b505aff99fd24560f622c97fcc132aab58 Mon Sep 17 00:00:00 2001 From: axemonk Date: Sat, 25 Jan 2025 15:24:44 -0600 Subject: [PATCH] Add support for `$sheet.A1` style sheet references unique to Libre Fixes #36 --- LibreOffice Calc Formula.sublime-syntax | 43 +++++++++++- tests/syntax_test_libre_references.localc.txt | 70 +++++++++++++++++++ 2 files changed, 111 insertions(+), 2 deletions(-) diff --git a/LibreOffice Calc Formula.sublime-syntax b/LibreOffice Calc Formula.sublime-syntax index 3229b06..d54ffdf 100644 --- a/LibreOffice Calc Formula.sublime-syntax +++ b/LibreOffice Calc Formula.sublime-syntax @@ -16,6 +16,30 @@ contexts: 2: meta.function-call.arguments.libre punctuation.section.arguments.begin.libre push: function-call-body + sheet-reference: + - match: (?=\$?{{sheet}}[!\.]) + push: sheet-reference-body + + sheet-reference-body: + - meta_scope: meta.reference.sheet + - match: '[!\.]' + scope: punctuation.separator.sequence.sheet + pop: 1 + - match: \$ + scope: punctuation.separator.sequence.libre + - 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}}) @@ -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_: |- diff --git a/tests/syntax_test_libre_references.localc.txt b/tests/syntax_test_libre_references.localc.txt index f53ee74..b5c36ae 100644 --- a/tests/syntax_test_libre_references.localc.txt +++ b/tests/syntax_test_libre_references.localc.txt @@ -1,5 +1,7 @@ ' SYNTAX TEST "Packages/Excel formula/LibreOffice Calc Formula.sublime-syntax" +'''[ SEMI-SHARED REFERENCES ]'''''''''''''''''''''''''''''''''''''''''''''''''' + =C[2] =R[4] @@ -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