Skip to content

Commit

Permalink
Add support for IF statements
Browse files Browse the repository at this point in the history
  • Loading branch information
chrhansk committed Nov 22, 2024
1 parent cd8d4d4 commit 4e7848d
Show file tree
Hide file tree
Showing 5 changed files with 177,044 additions and 171,796 deletions.
27 changes: 25 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',

Check failure on line 162 in grammar.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
field('condition', $.expression),

Check failure on line 163 in grammar.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
':',

Check failure on line 164 in grammar.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
field('consequence', $._suite),

Check failure on line 165 in grammar.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
repeat(field('alternative', $.ELIF_clause)),

Check failure on line 166 in grammar.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
optional(field('alternative', $.ELSE_clause)),

Check failure on line 167 in grammar.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
),

ELIF_clause: $ => seq(
'ELIF',

Check failure on line 171 in grammar.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
field('condition', $.expression),

Check failure on line 172 in grammar.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
':',

Check failure on line 173 in grammar.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
field('consequence', $._suite),

Check failure on line 174 in grammar.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
),

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

cdef_statement: $ =>
seq(
choice("cdef", "cpdef"),
Expand Down
114 changes: 112 additions & 2 deletions src/grammar.json

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

158 changes: 128 additions & 30 deletions src/node-types.json

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

Loading

0 comments on commit 4e7848d

Please sign in to comment.