Giter Site home page Giter Site logo

Comments (5)

nyamatongwe avatar nyamatongwe commented on July 17, 2024

It would be unusual to write this code in that form as Python programmers will commonly indent continued statements. Lexilla lexers and folders concentrate on languages as they are commonly written.

from lexilla.

Davidy22 avatar Davidy22 commented on July 17, 2024

Oh, if we're just covering typical formatting and not all possible formatting then I guess this isn't an issue for either language.

from lexilla.

mpheath avatar mpheath commented on July 17, 2024

I see invalid code. Let's look into this.

bat file to create "output.log"
> output.log call :test 2>&1
exit /b

:test
py -0
type test1.py
py test1.py
type test2.py
py test2.py
type test3.py
py test3.py

On Linux, type is like cat and py is like python3, except py is a launcher.

"output.log" in the directory "C:\Test"
C:\Test> py -0 
Installed Pythons found by py Launcher for Windows *


 -3.8-64
C:\Test> type test1.py 
param2 = 1

if param2 <= 2:
    print((-20 %


3) / 5)
    else:
        print(1)

C:\Test> py test1.py 
  File "test1.py", line 8
    else:
    ^
SyntaxError: invalid syntax

C:\Test> type test2.py 
param2 = 1

if param2 <= 2:
    print((-20 % 3) / 5)
    else:
        print(1)

C:\Test> py test2.py 
  File "test2.py", line 5
    else:
    ^
SyntaxError: invalid syntax

C:\Test> type test3.py 
param2 = 1

if param2 <= 2:
    print((-20 %


3) / 5)
else:
    print(1)

C:\Test> py test3.py 
0.2

Only test3.py is valid syntax as the else is at the same indent level as the if.

I am curious to know which Python interpreter would allow test1.py:

param2 = 1

if param2 <= 2:
    print((-20 %


3) / 5)
    else:
        print(1)

or test2.py without continuation caused by the parentheses, as I expect the interpreter to read the previous code like:

param2 = 1

if param2 <= 2:
    print((-20 % 3) / 5)
    else:
        print(1)

to run without error.

test3.py runs OK

param2 = 1

if param2 <= 2:
    print((-20 %


3) / 5)
else:
    print(1)

and the code folding appears OK.

I added the param2 = 1 else any test would error.

Look how Github colours the else as it's lexing surprisingly knows whether the else is valid or not. Impressive lexing, or lucky by chance.

The indent before the else cannot be ignored just because the previous line is a continued line. It needs to match the indent before the if.

This is valid Python code:

def test():
    print(1 + 2)
    print(1 +
  2)
    print(1 +
              2)
    print('abc'
'def'
                    'ghi')
    print('\
abcdefghi')
    print('''The rules of indentation
does not apply to continuations as
they are resolved during parsing.
    print() for example, not this textual one, needs to be indented.''')

test()

Indenting requirements does not apply with a continued lines while the above shows indenting of 2, 4 or any other amount of spaces. It is valid as all of the print calls are indented 4 spaces.

@Davidy22, do you still consider the initial code as valid Python code?

from lexilla.

Davidy22 avatar Davidy22 commented on July 17, 2024

Oh, whoops, I copied it from a test I had in a file where this was inside a function, nuked the indentation before the first if so the else has an excess indentation. The contents of test3.py were the intention, and they still fold incorrectly: this is what it looks like on its own:

image

Note how the fold indicator on the side stops on line 17 instead of extending down to just before the else

from lexilla.

mpheath avatar mpheath commented on July 17, 2024

OK, please post the full reproducable code next time.

I see the same folding with SciTE.

Line 17 points to the start of the line instead of the end, which is line 20. The lexer would need to account for all continuation types and be able to interpret correctly to the end. The person who would implement this would deserve a rather large treat.

from lexilla.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.