Skip to content

Commit

Permalink
Extend support for integer literals
Browse files Browse the repository at this point in the history
  • Loading branch information
chrhansk committed Nov 24, 2024
1 parent 5f7a61d commit 1495ff1
Show file tree
Hide file tree
Showing 5 changed files with 293,388 additions and 232,568 deletions.
37 changes: 37 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,43 @@ module.exports = grammar(Python, {

run_directive: $ => seq("PYTHON", /[^\r\n]+/, $._newline),

c_integer_signedness: $ =>
/[uU]/,

c_integer_type: $ => choice(
seq(
optional($.c_integer_signedness),
/[lL]/,
optional(/[lL]/),
),
$.c_integer_signedness,
),

integer: $ => choice(
seq(
choice("0x", "0X"),
repeat1(/_?[A-Fa-f0-9]+/),
optional($.c_integer_type),
),
seq(
choice("0o", "0O"),
repeat1(/_?[0-7]+/),
optional($.c_integer_type),
),
seq(
choice("0b", "0B"),
repeat1(/_?[0-1]+/),
optional($.c_integer_type),
),
seq(
repeat1(/[0-9]+_?/),
choice(
optional($.c_integer_type), // long numbers
optional(/[jJ]/), // complex numbers
),
),
),

// Cython allows 'cimport'
import_statement: $ =>
seq(
Expand Down
Loading

0 comments on commit 1495ff1

Please sign in to comment.