You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(EDIT (1/9/2025): Repo contents have changed dramatically in structure since this report. For a more succinct version of the repo that the below still applies to, switch to tag 2.5.2)
Link to repository in question. Latest release contains the code depicted below, but is probably not yet in PackageControl at time of writing.
Some strange behavior @michaelblyons and I have run into regarding backreferences in sublime syntax definitions. First finding was that using \n to enumerate backreferences like ({{thing}})(\1) is compatible with the new regex engine (edit: at least according to syntax compatibility check through Sublime), but ({{thing}})(\k<1>) is not. So far so good. Just use \n . The catch here is that if any pattern in a context uses \n , the whole context becomes anonymous:
Relevant patterns shown below (links to actual repo code can be found below snippets). The second pattern in the dynamic-reference context is what gets the capture pictured above, but the first pattern contains a \n backreference, causing the whole context to become anonymous. This also applies when a \n backreference appears after the capturing pattern.
variables:
cell: (?:\$?[A-Za-z]+\$?\d+)
# Push to dynamic context to isolate forced anonymity to just dynamic refs
- match: (?=(?:@?{{cell}})(?:(?:#?:{{cell}}#)|(?:#:{{cell}}#?)))
push: dynamic-reference
dynamic-reference:
# Zero-dimensional cell range w/ dynamics
# Verified as sregex compatible with \n but not with \k<n>
# A1#:A1#
# A1:A1#
# @A1#:A1#
# @A1:A1#
- match: (@?)({{cell}})(#?)(:)(\2)(#)
captures:
1: keyword.operator.reference.excel
2: storage.type.excel
3: keyword.operator.reference.excel
4: punctuation.separator.sequence.excel
5: storage.type.excel
6: keyword.operator.reference.excel
set: maybe-union-operator
# Cell range with dynamics
# A1#:B2
# A1#:B2#
# @A1#:B2
# @A1#:B2#
- match: (@?)({{cell}})(#)(:)({{cell}})(#?)
captures:
1: keyword.operator.reference.excel
2: storage.type.excel
3: keyword.operator.reference.excel
4: punctuation.separator.sequence.excel
5: storage.type.excel
6: keyword.operator.reference.excel
set: maybe-union-operator
# Bail if nothing matches
- include: immediately-pop
If Package Control hasn't grabbed latest release, add Excel formula.sublime-syntax to User packages folder from repo (or do some LCL magic after cloning the repo, I'm a bit of a noob personally). Enable Excel formula syntax in blank file.
Type =A1#:A2# and =A1:A1# on new lines and use scope inspector to inspect scopes. Note how both have an anonymous context.
Open Excel formula.sublime-syntax and run syntax compatibility check. Note that the check reports all green.
Comment out just the code with the backrefenced pattern in the dynamic-reference context and compare scopes again. Note how =A1#:A2# scopes correctly with no anonymity.
Finally, uncomment backreferenced code and replace the backreference with \k<2> and compare scopes again. Note how both =A1#:A2# and =A1:A1# are scoped correctly with no anonymity. Then run syntax compatibility check. Note that check reports incompatibility.
Expected behavior
Either one of the following: \n should cause compatibility check to fail. \n should work as normal and not cause anonymity, assuming that it is actually supported.
Actual behavior
Both of the following \n passes compatibility check \n forces all scopes applied from a context to become anonymous when viewed through the scope inspector.
Sublime Text build number
4189
Operating system & version
Windows 11
(Linux) Desktop environment and/or window manager
No response
Additional information
No response
OpenGL context information
No response
The text was updated successfully, but these errors were encountered:
axemonk
changed the title
Syntax Dev - Backreferences show as supported, but make entire context anonymous
Syntax Dev - Backreferences show as supported but make entire context anonymous
Jan 3, 2025
Repo contents have changed dramatically in structure since this report. For a more succinct version of the repo that the above still applies to, switch to tag 2.5.2.
Description of the bug
(EDIT (1/9/2025): Repo contents have changed dramatically in structure since this report. For a more succinct version of the repo that the below still applies to, switch to tag 2.5.2)
Link to repository in question. Latest release contains the code depicted below, but is probably not yet in PackageControl at time of writing.Some strange behavior @michaelblyons and I have run into regarding backreferences in sublime syntax definitions. First finding was that using
\n
to enumerate backreferences like({{thing}})(\1)
is compatible with the new regex engine (edit: at least according to syntax compatibility check through Sublime), but({{thing}})(\k<1>)
is not. So far so good. Just use\n
. The catch here is that if any pattern in a context uses\n
, the whole context becomes anonymous:Relevant patterns shown below (links to actual repo code can be found below snippets). The second pattern in the
dynamic-reference
context is what gets the capture pictured above, but the first pattern contains a\n
backreference, causing the whole context to become anonymous. This also applies when a\n
backreference appears after the capturing pattern.Code links corresponding to the above (not showing as embedded for some reason, apologies):
https://github.com/axemonk/Excel-formula/blob/53ba9bb1f4d3e52088c1928b257e75a1e6224279/Excel%20formula.sublime-syntax#L19-L20
https://github.com/axemonk/Excel-formula/blob/53ba9bb1f4d3e52088c1928b257e75a1e6224279/Excel%20formula.sublime-syntax#L321-L323
https://github.com/axemonk/Excel-formula/blob/53ba9bb1f4d3e52088c1928b257e75a1e6224279/Excel%20formula.sublime-syntax#L407-L440
The job of the backrefenced pattern is to match strings like this:
https://github.com/axemonk/Excel-formula/blob/53ba9bb1f4d3e52088c1928b257e75a1e6224279/syntax_test_.Excel%20Examples.txt#L203-L209
Sublime showing
\n
as not unsupported:Sublime showing
\k<n>
as not supported:Steps to reproduce
Excel formula.sublime-syntax
to User packages folder from repo (or do some LCL magic after cloning the repo, I'm a bit of a noob personally). Enable Excel formula syntax in blank file.=A1#:A2#
and=A1:A1#
on new lines and use scope inspector to inspect scopes. Note how both have an anonymous context.Excel formula.sublime-syntax
and run syntax compatibility check. Note that the check reports all green.dynamic-reference
context and compare scopes again. Note how=A1#:A2#
scopes correctly with no anonymity.\k<2>
and compare scopes again. Note how both=A1#:A2#
and=A1:A1#
are scoped correctly with no anonymity. Then run syntax compatibility check. Note that check reports incompatibility.Expected behavior
Either one of the following:
\n
should cause compatibility check to fail.\n
should work as normal and not cause anonymity, assuming that it is actually supported.Actual behavior
Both of the following
\n
passes compatibility check\n
forces all scopes applied from a context to become anonymous when viewed through the scope inspector.Sublime Text build number
4189
Operating system & version
Windows 11
(Linux) Desktop environment and/or window manager
No response
Additional information
No response
OpenGL context information
No response
The text was updated successfully, but these errors were encountered: