-
Notifications
You must be signed in to change notification settings - Fork 1.3k
'main': Highlight pipes inside array assignments as errors #651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
danielshahaf
wants to merge
1
commit into
zsh-users:master
from
danielshahaf:array-assignment-cmdsep
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env zsh | ||
# ------------------------------------------------------------------------------------------------- | ||
# Copyright (c) 2019 zsh-syntax-highlighting contributors | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without modification, are permitted | ||
# provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
# and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright notice, this list of | ||
# conditions and the following disclaimer in the documentation and/or other materials provided | ||
# with the distribution. | ||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors | ||
# may be used to endorse or promote products derived from this software without specific prior | ||
# written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR | ||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# ------------------------------------------------------------------------------------------------- | ||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- | ||
# vim: ft=zsh sw=2 ts=2 et | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
BUFFER=$'a=( foo | bar )' | ||
|
||
expected_region_highlight=( | ||
'1 3 assign' # a=( | ||
'5 7 default' # foo | ||
'9 9 unknown-token' # | | ||
'11 13 unknown-token' # bar | ||
'15 15 unknown-token' # ) | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env zsh | ||
# ------------------------------------------------------------------------------------------------- | ||
# Copyright (c) 2019 zsh-syntax-highlighting contributors | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without modification, are permitted | ||
# provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
# and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright notice, this list of | ||
# conditions and the following disclaimer in the documentation and/or other materials provided | ||
# with the distribution. | ||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors | ||
# may be used to endorse or promote products derived from this software without specific prior | ||
# written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR | ||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# ------------------------------------------------------------------------------------------------- | ||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- | ||
# vim: ft=zsh sw=2 ts=2 et | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
BUFFER=$'a=( foo ; bar )' | ||
|
||
expected_region_highlight=( | ||
'1 3 assign' # a=( | ||
'5 7 default' # foo | ||
'9 9 unknown-token' # ; | ||
'11 13 default' # bar | ||
'15 15 assign' # ) | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env zsh | ||
# ------------------------------------------------------------------------------------------------- | ||
# Copyright (c) 2019 zsh-syntax-highlighting contributors | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without modification, are permitted | ||
# provided that the following conditions are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright notice, this list of conditions | ||
# and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright notice, this list of | ||
# conditions and the following disclaimer in the documentation and/or other materials provided | ||
# with the distribution. | ||
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors | ||
# may be used to endorse or promote products derived from this software without specific prior | ||
# written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR | ||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# ------------------------------------------------------------------------------------------------- | ||
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- | ||
# vim: ft=zsh sw=2 ts=2 et | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
BUFFER=$'a=( foo \n bar )' | ||
|
||
expected_region_highlight=( | ||
'1 3 assign' # a=( | ||
'5 7 default' # foo | ||
'9 9 default' # \n | ||
'11 13 default' # bar | ||
'15 15 assign' # ) | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of pushing the logic into each case where z-sy-h needs to distinguish between
;
and\n
; perhaps it'd be better to assignarg=$'\n'
as appropriate when updating proc_buf. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this (passes tests, but should probably be more thoroughly reviewed. (Has the side effect of more correctly handling
histchars=$'!^\n'
if one is so insane. Although it seems to mishandlealias $'\n'=...
,)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed in principle. I didn't write it this way because I figured YAGNI: at the time there was only one instance, so the factoring out could be deferred until needed.
I don't object to DTRTing from day one but I haven't reviewed all uses of
';'
in the code to assess destabilizingness of that. Can do that later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There aren't any literal uses of
';'
, so we're clear on that front.I adapted your diff onto the current branch as follows:
However, it fails one of the new tests:
I haven't been able to reproduce this failure. If I run
zsh -f
, source z-sy-h, enable function tracing, and type ina=(foo <Shift+Enter> bar)
, the tracing doesn't showunknown-token-XXX
anywhere. Hints?(I added the XXX for debugging purposes, to demonstrate where exactly the style setting that fails the test comes from. The XXX won't be committed.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented and pushed to master:
e58e452 tests: Add some tests for unusual or invalid elements in array assignments:
a4525a0 'main': Add infrastructure for treating literal newlines differently to semicolons.
3ca93f8 'main': Highlight literal semicolons in array assignments as errors.
bfd44f5 noop: Add comments.
81267ca 'main': Highlight pipes inside array assignments as errors
498cc76 tests: Extend and document the after-a-parse-error aspects of the issue #651 test.
c5878ae changelog: Update through HEAD.
The second commit implements a variant of your suggestion. (At that point,
${proc_buf[1]}
is the intertoken whitespace.)I didn't test the
alias $'\n'=
andhistchars=$'!^\n'
cases.