Skip to content

Commit

Permalink
Merge pull request #9 from chrhansk/feature-c-integer-literals
Browse files Browse the repository at this point in the history
Extend support for integer literals
  • Loading branch information
b0o authored Nov 28, 2024
2 parents af2dc4e + 1495ff1 commit 0fe3849
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 0fe3849

Please sign in to comment.