Skip to content

Commit

Permalink
Merge pull request #6 from chrhansk/feature-for-loop-with-by-argument
Browse files Browse the repository at this point in the history
Add support for "for-from loops" with "by" argument
  • Loading branch information
b0o authored Nov 22, 2024
2 parents 119588a + 83f21a9 commit 439b8f2
Show file tree
Hide file tree
Showing 5 changed files with 163,509 additions and 152,597 deletions.
31 changes: 29 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ module.exports = grammar(Python, {
_compound_statement: ($, original) =>
choice(
original,
$.def_statement,
$.DEF_statement,
$.IF_statement,
$.cdef_statement,
$.ctypedef_statement,
$.property_definition,
Expand All @@ -148,7 +149,7 @@ module.exports = grammar(Python, {
),
),

def_statement: $ =>
DEF_statement: $ =>
seq(
"DEF",
field("name", $.identifier),
Expand All @@ -157,6 +158,28 @@ module.exports = grammar(Python, {
$._newline,
),

IF_statement: $ => seq(
"IF",
field("condition", $.expression),
":",
field("consequence", $._suite),
repeat(field("alternative", $.ELIF_clause)),
optional(field("alternative", $.ELSE_clause)),
),

ELIF_clause: $ => seq(
"ELIF",
field("condition", $.expression),
":",
field("consequence", $._suite),
),

ELSE_clause: $ => seq(
"ELSE",
":",
field("body", $._suite),
),

cdef_statement: $ =>
seq(
choice("cdef", "cpdef"),
Expand Down Expand Up @@ -729,6 +752,10 @@ module.exports = grammar(Python, {
choice("in", "from"),
)),
field("right", $._expressions),
optional(seq(
"by",
$._expressions,
)),
":",
field("body", $._suite),
field("alternative", optional($.else_clause)),
Expand Down
135 changes: 133 additions & 2 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 439b8f2

Please sign in to comment.