8000 Allow newlines inside argument and parameter lists · geddski/python@793b7a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 793b7a0

Browse files
committed
Allow newlines inside argument and parameter lists
FIX: Fix a bug that caused newlines to be disallowed in argument and parameter lists. Issue codemirror/dev#536
1 parent 8ed0598 commit 793b7a0

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/python.grammar

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ Decorator { At dottedName ArgList? newline }
2222

2323
FunctionDefinition {
2424
kw<"async">? kw<"def"> VariableName
25-
ParamList { "(" commaSep<param>? ")" }
25+
ParamList
2626
TypeDef { "->" test }?
2727
Body
2828
}
2929

30+
ParamList { "(" commaSep<param>? ")" }
31+
3032
ClassDefinition { kw<"class"> VariableName ArgList? Body }
3133

3234
param { VariableName TypeDef? (AssignOp{"="} test)? | "*" VariableName? | "**" VariableName | "/" }

src/tokens.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import {ExternalTokenizer, ContextTracker} from "lezer"
22
import {
33
newline as newlineToken, eof, newlineEmpty, newlineBracketed, indent, dedent, printKeyword,
4-
ParenthesizedExpression, TupleExpression, ComprehensionExpression, ArrayExpression, ArrayComprehensionExpression,
4+
ParenthesizedExpression, TupleExpression, ComprehensionExpression,
5+
ArrayExpression, ArrayComprehensionExpression, ArgList, ParamList,
56
DictionaryExpression, DictionaryComprehensionExpression, SetExpression, SetComprehensionExpression
67
} from "./parser.terms.js"
78

89
const newline = 10, carriageReturn = 13, space = 32, tab = 9, hash = 35, parenOpen = 40, dot = 46
910

1011
const bracketed = [
1112
ParenthesizedExpression, TupleExpression, ComprehensionExpression, ArrayExpression, ArrayComprehensionExpression,
12-
DictionaryExpression, DictionaryComprehensionExpression, SetExpression, SetComprehensionExpression
13+
DictionaryExpression, DictionaryComprehensionExpression, SetExpression, SetComprehensionExpression, ArgList, ParamList
1314
]
1415

1516
let cachedIndent = 0, cachedInput = null, cachedPos = 0

test/expression.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ Script(ExpressionStatement(ContinuedString(String, String)),
3333
ExpressionStatement(String),
3434
ExpressionStatement(String))
3535

36+
# Bracketed continued string
37+
38+
print('00300:'
39+
'03630:')
40+
41+
==>
42+
43+
Script(ExpressionStatement(CallExpression(VariableName, ArgList(ContinuedString(String, String)))))
44+
45+
3646
# Format strings
3747

3848
f'hello{22} abc {{ }} {d-1}'

0 commit comments

Comments
 (0)
0