Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

“折叠”的错误("folding" error) #332

Closed
lxgz12345 opened this issue May 16, 2021 · 15 comments
Closed

“折叠”的错误("folding" error) #332

lxgz12345 opened this issue May 16, 2021 · 15 comments

Comments

@lxgz12345
Copy link

我有个bat文件,在里面有一段代码是生成文件,它的“折叠”出现了错误
(I have a BAT file, in which there is a section of code is a generated file, its "folding" error)

图片和文件在下方
(Pictures and files are below)

1

NSudo.zip

@lifenjoiner
Copy link
Contributor

这是一个极为特殊的例子:异常部分是以特殊方式嵌入的且不符合bat语法的内容……
个人觉得很难搞,你有其它编辑器能正常处理的例子可以参考吗?

@zufuliu
Copy link
Owner

zufuliu commented May 17, 2021

I don't known how this can be fixed (batch file starts code to set the interrupter and ends with content for the interrupter), anothor example (from ActivePerl)

D:\Dev\Perl\bin\cpan.bat

@rem = '--*-Perl-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
:WinNT
perl -x -S %0 %*
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
#!perl
#line 15
    eval 'exec D:\Dev\Perl\bin\perl.exe -S $0 ${1+"$@"}'
	if $running_under_some_shell;
#!/usr/local/bin/perl

BEGIN { pop @INC if $INC[-1] eq '.' }
use strict;
use vars qw($VERSION);
...

@lifenjoiner
Copy link
Contributor

L297-L300 in the attachment:

for /F "tokens=1,3,4 delims=:" %%a in ("!inioff!") do (
set "inioff=%%~a"
set "base=%%~b"
set /A "size=%%~c" )

Seems 2 "issues" appeared to be improved:

  1. %%~a", %%~b" and %%~c" are colored with background. Extra: L330.
  2. ) in set /A "size=%%~c" ) is not recognized, comparing with other SETs. Example: L322.

Maybe they are all caused by %%~?

@lifenjoiner
Copy link
Contributor

Upstream patch has been committed.
For issue 2, SciTE recognizes the ) correctly without folding.

@zufuliu zufuliu added this to the v4.21.07 milestone May 19, 2021
@zufuliu
Copy link
Owner

zufuliu commented May 19, 2021

I need to find more documents before changing Batch lexer (it's different from the one at https://github.com/ScintillaOrg/lexilla)

@zufuliu
Copy link
Owner

zufuliu commented Jun 6, 2021

Notepa2-mod or other editors does not supports code folding for batch file, you can disable code folding by unchecking menu View -> Show Code Folding.

@zufuliu
Copy link
Owner

zufuliu commented Jun 17, 2021

I made some local fixes for LexBatch, NSudo.bat now looks good with the update lexer, but it seems a bit hard to fix all bugs:

  1. The variable highlighting bug for L297-L300 is fixed.
  2. Some Rebuilder.cab blocks are fixed by treating them as plain text, because the label :+res:b85:2176:Rebuilder.cab: is not reachable (+ after :), however, since : starts a line (line 1420) in :+res:b85:53013:NSudo_Installer_x64.cab: block, that line will be treated as Batch label (all characters on that line are valid label characters), so the normal Batch parsing resumed from the line.
  3. C-style backslash escape sequence is not implemented, which is required to fix line 217-220.
  4. I don't understand what line 302-326 is doing, some lines are cooled in wrong styles.

@zufuliu
Copy link
Owner

zufuliu commented Jun 20, 2021

Code folding and variable highlighting bugs fixed by 9a6cea8.

@lifenjoiner
Copy link
Contributor

Code folding and variable highlighting bugs fixed by 9a6cea8.

Good work!
Seems there are some minor improvements can be done, tested by

for /F "tokens=1,3,4 delims=:" %%a in ("!inioff!") do (
set "inioff=%%~a"
set "base=%%~b"
set /A "size=%%~c" )

The tailing " in line 2 is colored, while in line 3 it isn't.
bat-qp

@zufuliu
Copy link
Owner

zufuliu commented Jun 20, 2021

Maybe it's not a bug.

chcp 65001
for /?
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

    %~I         - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    %~pI        - expands %I to a path only
    %~nI        - expands %I to a file name only
    %~xI        - expands %I to a file extension only
    %~sI        - expanded path contains short names only
    %~aI        - expands %I to file attributes of file
    %~tI        - expands %I to date/time of file
    %~zI        - expands %I to size of file
    %~$PATH:I   - searches the directories listed in the PATH
                   environment variable and expands %I to the
                   fully qualified name of the first one found.
                   If the environment variable name is not
                   defined or the file is not found by the
                   search, then this modifier expands to the
                   empty string

The modifiers can be combined to get compound results:

    %~dpI       - expands %I to a drive letter and path only
    %~nxI       - expands %I to a file name and extension only
    %~fsI       - expands %I to a full path name with short names only
    %~dp$PATH:I - searches the directories listed in the PATH
                   environment variable for %I and expands to the
                   drive letter and path of the first one found.
    %~ftzaI     - expands %I to a DIR like output line

@lifenjoiner
Copy link
Contributor

%~aI - expands %I to file attributes of file

Yeah. tricky ...

@lifenjoiner
Copy link
Contributor

https://github.com/zufuliu/notepad2/blob/45ad427788fd7d1c8ec8a64d1c8a61a4a5706f83/scintilla/lexers/LexBatch.cxx#L125-L127
What about this?

while (IsTildeExpansion(sc.ch) && !(IsBatOp(sc.chNext, false) || IsBatSpec(sc.chNext) || sc.chNext == '.')) {

. can be a variable (line 302-326 you mentioned above), but it's rare, and it is not in most cases.

@zufuliu
Copy link
Owner

zufuliu commented Jun 20, 2021

%%~a is fixed by 3eed6c9.

@zufuliu
Copy link
Owner

zufuliu commented Jun 22, 2021

All bugs are fixed, feel free to test latest builds.

@zufuliu
Copy link
Owner

zufuliu commented Aug 21, 2024

Some changes were removed by recent a802549 and 01d55f3, feel free to test latest builds and check whether here are regressions (NStudio.bat looks good to me).

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants