Skip to content

Commit

Permalink
feat: Numbers overhaul
Browse files Browse the repository at this point in the history
* Underscores as numeric separators
* Integers with leading 0

Closes #4
  • Loading branch information
novusnota committed Feb 17, 2024
1 parent e4ed40b commit 6910f91
Show file tree
Hide file tree
Showing 11 changed files with 4,580 additions and 4,746 deletions.
38 changes: 25 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ module.exports = grammar({
field("alternative", optional($.else_clause)),
),

else_clause: ($) =>
seq("else", choice($.block_statement, $.if_statement)),
else_clause: ($) => seq("else", choice($.block_statement, $.if_statement)),

while_statement: ($) =>
seq(
Expand Down Expand Up @@ -548,10 +547,7 @@ module.exports = grammar({
static_call_expression: ($) =>
prec.right(
"static_call_expr",
seq(
field("name", $.identifier),
field("arguments", $.argument_list),
),
seq(field("name", $.identifier), field("arguments", $.argument_list)),
),

argument_list: ($) => seq("(", commaSep($.argument), ")"),
Expand Down Expand Up @@ -635,13 +631,29 @@ module.exports = grammar({

null: (_) => "null",

integer: (_) =>
choice(
/0[xX][a-fA-F0-9]+/, // hexadecimal
/0[oO][0-7]+/, // octal
/0[bB][01]+/, // binary
/[0-9]+/, // decimal
),
integer: (_) => {
const hex_literal = seq(choice("0x", "0X"), /[\da-fA-F](_?[\da-fA-F])*/);
// TODO: try ?:

const oct_literal = seq(choice("0o", "0O"), /[0-7](_?[0-7])*/);

const bin_literal = seq(choice("0b", "0B"), /[0-1](_?[0-1])*/);

const dec_digits = /(_?\d)*/;
const dec_literal = seq(/[1-9]/, optional(dec_digits));

const dec_leading_zero_literal = seq(/\d/, optional(dec_digits));

return token(
choice(
hex_literal, // hexadecimal
oct_literal, // octal
bin_literal, // binary
dec_literal, // decimal
dec_leading_zero_literal, // decimal, starting with 0
),
);
},

/* Comments */

Expand Down
34 changes: 0 additions & 34 deletions package-lock.json

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"devDependencies": {
"node-gyp": "^10.0.1",
"prettier": "^3.2.4",
"prettier": "^3.2.5",
"tree-sitter-cli": "^0.20.8"
},
"tree-sitter": [
Expand All @@ -65,4 +65,4 @@
"singleQuote": false,
"semi": true
}
}
}
70 changes: 41 additions & 29 deletions pnpm-lock.yaml

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

Loading

0 comments on commit 6910f91

Please sign in to comment.