PowerShell parenthesis matching



  • This was started in the Notepad++ v7.9.2 Released thread, but since the problem occurs in other versions, I have spawned a new discussion to address @magoo104’s problem.

    @magoo104 said in Notepad++ v7.9.2 Released:

    The following valid PowerShell statement doesn’t correctly match the parentheses. It can also mess up other valid bracket matching, but I haven’t figured out the right pattern yet.

    “$($s.replace(”’","’’"))"

    $s can be any valid string, with or without imbedded single quotes.

    The same thing happens for me on v7.9.1 (ie, previous version):
    c4c6f5c8-dbf7-47a1-8485-d263cb940e92-image.png
    cursor is on the first (, and it doesn’t match the end, and the Search > Goto Matching Brace isn’t even available:
    67ca2538-e4fc-4787-9d6a-e64f247f0663-image.png
    Whereas on the second line, it works just fine:
    61c55076-3199-4077-86ed-18b964aacc6e-image.png

    My guess is that the problem is with the underlying PowerShell lexer, which is technically part of the Scintilla project. To prove whether it’s a problem with the lexer or not, one needs to determine if the behavior is the same in both Notepad++ and SciTE (the Scintilla-testbed editor). If it works in the most recent SciTE, one would need to check an older SciTE v4.2.0 (which matches the version of Scintilla that Notepad++ currently uses). If it works in SciTE v4.2.0, then it’s something specific to Notepad++ and you’ll need to create an issue with Notepad++; if it doesn’t work in SciTE v4.2.0, then the bug is in Scintilla, and it needs to be fixed and released there before it can be incorporated into Notepad++.



  • @magoo104 ,

    BTW: Here is the ? > Debug Info from the version where I confirmed the same issue…

    Notepad++ v7.9.1   (64-bit)
    Build time : Nov  2 2020 - 01:07:46
    Path : C:\usr\local\apps\notepad++\notepad++.exe
    Admin mode : OFF
    Local Conf mode : ON
    OS Name : Windows 10 Enterprise (64-bit) 
    OS Version : 1903
    OS Build : 18362.1256
    Current ANSI codepage : 1252
    Plugins : ComparePlugin.dll ExtSettings.dll HexEditor.dll LuaScript.dll MarkdownViewerPlusPlus.dll mimeTools.dll NppConsole.dll NppConverter.dll NppEditorConfig.dll NppExec.dll NppExport.dll NppFTP.dll NppUISpy.dll PreviewHTML.dll PythonScript.dll QuickText.dll RestApiToText.dll TagLEET.dll XMLTools.dll 
    


  • @magoo104 ,

    I had a copy of SciTE 4.2.0.

    After editing the SciTEUser.properties (by running SciTE, then Options > Open User Options File, pasting the following, and saving…

    # To keep menus short, these .properties files are not loaded by default.
    imports.exclude=abaqus asl asn1 au3 ave avs baan blitzbasic bullant \
    cil cmake coffeescript csound dataflex ecl eiffel erlang escript \
    flagship forth freebasic \
    gap haskell hex inno kix latex lot lout \
    markdown maxima metapost mmixal modula3 nim nimrod nncrontab nsis \
    opal oscript pov powerpro ps purebasic r rebol rust \
    scriptol smalltalk sorcins spice specman \
    tacl tal txt2tags verilog vhdl visualprolog
    
    # Import all the language specific properties files in this directory
    import *
    

    When I reloaded SciTE, I could see PowerShell in the Language list.

    When I load the file powershell.ps1 which contains

    $($s.replace(”’","’’"))
    ( ( )  )
    

    The SciTE brace-matching (^E = Ctrl+E = Edit > Match Brace) works on the second line, but not on the first line.

    SciTE
    Version 4.2.0 
        Jul  5 2019 08:28:50
    by Neil Hodgson.
    December 1998-July 2019.
    http://www.scintilla.org
    Lua scripting language by TeCGraf, PUC-Rio
        http://www.lua.org
    Contributors:
        Atsuo Ishimoto
        Mark Hammond
        Francois Le Coguiec
        Dale Nagata
        Ralf Reinhardt
        Philippe Lhoste
        Andrew McKinlay
        Stephan R. A. Deibel
        Hans Eckardt
        Vassili Bourdo
        Maksim Lin
        Robin Dunn
        John Ehresman
        Steffen Goeldner
        Deepak S.
        DevelopMentor http://www.develop.com
        Yann Gaillard
        Aubin Paul
        Jason Diamond
        Ahmad Baitalmal
        Paul Winwood
        Maxim Baranov
        Ragnar Højland
        Christian Obrecht
        Andreas Neukoetter
        Adam Gates
        Steve Lhomme
        Ferdinand Prantl
        Jan Dries
        Markus Gritsch
        Tahir Karaca
        Ahmad Zawawi
        Laurent le Tynevez
        Walter Braeu
        Ashley Cambrell
        Garrett Serack
        Holger Schmidt
        ActiveState http://www.activestate.com
        James Larcombe
        Alexey Yutkin
        Jan Hercek
        Richard Pecl
        Edward K. Ream
        Valery Kondakoff
        Smári McCarthy
        Clemens Wyss
        Simon Steele
        Serge A. Baranov
        Xavier Nodet
        Willy Devaux
        David Clain
        Brendon Yenson
        Philipp
        Vamsi Potluru http://www.baanboard.com
        Praveen Ambekar
        Alan Knowles
        Kengo Jinno
        Valentin Valchev
        Marcos E. Wurzius
        Martin Alderson
        Robert Gustavsson
        José Fonseca
        Holger Kiemes
        Francis Irving
        Scott Kirkwood
        Brian Quinlan
        Ubi
        Michael R. Duerig
        Deepak T
        Don Paul Beletsky
        Gerhard Kalab
        Olivier Dagenais
        Josh Wingstrom
        Bruce Dodson
        Sergey Koshcheyev
        Chuan-jian Shen
        Shane Caraveo
        Alexander Scripnik
        Ryan Christianson
        Martin Steffensen
        Jakub Vrána
        The Black Horus
        Bernd Kreuss
        Thomas Lauer
        Mike Lansdaal
        Yukihiro Nakai
        Jochen Tucht
        Greg Smith
        Steve Schoettler
        Mauritius Thinnes
        Darren Schroeder
        Pedro Guerreiro
        Steven te Brinke
        Dan Petitt
        Biswapesh Chattopadhyay
        Kein-Hong Man
        Patrizio Bekerle
        Nigel Hathaway
        Hrishikesh Desai
        Sergey Puljajev
        Mathias Rauen
        Angelo Mandato http://www.spaceblue.com
        Denis Sureau
        Kaspar Schiess
        Christoph Hösler
        João Paulo F Farias
        Ron Schofield
        Stefan Wosnik
        Marius Gheorghe
        Naba Kumar
        Sean O'Dell
        Stefanos Togoulidis
        Hans Hagen
        Jim Cape
        Roland Walter
        Brian Mosher
        Nicholas Nemtsev
        Roy Wood
        Peter-Henry Mander
        Robert Boucher
        Christoph Dalitz
        April White
        S. Umar
        Trent Mick
        Filip Yaghob
        Avi Yegudin
        Vivi Orunitia
        Manfred Becker
        Dimitris Keletsekis
        Yuiga
        Davide Scola
        Jason Boggs
        Reinhold Niesner
        Jos van der Zande
        Pescuma
        Pavol Bosik
        Johannes Schmid
        Blair McGlashan
        Mikael Hultgren
        Florian Balmer
        Hadar Raz
        Herr Pfarrer
        Ben Key
        Gene Barry
        Niki Spahiev
        Carsten Sperber
        Phil Reid
        Iago Rubio
        Régis Vaquette
        Massimo Corà
        Elias Pschernig
        Chris Jones
        Josiah Reynolds
        Robert Roessler rftp.com http://www.rftp.com
        Steve Donovan
        Jan Martin Pettersen
        Sergey Philippov
        Borujoa
        Michael Owens
        Franck Marcia
        Massimo Maria Ghisalberti
        Frank Wunderlich
        Josepmaria Roca
        Tobias Engvall
        Suzumizaki Kimitaka
        Michael Cartmell
        Pascal Hurni
        Andre
        Randy Butler
        Georg Ritter
        Michael Goffioul
        Ben Harper
        Adam Strzelecki
        Kamen Stanev
        Steve Menard
        Oliver Yeoh
        Eric Promislow
        Joseph Galbraith
        Jeffrey Ren
        Armel Asselin
        Jim Pattee
        Friedrich Vedder
        Sebastian Pipping
        Andre Arpin
        Stanislav Maslovski
        Martin Stone
        Fabien Proriol
        mimir
        Nicola Civran
        Snow
        Mitchell Foral
        Pieter Holtzhausen
        Waldemar Augustyn
        Jason Haslam
        Sebastian Steinlechner
        Chris Rickard
        Rob McMullen
        Stefan Schwendeler
        Cristian Adam
        Nicolas Chachereau
        Istvan Szollosi
        Xie Renhui
        Enrico Tröger
        Todd Whiteman
        Yuval Papish
        instanton
        Sergio Lucato
        VladVRO
        Dmitry Maslov
        chupakabra
        Juan Carlos Arevalo Baeza
        Nick Treleaven
        Stephen Stagg
        Jean-Paul Iribarren
        Tim Gerundt
        Sam Harwell
        Boris
        Jason Oster
        Gertjan Kloosterman
        alexbodn
        Sergiu Dotenco
        Anders Karlsson
        ozlooper
        Marko Njezic
        Eugen Bitter
        Christoph Baumann
        Christopher Bean
        Sergey Kishchenko
        Kai Liu
        Andreas Rumpf
        James Moffatt
        Yuzhou Xin
        Nic Jansma
        Evan Jones
        Mike Lischke
        Eric Kidd
        maXmo
        David Severwright
        Jon Strait
        Oliver Kiddle
        Etienne Girondel
        Haimag Ren
        Andrey Moskalyov
        Xavi
        Toby Inkster
        Eric Forgeot
        Colomban Wendling
        Neo
        Jordan Russell
        Farshid Lashkari
        Sam Rawlins
        Michael Mullin
        Carlos SS
        vim
        Martial Demolins
        Tino Weinkauf
        Jérôme Laforge
        Udo Lechner
        Marco Falda
        Dariusz Knociński
        Ben Fisher
        Don Gobin
        John Yeung
        Adobe
        Elizabeth A. Irizarry
        Mike Schroeder
        Morten MacFly
        Jaime Gimeno
        Thomas Linder Puls
        Artyom Zuikov
        Gerrit
        Occam's Razor
        Ben Bluemel
        David Wolfendale
        Chris Angelico
        Marat Dukhan
        Stefan Weil
        Rex Conn
        Ross McKay
        Bruno Barbieri
        Gordon Smith
        dimitar
        Sébastien Granjoux
        zeniko
        James Ribe
        Markus Nißl
        Martin Panter
        Mark Yen
        Philippe Elsass
        Dimitar Zhekov
        Fan Yang
        Denis Shelomovskij
        darmar
        John Vella
        Chinh Nguyen
        Sakshi Verma
        Joel B. Mohler
        Isiledhel
        Vidya Wasi
        G. Hu
        Byron Hawkins
        Alpha
        John Donoghue
        kudah
        Igor Shaula
        Pavel Bulochkin
        Yosef Or Boczko
        Brian Griffin
        Özgür Emir
        Neomi
        OmegaPhil
        SiegeLord
        Erik
        TJF
        Mark Robinson
        Thomas Martitz
        felix
        Christian Walther
        Ebben
        Robert Gieseke
        Mike M
        nkmathew
        Andreas Tscharner
        Lee Wilmott
        johnsonj
        Vicente
        Nick Gravgaard
        Ian Goldby
        Holger Stenger
        danselmi
        Mat Berchtold
        Michael Staszewski
        Baurzhan Muftakhidinov
        Erik Angelin
        Yusuf Ramazan Karagöz
        Markus Heidelberg
        Joe Mueller
        Mika Attila
        JoMazM
        Markus Moser
        Stefan Küng
        Jiří Techet
        Jonathan Hunt
        Serg Stetsuk
        Jordan Jueckstock
        Yury Dubinsky
        Sam Hocevar
        Luyomi
        Matt Gilarde
        Mark C
        Johannes Sasongko
        fstirlitz
        Robin Haberkorn
        Pavel Sountsov
        Dirk Lorenzen
        Kasper B. Graversen
        Chris Mayo
        Van de Bugger
        Tse Kit Yam
        SmartShare Systems https://www.smartsharesystems.com/
        Morten Brørup
        Alexey Denisov
        Justin Dailey
        oirfeodent
        A-R-C-A
        Roberto Rossi
        Kenny Liu
        Iain Clarke
        desto
        John Flatness
        Thorsten Kani
        Bernhard M. Wiedemann
        Baldur Karlsson
        Martin Kleusberg
        Jannick
        Zufu Liu
        Simon Sobisch
        Georger Araújo
        Tobias Kühne
        Dimitar Radev
        Liang Bai
        Gunter Königsmann
        Nicholai Benalal
        Uniface
        Raghda Morsy
        Giuseppe Corbelli
        Andreas Rönnquist
        Henrik Hank
        Luke Rasmussen
        maboroshin
        Gokul Krishnan
        John Horigan
        jj5
        Jad Altahan
        Andrea Ricchi
        Juarez Rudsatz
        Wil van Antwerpen
        Hodong Kim
    


  • @PeterJones said in PowerShell parenthesis matching:

    The SciTE brace-matching (^E = Ctrl+E = Edit > Match Brace) works on the second line, but not on the first line.

    However, more examples show: if I use real quotes rather than smart quotes:

    $($s.replace(”’","’’"))
    ( ( )  )
    $($s.replace("'","'"))
    

    The third line, which has true ASCII " and ', the brace matching works fine in SciTE 4.2.0.

    In Notepad++, if I leave that first line there, but add the third, it still thinks it is inside a string, which confuses things. But if I remove the first line and just have

    ( ( )  )
    $($s.replace("'","'"))
    

    … then Notepad++ brace-matching with Ctrl+B works for me.

    @magoo104 , could you paste in some actual PowerShell syntax that shows the problem – once you paste it in the forum, highlight the text and click the </> button in the forum entry toolbar,

    so that your PowerShell will be properly in a black box, and the Forum won’t try to “fix” your " " to “ ” or similar smart-quotes.

    And I did confirm: in v7.9.2, with the most recent text shown, it properly highlights matching braces, as shown in this screenshot
    08e8ec17-3a95-4497-b48e-adbf7a464f00-image.png
    … and Ctrl+B works correctly as well.

    So it was only with mismatched quotes and “smart quotes” that the problem occurs for me. With balanced ASCII quotes, it works just fine.


Log in to reply