Comments (5)
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.
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.
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.
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:
Note how the fold indicator on the side stops on line 17 instead of extending down to just before the else
from lexilla.
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)
- Request: UML language support
- Inconsistent lexing of '-' at line start by bash lexer HOT 8
- [Bash] two bugs in test operator highlighting HOT 6
- Fold Issue in Verilog mode HOT 17
- LexerVerilog tries to set line state beyond EOF HOT 2
- R escape sequences don't terminate properly HOT 13
- Syntax highlighting for Svelte HOT 1
- [CSS] Nesting and &-selector HOT 4
- Fold issue in verilog with nested MACRO and nested if HOT 3
- nested square brackets, TeX files
- Syntax colour highlighting of HTML with JSON context in JavaScript section HOT 7
- Shell language lexing mistakes bitwise left shift operator for here document HOT 3
- [Bash] Don't nest `${}` parameter expansion on `{` HOT 1
- unreachable code HOT 1
- Feature Request: Folding by indentation in plain text HOT 2
- Update Assembly (Update Syntax Highlighting)
- Batch Syntax "keyword" + ":" => "keyword:" dont work properly HOT 5
- raw formatted string is not handled in Python lexer HOT 5
- prevent negative code folding level in lexer HOT 26
- [Ruby] fix `number.method` highlighting
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lexilla.