String-Commands * TXT-Command

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > TXT. Text-File Engine >

String-Commands * TXT-Command

TXT.-Commands-Sample Code

Previous Top Next


MiniRobotLanguage (MRL)

Indentation Checker for Python Code

This Script is a Indentation Checker for Python Scripts

 

 

Intention

 

As PYTHON uses a "Block Indentation Syntax", which even checks if you use TAB's or SPACES,

its very easy to make indentation errors.

And depending on the type of Editor you will not even see then because TABs and Spaces are both generally invisible.

Going through a thousands of code lines checking the indentation manually is also not a good solution.

Why not let it the SPR do?

Due to its very easy block-Syntax he does not have this kind of problems, and when compiled he is as fast as Python Code or even faster.

Using the SPR and its PlugIn we can realize a Indentation Checker for Python Scripts quickly.

The Code below is an example for that.

After changing its structure from FEL. to the new TXT.-Commands, it got a speedup fo ten times!

Currently it takes just about 1 second for checking 1000 Lines of Code.

 

 

'#EXE:?path\

'#SPI:ForceWrite

'#ICS:39

NEM.

  'GTO.enx 

  VAR.$$INF=?path\V2.py

ELS.

  VAR.$$INF=$cmdexe$

EIF.

VAR.$$TIA=#time#

 

VAR.$$OUF=?exeloc\Backup.py

DEL.$$OUF

NEF.$$INF

  VAR.$$INF=?exeloc\Library.py

EIF.

NEF.$$INF

  MBX.Can not open: $$INF

  GTO.enx  

EIF.

PRT.Lib-Checker started: $now$

PRT.--------------------------

VAR.$$DEF=def$sp$

VAR.$$SP3=$sp$$sp$$sp$

VAR.$$TAB=$tab$

VAR.$$DEE=$crlf$

VAR.$$DEL=$tab$$sp$

VAR.$$LFF=$lf$

VAR.$$CRC=$cr$

VAR.$$CRL=$crlf$

' Read File

TXT.Load_Textfile|$$INF|$$ANZ

TXT.Save|$$OUF

VAR.$$IDL=0

VAR.$$ADL=0

VAN.$$BLM=0

FOR.$$CNT|1|$$ANZ

  TXT.get_line|$$CNT|$$LIN

  GSB.CheckLine

NEX.

TXT.Save

CAL.$$TIB=(#time#-$$TIA)|i

MBX.Ready in $$TIB Seconds.

:enx

ENR.

'===========================================================

' Check for:

' $$IDL = Ident-Level (Anzahl nötiger Spaces)

' NoSPaces links und rechts

' $$LIN - Original

' $$LIA - nur links getrimmt

' $$LIB - nur rechte Seite getrimmt

' $$LIX - Korrigiert

:CheckLine

GSB.GenLIV

 

GSB.CheckBlockComments

 

' Blockkommentare alles überlaufen

CAL.$$BLO=$$BLM+$$BLN

IVV.$$BLO>0

  VAR.$$LIX=$$LIB

  GTO.comment   

EIF.

 

 

' Leerzeile

LEN.$$LIA|$$LEA

IVV.$$LEA=0

  VAR.$$LIX=

  GTO.enl

EIF.

 

' Prüfe Kommentare

GSS.1|1|$$LIC|$$LAS

IVS.$$LAS=#

  $$LIX=$$LIC 

  GTO.comment

EIF.

 

' Vorprüfungen

GSB.CheckIMaxdentLevelChange

GSB.CountIdentofLine

GSB.CheckIdentofLine

 

:enl

IVS.$$LIB!$$LIX

  PRT.Changes in Line: $$CNT

  PRT.($$BLM)-($$IDL)<-$$LIX

EIF.

:comment

VAR.$$IDL=$$ADL

TXT.set_line_to|$$LOP|$$LIX

RET.

 

'-----------------------------------------------------------

:CheckIdentofLine

 

RET.

'-----------------------------------------------------------

:CountIdentofLine

VAR.$$SPA=0

VAR.$$TAA=0

VAR.$$FNI=

VAR.$$LOA=0

FOR.$$LOA|1|$$LEB

  GSS.$$LOA|$$LOA|$$LIB|$$LAS

' Wurde Leerzeichen gefunden?

  IVS.$$LAS=$tab$

    VIC.$$TAA

  ELS.   

    IVS.$$LAS=$sp$

      VIC.$$SPA

    ELS.

      GTO.others  

    EIF.

  EIF.  

NEX.

:others

JIV.$$LOP=1|NoIdent

IVV.$$SPA>0

  IVV.$$TAA>0

    PRT.Ident in Line $$CNT is wrong (Tabs and Spaces) please check it.       

    VAR.$$TAN=$$TAA   

  ELS.

    CAL.$$TAN=$$SPA/4

  EIF. 

  GSB.GenwithTabs

ELS.

  IVV.$$TAA>0

    IVV.$$TAA>$$IDL

      PRT.Possible Ident-Error in Line $$CNT (too much idented)?

      VAR.$$TAN=$$IDL       

    ELS.

      VAR.$$TAN=$$TAA

      VAR.$$IDL=$$TAA

    EIF.

    GSB.GenwithTabs

  ELS.

    GTO.NoIdent

  EIF.

EIF.

RET.

'-----------------------------------------------------------

:NoIdent

VAR.$$LIX=$$LIA

VAR.$$IDL=0

RET.

'-----------------------------------------------------------

' Erzeuge Indent mit Tabs

:GenwithTabs

STR.CLONE|$$FID|$$TAN|$$TAB

VAR.$$LIX=$$FID$$LIA

RET.

'-----------------------------------------------------------

:CheckIMaxdentLevelChange

GSS.-1|-1|$$LIA|$$LAS

IVS.$$LAS=:

  VIC.$$ADL   

EIF.

GSS.1|4|$$LIA|$$LAS

IVS.$$LAS=$$DEF

  $$IDL=0

EIF.

RET.

'-----------------------------------------------------------

:CheckBlockComments

GSS.1|3|$$LIC|$$LAS

' Blockkommentare

IVS.$$LAS="""

  CAL.$$BLM=1-$$BLM

ELS.

  IVS.$$LAS='''

    CAL.$$BLM=1-$$BLM

  EIF.     

EIF.

IVS.$$LIC=#region INFO

  VAN.$$BLN=0

ELS.

  IVS.$$LIC=#endregion

    IVV.$$BLN=1

      VAN.$$BLN=0        

    EIF.

  EIF.   

EIF.

RET.

'-----------------------------------------------------------

:GenLIV

VAR.$$LIB=$$LIN

VRT.$$LIB|$$DEL

VAR.$$LIC=$$LIN

VBT.$$LIC

VAR.$$LIA=$$LIB

VLT.$$LIA|$$DEL

LEN.$$LIB|$$LEB

RET.

 

 

 

 

Code Explanation

 

 

 

 

 

Example

 

'

 

'-----------------------------------------------------------

END.

 

 

 

 

 

Remarks

 

-

 

 

Limitations:-

-

 

 

See also:

 

  TXT.Load Textfile

  TXT.Clear

  TXT.From_Var

  TXT.Load_pure_Text

  TXT.Get_pure_Text

  FIL.Generate numbered Name

  FIL.Move numbered File