You are here: PSPad forum > České diskuzní fórum > Zvýrazňování windows shell syntaxe

Zvýrazňování windows shell syntaxe

Goto Page: Previous1 2 3 4 5 6 7 8 9 10 11 ...LastNext

#11 Re: Kontrola poctu zavorek v batch souboru

Posted by: lazna | Date: 2014-09-06 11:56 | IP: IP Logged

Po delsi dobe jsem se k tomu zas dostal, stahl build 2500 a koukam ze zavorky stale haluzi:

if "%%b"=="" (echo.) else ()

uvedena konstrukce zvyrazni bere v uvahu pouze prvni zavorku, zbytek ignoruje.
Obecne by se ve Windows scriptech mely zavorky ignorovat pouze pokud jsou uvnitr dvojitych uvozovek (pak se povazuji za soucast stringu) nebo pokud jsou escapnuty striskou ^( ^)

Vyborne tematicke cteni zde:

----------------------------------------------

The BatchLineParser:

A line of code in a batch file has multiple phases (on the command line the expansion is different!).

The process starts with phase 1

Phase/order
1) Phase(Percent):
•A double %% is replaced by a single %
•Expansion of argument variables (%1, %2, etc.)
•Expansion of %var%, if var does not exists replace it with nothing
•For a complete explanation read this from dbenham Same thread: percent expansion

1.5) Remove all <CR> (CarriageReturn 0x0d) from the line

2) Phase(Special chars, " <LF> ^ & | < > ( ): Look at each character
•If it is a quote (") toggle the quote flag, if the quote flag is active, the following special characters are no longer special: ^ & | < > ( ).
•If it is a caret (^) the next character has no special meaning, the caret itself is removed, if the caret is the last character of the line, the next line is appended, the first charater of the next line is always handled as escaped charater. •<LF> stops the parsing immediatly, but not with a caret in front

•If it is one of the special characters & | < > split the line at this point, in case of the pipe (|) both parts gets a phase restart (a bit more complex ...) For more info on how pipes are parsed and processed, look at this question and answers: Why does delayed expansion fail when inside a piped block of code?
•In this phase the primary token list is build, token delimiters are <space> <tab> , ; = and <0xFF> (also known as non-breaking space)
•Process parenthesis (provides for compound statements across multiple lines): •If the parser is not looking for a command token, then ( is not special.
•If the parser is looking for a command token and finds (, then start a new compound statement and increment the parenthesis counter
•If the parenthesis counter is > 0 then ) terminates the compound statement and decrements the parenthesis counter.
•If the line end is reached and the parenthesis counter is > 0 then the next line will be appended to the compound statement (starts again with phase 1)
•If the parenthesis counter is = 0, and the parser is looking for a commmand, then ) and all remaining characters on line are ignored

•In this phase REM, IF and FOR are detected, for the special handling of them.
•If the first token is "rem", only two tokens are processed, important for the multiline caret

3) Phase(echo): If "echo is on" print the result of phase 1 and 2
•For-loop-blocks are echoed multiple times, first time in the context of the for-loop, with unexpanded for-loop-vars
•For each iteration, the block is echoed with expanded for-loop-vars

---- These two phases are not really follows directly, but it makes no difference
4) Phase(for-loop-vars expansion): Expansion of %%a and so on

5) Phase(Exclamation mark): Only if delayed expansion is on, look at each character
•If it is a caret (^) the next character has no special meaning, the caret itself is removed
•If it is an exclamation mark, search for the next exclamation mark (carets are not observed anymore), expand to the content of the variable •Consecutive opening ! are collapsed into a single !
•Any remaining ! that cannot be paired is removed

•If no exclamation mark is found in this phase, the result is discarded, the result of phase 4 is used instead (important for the carets)
•Important: At this phase quotes and other specical characters are ignored
•Expanding vars at this stage is "safe", because special characters are not detected anymore (even <CR> or <LF>)

6) Phase(call/caret doubling): Only if the cmd token is CALL
•If the first token is "call", start with phase 1 again, but stops after phase 2, delayed expansion are not processed a second time here
•Remove the first CALL, so multiple CALL's can be stacked
•Double all carets (the normal carets seems to be stay unchanged, because in phase 2 they are reduced to one, but in quotes they are effectivly doubled)

7) Phase(Execute): The command is executed
•Different tokens are used here, depends on the internal command executed
•In case of a set "name=content", the complete content of the first equal sign to the last quote of the line is used as content-token, if there is no quote after the equal sign, the rest of the line is used.

Zdroj: stackoverflow.com

Options: Reply | Quote | Up ^


#12 Re: Kontrola poctu zavorek v batch souboru

Posted by: pspad | Date: 2014-09-06 13:44 | IP: IP Logged

To, co jste mi poslal (nebo nekdo jiny) minule jsem opravil, tohle je zase trosku jiny pripad. Takze opravim tento a prosim o poradne otestovani a poslani vsech pripadu, kdy to zlobi

Options: Reply | Quote | Up ^


#13 Re: Kontrola poctu zavorek v batch souboru

Posted by: lazna | Date: 2014-09-06 18:22 | IP: IP Logged

Myslim ze v principu jde porad o to, ze za ne vsechno co na radku nasleduje za prikazem echo je string urceny k vypsani na konzoli. Jedine snad pokud jsou hned za prikazem echo dvojite uvozovky, tak vse do dalsich dvojitych uvozovek je (snad) brano jako string. Nejsem batch expert, proto jsem poslal ten text od skutecneho experta, jedina, mnoha experimenty podlozena, analyza toho jak cmd.exe parsuje scripty kterou jsem za 10 let co se tim zabyvam na webu nasel.

Rad Vam budu napomocen, pokud to pomuze zvyraznovac shell scriptu opravit. Pspad k jejich editaci rad pouzivam.

L.

Options: Reply | Quote | Up ^


#14 Re: Kontrola poctu zavorek v batch souboru

Posted by: pspad | Date: 2014-09-06 19:28 | IP: IP Logged

Tento případ už mám také opravený. Pokud by bylo něco jiného mimo ECHO a před tím to bylo tuším &&, tak mi pošlete opět příklad kódu

Options: Reply | Quote | Up ^


#15 Re: Kontrola poctu zavorek v batch souboru

Posted by: lazna | Date: 2015-05-06 11:06 | IP: IP Logged

echo === sometext ===>> %bindir%\output.txt
Vse co je za redirectem '>>' je zvyrazneno take jakou soucast echovaneho textu (4.5.9 2600)

Echovany text na radku konci vzdy pokud narazi na nektery ze znaku '&,|,<,>,(,)'

Options: Reply | Quote | Up ^


#16 Re: Kontrola poctu zavorek v batch souboru

Posted by: lazna | Date: 2015-05-07 11:36 | IP: IP Logged

Tato konstrukce sparuje prvni zavorku se treti, i kdyz je escapnuta striskou a je to tedy jen znak jako kterykoliv jiny.

if not defined variable (
echo No device^(s^) found. EXITING....
)

Options: Reply | Quote | Up ^


#17 Re: Kontrola poctu zavorek v batch souboru

Posted by: pspad | Date: 2015-05-19 05:52 | IP: IP Logged

I hope both cases are fixed. Available in the next build

Options: Reply | Quote | Up ^


#18 Re: Kontrola poctu zavorek v batch souboru

Posted by: lazna | Date: 2015-05-20 10:22 | IP: IP Logged

Promenne se nezvyraznuji pokud jsou soucasti retezce uzavreneho ve dvojitych uvozovkach, ovsem evaluuji se i tam takze by mely byt zvyrazneny. Nezvyraznuji se dokonce ani kdyz je pred nimi jen jedna dvojita uvozovka.

L.

BTW: Navrhuji tento thread prejmenovat na: "Zvýrazňování windows shell syntaxe" nebo tak neco

Options: Reply | Quote | Up ^


#19 Re: Kontrola poctu zavorek v batch souboru

Posted by: pspad | Date: 2015-05-20 10:56 | IP: IP Logged

Potřebuju příklady. Tak hluboko do "davkovani" jsem nepronikl

Thread prejmenuju

Options: Reply | Quote | Up ^


#20 Re: Kontrola poctu zavorek v batch souboru

Posted by: lazna | Date: 2015-05-21 12:41 | IP: IP Logged

Myslim ze jsem to popsal jasne, ale budiz: V tomto prikladu se nezvyrazni promenne dokud neostranim uvozovky (respektive tu prvni, vypada to ze vse co je za prvni uvozovkou se bere jako string, tedy dokud to nenajde uzaviraci. Za druhou uvozovkou uz to totiz zase funguje)

wget.exe "http://%login%:%passwd%@%host%"

Procentove promenne se ve win shellu evaluuji vsude, nemuzu si vzpomenout na situaci kde by se tak nedelo.

Options: Reply | Quote | Up ^


Goto Page: Previous1 2 3 4 5 6 7 8 9 10 11 ...LastNext





Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR