Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

octal and binary numbers in JavaScript grammar #250

Open
jcubic opened this issue May 24, 2022 · 2 comments
Open

octal and binary numbers in JavaScript grammar #250

jcubic opened this issue May 24, 2022 · 2 comments

Comments

@jcubic
Copy link

jcubic commented May 24, 2022

I wanted to copy hex, octal and binary number literals from JavaScript grammar:

https://github.com/peggyjs/peggy/blob/main/examples/javascript.pegjs

And I think that there are missing octal and binary numbers. There are only hex numbers defined.

@jcubic
Copy link
Author

jcubic commented May 24, 2022

I can provide a PR, the code is analogous to hex digits:

number = hex_number / binary_number / octal_number / decimal_number

hex_number = "0x"i digits:$hex_digit+ {
      return parseInt(digits, 16);
}

octal_number = "0" digits:$octal_digit+ {
      return parseInt(digits, 8);
}

binary_number = "0b" digits:$binary_digit+ {
      return parseInt(digits, 2);
}

hex_digit
  = [0-9a-f]i
  
octal_digit
  = [0-7]
  
binary_digit
  = [01]

If you're ok with PR I will match the implementation into the current code. This is simply what I have in my own language called Gaiman.

The hex is based on JSON grammar.

@hildjj
Copy link
Contributor

hildjj commented May 24, 2022

Hm. I'm more interested in syncing the current JavaScript grammar with ECMA-262. In order to stay closer to that grammar, we may need a couple of features, including working on #15.

There are a couple of options:
a) Take a minor patch now like you propose. (open to this, but not excited about it)
b) Transform this issue into "Sync the ECMA-262 grammar", and keep it open
c) Open a new "Sync the ECMA-262 grammar" issue, and link this issue to it

Opinions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants